Skip to content

Commit

Permalink
Added exam skeleton and exam author solution
Browse files Browse the repository at this point in the history
  • Loading branch information
InKolev committed Aug 15, 2016
1 parent decf576 commit 3e6eead
Show file tree
Hide file tree
Showing 272 changed files with 7,551 additions and 3,474 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
using System;
using ArmyOfCreatures.Logic;
using ArmyOfCreatures.Logic.Battles;
using ArmyOfCreatures.Logic.Creatures;
using Moq;
using NUnit.Framework;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.Kernel;

namespace ArmyOfCreatures.Tests
{
[TestFixture]
public class BattleManagerAddCreaturesTests
{
[Test]
public void AddCreatures_WhenCreatureIdentifierIsNull_ShouldThrowArgumentNullException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(null, mockedLogger.Object);

// Act & Assert
Assert.Throws<ArgumentNullException>(() => battleManager.AddCreatures(null, 1));
}

[Test]
public void AddCreatures_WhenValidIdentifierIsPassed_FactoryShouldCallCreateCreature()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

var fixture = new Fixture();

fixture.Customizations.Add(
new TypeRelay(
typeof(Creature),
typeof(Angel)));

var creature = fixture.Create<Creature>();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act
battleManager.AddCreatures(identifier, 1);

// Assert
mockedFactory.Verify(x => x.CreateCreature(It.IsAny<string>()), Times.Exactly(1));
}

[Test]
public void AddCreatures_WhenValidIdentifierIsPassed_WritelineShoulbeCalled()
{
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

var fixture = new Fixture();

fixture.Customizations.Add(
new TypeRelay(
typeof(Creature),
typeof(Angel)));

var creature = fixture.Create<Creature>();

// var creature = new Angel();
mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act
battleManager.AddCreatures(identifier, 1);

// Assert
mockedLogger.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(1));
}
}
}
using System;
using ArmyOfCreatures.Logic;
using ArmyOfCreatures.Logic.Battles;
using ArmyOfCreatures.Logic.Creatures;
using Moq;
using NUnit.Framework;
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.Kernel;

namespace ArmyOfCreatures.Tests
{
[TestFixture]
public class BattleManagerAddCreaturesTests
{
[Test]
public void AddCreatures_WhenCreatureIdentifierIsNull_ShouldThrowArgumentNullException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(null, mockedLogger.Object);

// Act & Assert
Assert.Throws<ArgumentNullException>(() => battleManager.AddCreatures(null, 1));
}

[Test]
public void AddCreatures_WhenValidIdentifierIsPassed_FactoryShouldCallCreateCreature()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

var fixture = new Fixture();

fixture.Customizations.Add(
new TypeRelay(
typeof(Creature),
typeof(Angel)));

var creature = fixture.Create<Creature>();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act
battleManager.AddCreatures(identifier, 1);

// Assert
mockedFactory.Verify(x => x.CreateCreature(It.IsAny<string>()), Times.Exactly(1));
}

[Test]
public void AddCreatures_WhenValidIdentifierIsPassed_WritelineShoulbeCalled()
{
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

var fixture = new Fixture();

fixture.Customizations.Add(
new TypeRelay(
typeof(Creature),
typeof(Angel)));

var creature = fixture.Create<Creature>();

// var creature = new Angel();
mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act
battleManager.AddCreatures(identifier, 1);

// Assert
mockedLogger.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(1));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,105 +1,105 @@
using System;
using ArmyOfCreatures.Logic;
using ArmyOfCreatures.Logic.Battles;
using ArmyOfCreatures.Logic.Creatures;
using ArmyOfCreatures.Tests.MockedClasses;
using Moq;
using NUnit.Framework;

namespace ArmyOfCreatures.Tests
{
[TestFixture]
public class BattleManagerAttackTests
{
[Test]
public void Attack_WhenAttackingCreatureIdentifierIsNull_ShouldThrowArgumentException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act & Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifier, identifier));
}

[Test]
public void Attack_WhenDefenderCreatureIdentifierIsNull_ShouldThrowArgumentException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Pesho(1)");

// Act & Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifier, identifier));
}

[Test]
public void Attack_WhenAttackIsSucessful_ShouldCallWriteline6Times()
{
// Arrange
var mockedFactory = new Mock<CreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifierAttacker = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
var identifierDefender = CreatureIdentifier.CreatureIdentifierFromString("Angel(2)");

var creature = new Angel();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

battleManager.AddCreatures(identifierAttacker, 1);
battleManager.AddCreatures(identifierDefender, 1);

// Act
battleManager.Attack(identifierAttacker, identifierDefender);

// Assert
mockedLogger.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(6));
}

[Test]
public void Attack_WhenAttackingOwnArmy_ShouldThrow()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();
var mockedCreaturesInBattle = new Mock<ICreaturesInBattle>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifierAttacker = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
var identifierDefender = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

var creature = new Angel();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);
mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

battleManager.AddCreatures(identifierAttacker, 1);
battleManager.AddCreatures(identifierDefender, 1);

// Act and Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifierAttacker, identifierDefender));
}
}
}
using System;
using ArmyOfCreatures.Logic;
using ArmyOfCreatures.Logic.Battles;
using ArmyOfCreatures.Logic.Creatures;
using ArmyOfCreatures.Tests.MockedClasses;
using Moq;
using NUnit.Framework;

namespace ArmyOfCreatures.Tests
{
[TestFixture]
public class BattleManagerAttackTests
{
[Test]
public void Attack_WhenAttackingCreatureIdentifierIsNull_ShouldThrowArgumentException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

// Act & Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifier, identifier));
}

[Test]
public void Attack_WhenDefenderCreatureIdentifierIsNull_ShouldThrowArgumentException()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifier = CreatureIdentifier.CreatureIdentifierFromString("Pesho(1)");

// Act & Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifier, identifier));
}

[Test]
public void Attack_WhenAttackIsSucessful_ShouldCallWriteline6Times()
{
// Arrange
var mockedFactory = new Mock<CreaturesFactory>();
var mockedLogger = new Mock<ILogger>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifierAttacker = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
var identifierDefender = CreatureIdentifier.CreatureIdentifierFromString("Angel(2)");

var creature = new Angel();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);

mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

battleManager.AddCreatures(identifierAttacker, 1);
battleManager.AddCreatures(identifierDefender, 1);

// Act
battleManager.Attack(identifierAttacker, identifierDefender);

// Assert
mockedLogger.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(6));
}

[Test]
public void Attack_WhenAttackingOwnArmy_ShouldThrow()
{
// Arrange
var mockedFactory = new Mock<ICreaturesFactory>();
var mockedLogger = new Mock<ILogger>();
var mockedCreaturesInBattle = new Mock<ICreaturesInBattle>();

var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object);

// The code itself should be refactored. Think about sealed class to be changed or the static method itself
// You could use an unconstrained Mocking framework
var identifierAttacker = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
var identifierDefender = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

var creature = new Angel();

mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature);
mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>()));

battleManager.AddCreatures(identifierAttacker, 1);
battleManager.AddCreatures(identifierDefender, 1);

// Act and Assert
Assert.Throws<ArgumentException>(() => battleManager.Attack(identifierAttacker, identifierDefender));
}
}
}
Loading

0 comments on commit 3e6eead

Please sign in to comment.