Beispiel #1
0
        public void TeleportUnit_WhenIUnitUnitToTeleportIsNull_ShouldThrowArgumentNullExceptionAndMassageShouldContainSpecialString()
        {
            var exMassageShouldContains = "unitToTeleport";
            var mockedOwner             = new Mock <IBusinessOwner>();
            var mockedGalacticMap       = new Mock <IEnumerable <IPath> >();
            var mockedLocation          = new Mock <ILocation>();

            var teleportStation = new MockedTeleportStation(mockedOwner.Object, mockedGalacticMap.Object, mockedLocation.Object);

            var ex = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(null, mockedLocation.Object));

            StringAssert.Contains(exMassageShouldContains, ex.Message);
        }
Beispiel #2
0
        public void PayProfits_WhenPassedArgumentIsActualOwner_ShouldReturnTotalAmountOfResources()
        {
            //Arrange
            var mockedBusinessOwner = new Mock <IBusinessOwner>();

            var mockedLocation = new Mock <ILocation>();
            var mockedGalaxy   = new Mock <IGalaxy>();

            mockedGalaxy.SetupGet(x => x.Name).Returns("Milky Way");
            mockedLocation.SetupGet(x => x.Planet.Galaxy).Returns(mockedGalaxy.Object);
            mockedLocation.SetupGet(x => x.Planet.Name).Returns("Earth");
            var mockedUnit = new Mock <IUnit>();

            mockedUnit.SetupGet(x => x.CurrentLocation).Returns(mockedLocation.Object);

            var mockedUnitGalaxy = new Mock <IGalaxy>();

            mockedUnitGalaxy.SetupGet(x => x.Name).Returns("Milky Way");
            var mockedLocationToTeleportTo = new Mock <ILocation>();

            mockedLocationToTeleportTo.SetupGet(x => x.Planet.Name).Returns("Earth");
            mockedLocationToTeleportTo.SetupGet(x => x.Planet.Galaxy).Returns(mockedUnitGalaxy.Object);
            var mockedGalacticMap = new List <IPath>();
            var mockedPath        = new Mock <IPath>();

            var mockedMoneyForUnit = new Mock <IResources>();

            mockedMoneyForUnit.SetupGet(x => x.BronzeCoins).Returns(100);
            mockedMoneyForUnit.SetupGet(x => x.GoldCoins).Returns(100);
            mockedMoneyForUnit.SetupGet(x => x.SilverCoins).Returns(100);
            mockedUnit.SetupGet(x => x.Resources).Returns(mockedMoneyForUnit.Object);

            mockedUnit.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true);

            var mockedCostToTravel = new Mock <IResources>();

            mockedCostToTravel.SetupGet(x => x.BronzeCoins).Returns(1);
            mockedCostToTravel.SetupGet(x => x.GoldCoins).Returns(1);
            mockedCostToTravel.SetupGet(x => x.SilverCoins).Returns(1);
            mockedPath.SetupGet(x => x.Cost).Returns(mockedCostToTravel.Object);
            mockedUnit.Setup(x => x.Pay(It.IsAny <IResources>())).Returns(mockedCostToTravel.Object);

            mockedPath.SetupGet(x => x.TargetLocation).Returns(mockedLocationToTeleportTo.Object);
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Milky Way");
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Earth");
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Units).Returns(new List <IUnit>());

            mockedLocation.Setup(x => x.Planet.Units).Returns(new List <IUnit>());
            mockedLocation.Setup(x => x.Planet.Units.Remove(It.IsAny <IUnit>()));
            mockedUnit.SetupGet(x => x.CurrentLocation).Returns(mockedLocation.Object);

            mockedGalacticMap.Add(mockedPath.Object);
            var teleportStation = new MockedTeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);

            teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationToTeleportTo.Object);

            var expectedGoldCoins   = teleportStation.Resources.GoldCoins;
            var expectedSilverCoins = teleportStation.Resources.SilverCoins;
            var expectedBronzeCoins = teleportStation.Resources.BronzeCoins;
            //Act

            var result = teleportStation.PayProfits(mockedBusinessOwner.Object);

            //Assert
            Assert.AreEqual(expectedGoldCoins, result.GoldCoins);
            Assert.AreEqual(expectedSilverCoins, result.SilverCoins);
            Assert.AreEqual(expectedBronzeCoins, result.BronzeCoins);
        }
Beispiel #3
0
        public void TeleportUnit_WhenEverythingIsValid_ShouldIncreaseTeleportStationResourcesByCostToTravel()
        {
            //Arrange
            var mockedBusinessOwner = new Mock <IBusinessOwner>();

            var mockedLocation = new Mock <ILocation>();
            var mockedGalaxy   = new Mock <IGalaxy>();

            mockedGalaxy.SetupGet(x => x.Name).Returns("Milky Way");
            mockedLocation.SetupGet(x => x.Planet.Galaxy).Returns(mockedGalaxy.Object);
            mockedLocation.SetupGet(x => x.Planet.Name).Returns("Earth");
            var mockedUnit = new Mock <IUnit>();

            mockedUnit.SetupGet(x => x.CurrentLocation).Returns(mockedLocation.Object);

            var mockedUnitGalaxy = new Mock <IGalaxy>();

            mockedUnitGalaxy.SetupGet(x => x.Name).Returns("Milky Way");
            var mockedLocationToTeleportTo = new Mock <ILocation>();

            mockedLocationToTeleportTo.SetupGet(x => x.Planet.Name).Returns("Earth");
            mockedLocationToTeleportTo.SetupGet(x => x.Planet.Galaxy).Returns(mockedUnitGalaxy.Object);
            var mockedGalacticMap = new List <IPath>();
            var mockedPath        = new Mock <IPath>();

            var mockedMoneyForUnit = new Mock <IResources>();

            mockedMoneyForUnit.SetupGet(x => x.BronzeCoins).Returns(100);
            mockedMoneyForUnit.SetupGet(x => x.GoldCoins).Returns(100);
            mockedMoneyForUnit.SetupGet(x => x.SilverCoins).Returns(100);
            mockedUnit.SetupGet(x => x.Resources).Returns(mockedMoneyForUnit.Object);

            mockedUnit.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true);

            var mockedCostToTravel = new Mock <IResources>();

            mockedCostToTravel.SetupGet(x => x.BronzeCoins).Returns(1);
            mockedCostToTravel.SetupGet(x => x.GoldCoins).Returns(1);
            mockedCostToTravel.SetupGet(x => x.SilverCoins).Returns(1);
            mockedPath.SetupGet(x => x.Cost).Returns(mockedCostToTravel.Object);
            mockedUnit.Setup(x => x.Pay(It.IsAny <IResources>())).Returns(mockedCostToTravel.Object);

            mockedPath.SetupGet(x => x.TargetLocation).Returns(mockedLocationToTeleportTo.Object);
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Milky Way");
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Earth");
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Units).Returns(new List <IUnit>());

            mockedLocation.Setup(x => x.Planet.Units).Returns(new List <IUnit>());
            mockedLocation.Setup(x => x.Planet.Units.Remove(It.IsAny <IUnit>()));
            mockedUnit.SetupGet(x => x.CurrentLocation).Returns(mockedLocation.Object);

            mockedGalacticMap.Add(mockedPath.Object);
            var teleportStation = new MockedTeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);

            //Act
            teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationToTeleportTo.Object);
            //Assert
            Assert.AreEqual(1, teleportStation.Resources.GoldCoins);
            Assert.AreEqual(1, teleportStation.Resources.BronzeCoins);
            Assert.AreEqual(1, teleportStation.Resources.SilverCoins);
        }