-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added exam skeleton and exam author solution
- Loading branch information
Showing
272 changed files
with
7,551 additions
and
3,474 deletions.
There are no files selected for viewing
File renamed without changes.
280 changes: 140 additions & 140 deletions
280
...atures.Tests/ArmyOfCreatures.Tests.csproj → ...atures.Tests/ArmyOfCreatures.Tests.csproj
Large diffs are not rendered by default.
Oops, something went wrong.
184 changes: 92 additions & 92 deletions
184
...s.Tests/BattleManagerAddCreaturesTests.cs → ...s.Tests/BattleManagerAddCreaturesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
210 changes: 105 additions & 105 deletions
210
...eatures.Tests/BattleManagerAttackTests.cs → ...eatures.Tests/BattleManagerAttackTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.