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)); }
public void AttackCreatures_WhenDefenderCreatureIdentifierIsNull_SHouldTHrowArgument() { var mockedFactory = new Mock <ICreaturesFactory>(); var mockedLogger = new Mock <ILogger>(); var manager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)"); Assert.Throws <ArgumentException>(() => manager.Attack(identifier, null)); }
public void AttackCreatures_WhenDefenderCreatureIdentifierIsNull_SHouldTHrowArgument() { var mockedFactory = new Mock<ICreaturesFactory>(); var mockedLogger = new Mock<ILogger>(); var manager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)"); Assert.Throws<ArgumentException>(() => manager.Attack(identifier, null)); }
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)); }
public void Attack_ShouldCallLoggerWriteLineMethodFourTimes_WhenAttackIsSuccessfull() { var mockedFactory = new Mock <ICreaturesFactory>(); var mockedLogger = new Mock <ILogger>(); var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); 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); battleManager.AddCreatures(identifierAttacker, 3); battleManager.AddCreatures(identifierDefender, 3); battleManager.Attack(identifierAttacker, identifierDefender); mockedLogger.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(6)); }
public void Attack_ShouldReturnRightResult_WhenTwoBehemothsAttackOne() { var mockedFactory = new Mock <ICreaturesFactory>(); var mockedLogger = new Mock <ILogger>(); var battleManager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); var identifierAttacker = CreatureIdentifier.CreatureIdentifierFromString("Behemoth(1)"); var identifierDefender = CreatureIdentifier.CreatureIdentifierFromString("Behemoth(2)"); var creature = new Behemoth(); mockedFactory.Setup(x => x.CreateCreature(It.IsAny <string>())).Returns(creature); battleManager.AddCreatures(identifierAttacker, 2); battleManager.AddCreatures(identifierDefender, 1); battleManager.Attack(identifierAttacker, identifierDefender); var result = battleManager.SecondArmyOfCreatures.FirstOrDefault().TotalHitPoints; Assert.IsTrue(result == 56); }
public void AttackCreatures_WhenAttackIsSuccessful_ShouldCallWriteLIne4Times() { var mockedFactory = new Mock<ICreaturesFactory>(); var mockedLogger = new Mock<ILogger>(); var manager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)"); var creature = new Angel(); mockedFactory.Setup(x => x.CreateCreature(It.IsAny<string>())).Returns(creature); manager.AddCreatures(identifier, 1); mockedLogger.Setup(x => x.WriteLine(It.IsAny<string>())); manager.Attack(identifier, identifier); mockedLogger.Verify(x => x.WriteLine(It.IsAny<string>()), Times.Exactly(4)); }
public void CallWriteLine4Times_WhenAttackIsSucessful() { var creatureFactoryMock = new Mock <ICreaturesFactory>(); var loggerMock = new Mock <ILogger>(); var battleManager = new MockedBattleManager(creatureFactoryMock.Object, loggerMock.Object); var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)"); creatureFactoryMock.Setup(x => x.CreateCreature(It.IsAny <string>())).Returns(new Angel()); battleManager.AddCreatures(identifier, 1); loggerMock.Setup(x => x.WriteLine(It.IsAny <string>())); battleManager.Attack(identifier, identifier); loggerMock.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(4)); }
public void AttackCreatures_WhenAttackIsSuccessful_ShouldCallWriteLIne4Times() { var mockedFactory = new Mock <ICreaturesFactory>(); var mockedLogger = new Mock <ILogger>(); var manager = new MockedBattleManager(mockedFactory.Object, mockedLogger.Object); var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)"); var creature = new Angel(); mockedFactory.Setup(x => x.CreateCreature(It.IsAny <string>())).Returns(creature); manager.AddCreatures(identifier, 1); mockedLogger.Setup(x => x.WriteLine(It.IsAny <string>())); manager.Attack(identifier, identifier); mockedLogger.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(4)); }
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)); }