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));
        }
        public void CreatureIdentifier_WhenValidValueIsPassed_ShouldReturnExpectedArmyNumber()
        {
            // Act
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            // Assert
            Assert.AreEqual(1, identifier.ArmyNumber);
        }
        public void CreatureIdentifier_WhenValidValueIsPassed_ToStringShouldReturnExpectedString()
        {
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            var result = identifier.ToString();

            Assert.AreEqual("Angel(1)", result);
        }
Exemplo n.º 4
0
        public void ToString_ShouldReturnCorrectString()
        {
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
            var expected   = "Angel(1)";
            var result     = identifier.ToString();

            Assert.AreEqual(expected, result);
        }
        public void CreatureIdentifier_WhenValidValueIsPassed_ShouldReturnExpectedType()
        {
            // Act
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            // Assert
            Assert.IsInstanceOf <CreatureIdentifier>(identifier);
        }
Exemplo n.º 6
0
        public void Attack_ShouldThrowArgumentNullException_WhenDefenderCreatureIdentifierIsNull()
        {
            var mockedFactory = new Mock <ICreaturesFactory>();
            var mockedLogger  = new Mock <ILogger>();
            var battleManager = new BattleManager(mockedFactory.Object, mockedLogger.Object);
            var identifier    = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            Assert.Throws <ArgumentException>(() => battleManager.Attack(identifier, null));
        }
        public void AttackCreatures_WhenAttackerCreatureIdentifierIsNull_SHouldTHrowArgument()
        {
            var mockedFactory = new Mock <ICreaturesFactory>();
            var mockedLogger  = new Mock <ILogger>();

            var manager    = new BattleManager(mockedFactory.Object, mockedLogger.Object);
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            Assert.Throws <ArgumentException>(() => manager.Attack(null, identifier));
        }
        public void ThrowArgumentException_WhenNullAttackerCreatureIsPassed()
        {
            var creatureFactoryMock = new Mock <ICreaturesFactory>();
            var loggerMock          = new Mock <ILogger>();

            var battleManager = new BattleManager(creatureFactoryMock.Object, loggerMock.Object);

            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Pesho(1)");

            Assert.Throws <ArgumentException>(() => battleManager.Attack(identifier, identifier));
        }
Exemplo n.º 9
0
        public void AddCreatures_ShouldThrowArgumentException_WhenInvalidArmyNumberIsProvided()
        {
            var mockedLogger = new Mock <ILogger>();
            var mockFactory  = new Mock <ICreaturesFactory>();

            mockFactory.Setup(x => x.CreateCreature(It.IsAny <string>())).Returns(new Angel());
            var manager    = new BattleManager(mockFactory.Object, mockedLogger.Object);
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(3)");

            Assert.Throws <ArgumentException>(() => manager.AddCreatures(identifier, 1));
        }
        public void Attack_ShouldThrowArgumentException_WhenDefenderCreatureIdentifierIsNull()
        {
            //Arrange
            var creaturesFactoryStub = new Mock <ICreaturesFactory>();
            var loggerStub           = new Mock <ILogger>();
            var sut        = new Logic.Battles.BattleManager(creaturesFactoryStub.Object, loggerStub.Object);
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            //Act & Assert
            Assert.Throws <ArgumentException>(() => sut.Attack(identifier, identifier));
        }
