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_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_WhenArmyNumbersAreEqual_ShouldThrowException()
        {
            var mockedCreaturesFactory = new Mock<ICreaturesFactory>();
            var mockedLogger = new Mock<ILogger>();

            var mockedBattleManager = new MockedBattleManager(mockedCreaturesFactory.Object, mockedLogger.Object);

            var attackerIdentifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
            var defenderIdentifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            var creature = new Angel();

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

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

            mockedBattleManager.AddCreatures(attackerIdentifier, 1);
            mockedBattleManager.AddCreatures(defenderIdentifier, 1);

            Assert.Throws<ArgumentException>(() => mockedBattleManager.Attack(attackerIdentifier, defenderIdentifier));
        }
        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));
        }
        public void Attack_WhenIdentifiersAreValid_ShouldWorkCorrectly()
        {
            var mockedCreaturesFactory = new Mock<ICreaturesFactory>();
            var mockedLogger = new Mock<ILogger>();

            var mockedBattleManager = new MockedBattleManager(mockedCreaturesFactory.Object, mockedLogger.Object);

            var attackerIdentifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
            var defenderIdentifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(2)");

            var creature = new Angel();

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

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

            mockedBattleManager.AddCreatures(attackerIdentifier, 1);
            mockedBattleManager.AddCreatures(defenderIdentifier, 1);

            mockedBattleManager.Attack(attackerIdentifier, defenderIdentifier);

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