Exemplo n.º 11
0
        public void AddCreatures_ShouldCallCreateCreatureMethodOfFactory_WhenValidIdentifierIsProvided()
        {
            var mockedLogger = new Mock <ILogger>();
            var mockFactory  = new Mock <ICreaturesFactory>();
            var manager      = new BattleManager(mockFactory.Object, mockedLogger.Object);

            mockFactory.Setup(x => x.CreateCreature(It.IsAny <string>())).Returns(new Angel());
            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            manager.AddCreatures(identifier, 1);

            mockFactory.Verify(x => x.CreateCreature(It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 12
0
        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));
        }
        public void CallCreateCreature_WhenValidIdentifierIsPassed()
        {
            var mockedFactory = new Mock <ICreaturesFactory>();
            var mockedLogger  = new Mock <ILogger>();

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

            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            var creature = new Angel();

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

            bmanager.AddCreatures(identifier, 1);

            mockedFactory.Verify(x => x.CreateCreature(It.IsAny <string>()), Times.Exactly(1));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        public void AddCreatures_ShouldCallCreteCreatureFromFactory_IfInputIsValid()
        {
            int count = 5;
            var creatureIdentifier = CreatureIdentifier.CreatureIdentifierFromString("AncientBehemoth(1)");

            var creaturesFactoryMock = new Mock <ICreaturesFactory>();
            var loggerMock           = new Mock <ILogger>();

            var battleManager = new BattleManager(creaturesFactoryMock.Object, loggerMock.Object);

            try
            {
                battleManager.AddCreatures(creatureIdentifier, count);
            }
            catch { }

            creaturesFactoryMock.Verify(x => x.CreateCreature(It.IsAny <string>()), Times.Once());
        }
        public void CallWriteLineExactly2Times_WhenValidValueIsPassed()
        {
            var loggerMock  = new Mock <ILogger>();
            var factoryMock = new Mock <ICreaturesFactory>();

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

            var battleManager = new MockedBattleManager(factoryMock.Object, loggerMock.Object);

            var creaturesInBattle = new CreaturesInBattle(new Angel(), 1);

            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            battleManager.FirstArmyCreatures.Add(creaturesInBattle);

            battleManager.Skip(identifier);

            loggerMock.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(2));
        }
Exemplo n.º 17
0
        public void AddCreature_ShouldCallICreaturesFactoryCreateCreatureWithCorrectCreatureNameString_WhenParametersAreValid()
        {
            var expectedCreatureName = "fake";

            var fakeFactory = new Mock <ICreaturesFactory>();

            fakeFactory.Setup(mock => mock.CreateCreature(expectedCreatureName)).Returns(new FakeCreature());

            var fakeLogger = new Mock <ILogger>();

            var creatureIdentifier = CreatureIdentifier.CreatureIdentifierFromString(expectedCreatureName + "(1)");
            var count = 1;

            var battleManager = new BattleManager(fakeFactory.Object, fakeLogger.Object);

            battleManager.AddCreatures(creatureIdentifier, count);

            fakeFactory.Verify(mock => mock.CreateCreature(expectedCreatureName), Times.Once());
        }
        public void AddCreaturesInThirdArmy_WhenCorrectDataIsPassed()
        {
            var logger  = new Mock <ILogger>();
            var factory = new Mock <ICreaturesFactory>();

            var creature = new Angel();

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

            var battleManager = new MockedBattleManager(factory.Object, logger.Object);

            var creatureIdentifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(3)");

            battleManager.AddCreatures(creatureIdentifier, 1);

            var result = battleManager.ThirdArmyCreatures.FirstOrDefault();

            Assert.IsInstanceOf(typeof(CreaturesInBattle), result);
        }
        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));
        }
Exemplo n.º 20
0
        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));
        }
Exemplo n.º 22
0
        public void AddCreatures_WhenValidIdentifierIsPassed_FactoryShouldCallCreateCreature()
        {
            var mockedFactory = new Mock <ICreaturesFactory>();
            var mockedLogger  = new Mock <ILogger>();

            var manager = 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);

            var identifier = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            manager.AddCreatures(identifier, 1);
            mockedFactory.Verify(x => x.CreateCreature(It.IsAny <string>()), Times.Exactly(1));
        }
Exemplo n.º 23
0
        public void AddCreatures_ShouldThrowArgumentException_IfCreatureIsAddedToNonexistentArmy()
        {
            int count = 5;
            var creatureIdentifier = CreatureIdentifier.CreatureIdentifierFromString("AncientBehemoth(3)");

            var creature = new Angel();

            //var fixture = new Fixture();
            //var creature = fixture.Create<Angel>();

            var creaturesFactoryMock = new Mock <ICreaturesFactory>();

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

            var loggerMock = new Mock <ILogger>();

            var battleManager = new BattleManager(creaturesFactoryMock.Object, loggerMock.Object);

            Assert.Throws <ArgumentException>(() => battleManager.AddCreatures(creatureIdentifier, count));
        }
Exemplo n.º 24
0
        public void ProcessCommand(IBattleManager battleManager, params string[] arguments)
        {
            if (battleManager == null)
            {
                throw new ArgumentNullException("battleManager");
            }

            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            if (arguments.Length < 1)
            {
                throw new ArgumentException("Invalid number of arguments for skip command");
            }

            var creatureIdentifierString = arguments[0];
            var creatureIdentifier       = CreatureIdentifier.CreatureIdentifierFromString(creatureIdentifierString);

            battleManager.Skip(creatureIdentifier);
        }
Exemplo n.º 25
0
        public void AddCreature_ShouldAddACreatureToFirstArmyCreatures_WhenCreatureIdentifierArmyNumberIsOne()
        {
            var creatureName = "fake";
            var armyNr       = "1";

            var fakeFactory = new Mock <ICreaturesFactory>();

            fakeFactory.Setup(moch => moch.CreateCreature(It.IsAny <string>())).Returns(new FakeCreature());

            var fakeLogger = new Mock <ILogger>();

            var identifier = CreatureIdentifier.CreatureIdentifierFromString(string.Format("{0}({1})", creatureName, armyNr));
            var count      = 1;

            var manager   = new BattleManager(fakeFactory.Object, fakeLogger.Object);
            var managerPO = new MSTest.PrivateObject(manager);

            var firstArmy = (ICollection <ICreaturesInBattle>)managerPO.GetField("firstArmyCreatures");

            manager.AddCreatures(identifier, count);

            Assert.AreEqual(1, firstArmy.Count);
        }
Exemplo n.º 26
0
        public void Attack_WhenAttackingOwnArmy_ShouldThrowArgumentException()
        {
            // Arrange
            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(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));
        }
Exemplo n.º 27
0
        public void ProcessCommand(IBattleManager battleManager, params string[] arguments)
        {
            if (battleManager == null)
            {
                throw new ArgumentNullException("battleManager");
            }

            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            if (arguments.Length < 2)
            {
                throw new ArgumentException("Invalid number of arguments for add command");
            }

            var count = int.Parse(arguments[0], CultureInfo.InvariantCulture);
            var creatureIdentifierString = arguments[1];
            var creatureIdentifier       = CreatureIdentifier.CreatureIdentifierFromString(creatureIdentifierString);

            battleManager.AddCreatures(creatureIdentifier, count);
        }
Exemplo n.º 28
0
        public void AddCreatures_ShouldCallWriteLineFromlogger_IfInputIsValid()
        {
            int count = 5;
            var creatureIdentifier = CreatureIdentifier.CreatureIdentifierFromString("AncientBehemoth(1)");

            var creature = new Angel();

            //var fixture = new Fixture();
            //var creature = fixture.Create<Angel>();

            var creaturesFactoryMock = new Mock <ICreaturesFactory>();

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

            var loggerMock = new Mock <ILogger>();

            var battleManager = new BattleManager(creaturesFactoryMock.Object, loggerMock.Object);

            battleManager.AddCreatures(creatureIdentifier, count);

            loggerMock.Verify(x => x.WriteLine(It.IsAny <String>()), Times.Once());
        }
        public void Attack_WhenAttackIsSuccessfull_ShoulCallWriteLine6Times()
        {
            //Arrange
            var creaturesFactoryStub = new Mock <ICreaturesFactory>();
            var loggerMock           = new Mock <ILogger>();
            var sut = new MockedBattleManager(creaturesFactoryStub.Object, loggerMock.Object);

            var identifier1 = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
            var identifier2 = CreatureIdentifier.CreatureIdentifierFromString("Angel(2)");

            var creature = new Angel();

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


            //Act
            sut.AddCreatures(identifier1, 1);
            sut.AddCreatures(identifier2, 1);
            sut.Attack(identifier1, identifier2);

            //Assert
            loggerMock.Verify(x => x.WriteLine(It.IsAny <string>()), Times.Exactly(6));
        }
        //[Test]
        public void Attack_WhenAttackingOwnArmy_ShouldThrow()
        {
            //Arrange
            var mockedfacttory          = new Mock <ICreaturesFactory>();
            var mockedLogger            = new Mock <ILogger>();
            var mockedCreaturesInBatlle = new Mock <ICreaturesInBattle>();

            var sut = new MockedBattleManager(mockedfacttory.Object, mockedLogger.Object);

            var identifier1 = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");
            var identifier2 = CreatureIdentifier.CreatureIdentifierFromString("Angel(1)");

            var creature = new Angel();

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

            //Act
            sut.AddCreatures(identifier1, 1);
            sut.AddCreatures(identifier2, 1);

            //Assert
            Assert.Throws <ArgumentException>(() => sut.Attack(identifier1, identifier2));
        }