public void ThrowTeleportOutOfRangeException_WhenUnitTriesToUseTeleportFromDifferentPlanet()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();
            var stationMapStub   = new List <IPath> {
                new Mock <IPath>().Object
            };
            var stationLocationStub = new Mock <ILocation>();

            stationLocationStub.SetupGet(l => l.Planet.Galaxy.Name).Returns("Milky way");
            stationLocationStub.SetupGet(l => l.Planet.Name).Returns("Earth");

            var teleport = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            var differentLocationStub = new Mock <ILocation>();

            differentLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Milky way");
            differentLocationStub.SetupGet(d => d.Planet.Name).Returns("Mars");

            var targetLocationStub = new Mock <ILocation>();

            targetLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Andromeda");
            targetLocationStub.SetupGet(d => d.Planet.Name).Returns("Kobe");

            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(u => u.CurrentLocation).Returns(differentLocationStub.Object);
            // Act and Assert
            Assert.Throws <TeleportOutOfRangeException>(
                () => teleport.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object));
        }
Exemple #2
0
        public void TeleportUnit_WhenAUnitIsTryingToUseTheTeleportStationFromADistantLocation_ShouldThrowTeleportOutOfRangeExceptionAndMassageShouldContainSpecialString()
        {
            var exMassageShouldContains = "unitToTeleport.CurrentLocation";

            var mockedOwner              = new Mock <IBusinessOwner>();
            var mockedGalacticMap        = new Mock <IEnumerable <IPath> >();
            var mockedLocationForStation = new Mock <ILocation>();

            var mockedPlanetOne = new Mock <IPlanet>();
            var mockedPlanetTwo = new Mock <IPlanet>();
            var mockedGalaxy    = new Mock <IGalaxy>();

            mockedGalaxy.Setup(x => x.Name).Returns("firstGalaxy");

            mockedPlanetOne.Setup(x => x.Galaxy).Returns(mockedGalaxy.Object);
            mockedPlanetOne.Setup(x => x.Galaxy.Name).Returns("Earth");

            mockedPlanetTwo.Setup(x => x.Galaxy.Name).Returns("Mars");
            mockedPlanetTwo.Setup(x => x.Galaxy).Returns(mockedGalaxy.Object);

            mockedLocationForStation.Setup(x => x.Planet).Returns(mockedPlanetOne.Object);

            var mockedUnit = new Mock <IUnit>();

            mockedUnit.Setup(x => x.CurrentLocation.Planet).Returns(mockedPlanetTwo.Object);

            var teleportStation = new TeleportStation(mockedOwner.Object, mockedGalacticMap.Object, mockedLocationForStation.Object);

            var ex = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationForStation.Object));

            StringAssert.Contains(exMassageShouldContains, ex.Message);
        }
Exemple #3
0
        public void ThrowLocationNotFoundExceptionWithProperMessage_WhenTryingToTravelToNonExistingPlanet()
        {
            var owner       = new Mock <IBusinessOwner>();
            var galacticMap = new List <IPath>();
            var location    = new Mock <ILocation>();

            location.SetupGet(x => x.Planet.Name).Returns("Gosho");
            location.SetupGet(x => x.Planet.Galaxy.Name).Returns("Gosho");

            var teleportStation = new TeleportStation
                                      (owner.Object, galacticMap, location.Object);
            var expectedMessage = "Planet";
            var unit            = new Mock <IUnit>();

            unit.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Gosho");
            unit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Gosho");

            var path = new Mock <IPath>();

            path.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Gosho");
            path.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Pesho");
            galacticMap.Add(path.Object);

            var exc = Assert.Throws <LocationNotFoundException>
                          (() => teleportStation.TeleportUnit(unit.Object, location.Object));

            StringAssert.Contains(expectedMessage, exc.Message);
        }
Exemple #4
0
        public void TeleportUnit_WhenTryingToTeleportAUnitToALocationWhichAnotherTaken_ShouldThrowInvalidTeleportationLocationExceptionAndMassageShouldContainSpecialString()
        {
            var exMassageShouldContains = "units will overlap";

            var mockedOwner              = new Mock <IBusinessOwner>();
            var mockedGalacticMap        = new Mock <IEnumerable <IPath> >();
            var mockedLocationForStation = new Mock <ILocation>();

            var mockedPlanetOne = new Mock <IPlanet>();
            var mockedPlanetTwo = new Mock <IPlanet>();
            var mockedGalaxy    = new Mock <IGalaxy>();

            mockedGalaxy.Setup(x => x.Name).Returns("firstGalaxy");
            mockedPlanetOne.Setup(x => x.Galaxy).Returns(mockedGalaxy.Object);
            mockedPlanetOne.Setup(x => x.Galaxy.Name).Returns("Earth");

            mockedPlanetTwo.Setup(x => x.Galaxy.Name).Returns("Mars");
            mockedPlanetTwo.Setup(x => x.Galaxy).Returns(mockedGalaxy.Object);
            mockedLocationForStation.Setup(x => x.Planet).Returns(mockedPlanetOne.Object);

            var mockedUnit = new Mock <IUnit>();

            mockedUnit.Setup(x => x.CurrentLocation.Planet).Returns(mockedPlanetTwo.Object);

            var teleportStation = new TeleportStation(mockedOwner.Object, mockedGalacticMap.Object, mockedLocationForStation.Object);

            var ex = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationForStation.Object));

            StringAssert.Contains(exMassageShouldContains, ex.Message);
        }
        public void Constructor_ShouldSetUpAllFields_WhenNewTeleportStationIsCreatedWhithValidParameters()
        {
            // Arrange
            var expectedMockedOwner    = new Mock <IBusinessOwner>();
            var mockedPath             = new Mock <IPath>();
            var expectedmockedLocation = new Mock <ILocation>();
            var expectedgalacticMap    = new List <IPath>();

            expectedgalacticMap.Add(mockedPath.Object);

            var expectedgalacticMap1 = new Mock <List <IPath> >();

            // Act
            var teleportStation = new TeleportStation(expectedMockedOwner.Object, expectedgalacticMap1.Object,
                                                      expectedmockedLocation.Object);

            var wrapperTeleportStation = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(teleportStation);

            var actualResources   = wrapperTeleportStation.GetField("resources");
            var actualOwner       = wrapperTeleportStation.GetField("owner");
            var actualLocation    = wrapperTeleportStation.GetField("location");
            var actualGalacticMap = wrapperTeleportStation.GetField("galacticMap");

            // Assert
            Assert.AreSame(expectedMockedOwner.Object, actualOwner);
            Assert.AreSame(expectedgalacticMap1.Object, actualGalacticMap);
            Assert.AreSame(expectedmockedLocation.Object, actualLocation);
        }
Exemple #6
0
        public void TeleportUnit_WhenLocationOfUnitDoesNotMatchStationLocation_ShouldThrowTeleportOutOfRangeExceptionWithCorrectMessage()
        {
            //Arrange
            var mockedBusinessOwner = new Mock <IBusinessOwner>();

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

            mockedGalaxy.SetupGet(x => x.Name).Returns("Andromeda");
            mockedLocation.SetupGet(x => x.Planet.Galaxy).Returns(mockedGalaxy.Object);
            mockedLocation.SetupGet(x => x.Planet.Name).Returns("SG306");

            var mockedUnitGalaxy = new Mock <IGalaxy>();

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

            mockedUnitLocation.SetupGet(x => x.Planet.Name).Returns("Earth");
            mockedUnitLocation.SetupGet(x => x.Planet.Galaxy).Returns(mockedUnitGalaxy.Object);
            var mockedUnit = new Mock <IUnit>();

            mockedUnit.Setup(x => x.CurrentLocation).Returns(mockedUnitLocation.Object);

            var mockedGalacticMap = new List <IPath>();
            var teleportStation   = new TeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);
            //Act and Assert
            var ex = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedUnitLocation.Object));

            StringAssert.Contains("unitToTeleport.CurrentLocation", ex.Message);
        }
        public void ThrowLocationNotFoundException_WhenTryToTeleportUnitToPlanetWhichIsNotInTheStaionMap()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();

            var stationLocationStub = new Mock <ILocation>();

            stationLocationStub.SetupGet(l => l.Planet.Galaxy.Name).Returns("Milky way");
            stationLocationStub.SetupGet(l => l.Planet.Name).Returns("Earth");

            var targetLocationStub = new Mock <ILocation>();

            targetLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Andromeda");
            targetLocationStub.SetupGet(d => d.Planet.Name).Returns("Kobe");

            var pathStub = new Mock <IPath>();

            pathStub.SetupGet(p => p.TargetLocation.Planet.Galaxy.Name).Returns("Andromeda");
            pathStub.SetupGet(p => p.TargetLocation.Planet.Name).Returns("Sirius");

            var stationMapStub = new List <IPath> {
                pathStub.Object
            };

            var teleport = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(u => u.CurrentLocation).Returns(stationLocationStub.Object);
            // Act and Assert
            Assert.Throws <LocationNotFoundException>(
                () => teleport.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object));
        }
        public void TestTeleportUnit_PassDistantLockationForUnit_ShouldThrowTeleportOutOfRangeException()
        {
            var mockedBusinessOwner = new Mock <IBusinessOwner>();
            var mockedPath          = new Mock <IPath>();
            var map = new List <IPath>()
            {
                mockedPath.Object
            };
            var mockedDestination = new Mock <ILocation>();

            var mockedLocation     = new Mock <ILocation>();
            var mockedUnitLocation = new Mock <ILocation>();

            var mockedUnit          = new Mock <IUnit>();
            var mockedUnitPlanet    = new Mock <IPlanet>();
            var mockedCurrentPlanet = new Mock <IPlanet>();

            mockedCurrentPlanet.SetupGet(x => x.Galaxy.Name).Returns("Milky Way");
            mockedCurrentPlanet.SetupGet(x => x.Name).Returns("Mars");
            mockedLocation.SetupGet(x => x.Planet).Returns(mockedCurrentPlanet.Object);

            var teleportStation = new TeleportStation(mockedBusinessOwner.Object, map, mockedLocation.Object);

            mockedUnitPlanet.SetupGet(x => x.Galaxy.Name).Returns("Way out");
            mockedUnitPlanet.SetupGet(x => x.Name).Returns("Unknown");
            mockedUnitLocation.SetupGet(x => x.Planet).Returns(mockedUnitPlanet.Object);

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

            Assert.Throws <TeleportOutOfRangeException>(() =>
                                                        teleportStation.TeleportUnit(mockedUnit.Object, mockedDestination.Object),
                                                        "unitToTeleport.CurrentLocation");
        }
        public void ThrowWithMessageContainingTheStringUnitToTeleportCurrentLocation_WhenUnitTriesToUseTeleportFromDifferentPlanetOrGalaxy()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();
            var stationMapStub   = new List <IPath> {
                new Mock <IPath>().Object
            };
            var stationLocationStub = new Mock <ILocation>();

            stationLocationStub.SetupGet(l => l.Planet.Galaxy.Name).Returns("Milky way");
            stationLocationStub.SetupGet(l => l.Planet.Name).Returns("Earth");

            var teleport = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            var targetLocationStub = new Mock <ILocation>();

            targetLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Andromeda");
            targetLocationStub.SetupGet(d => d.Planet.Name).Returns("Kobe");

            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(u => u.CurrentLocation).Returns(targetLocationStub.Object);

            try
            {   // Act
                teleport.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object);
            }
            catch (TeleportOutOfRangeException ex)
            {   // Assert
                StringAssert.Contains("unitToTeleport.CurrentLocation", ex.Message);
            }
        }
        public void ThrowTeleportOutOfRangeExceptionWithSpecificMessage_WhenUnitPlanetIsDifferentThanTheStations()
        {
            // Arrange
            var businessOwnerMock  = new Mock <IBusinessOwner>();
            var galacticMapMock    = new Mock <IEnumerable <IPath> >();
            var locationMock       = new Mock <ILocation>();
            var unitMock           = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            var stationPlanetMock = new Mock <IPlanet>();
            var targetPlanetMock  = new Mock <IPlanet>();

            var stationGalaxyMock = new Mock <IGalaxy>();
            var targetGalaxyMock  = new Mock <IGalaxy>();

            locationMock.SetupGet(x => x.Planet.Name).Returns("Earth");
            locationMock.SetupGet(x => x.Planet.Galaxy.Name).Returns("Chiki-riki");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Mars");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Ne Chiki-riki");

            var station = new TeleportStation(businessOwnerMock.Object, galacticMapMock.Object, locationMock.Object);

            // Act & Assert
            var ex = Assert.Throws <TeleportOutOfRangeException>(() => station.TeleportUnit(unitMock.Object, targetLocationMock.Object));

            StringAssert.Contains("unitToTeleport.CurrentLocation", ex.Message);
        }
        public void ThrowInsufficientResourcesException_WhenTryToTeleportUnitWithInsuficientResources()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();

            var stationLocationStub = new Mock <ILocation>();

            stationLocationStub.SetupGet(l => l.Planet.Galaxy.Name).Returns("Milky way");
            stationLocationStub.SetupGet(l => l.Planet.Name).Returns("Earth");

            var targetLocationStub = new Mock <ILocation>();

            targetLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Andromeda");
            targetLocationStub.SetupGet(d => d.Planet.Name).Returns("Kobe");

            var pathStub = new Mock <IPath>();

            pathStub.SetupGet(p => p.TargetLocation.Planet.Galaxy.Name).Returns("Andromeda");
            pathStub.SetupGet(p => p.TargetLocation.Planet.Name).Returns("Kobe");
            pathStub.SetupGet(p => p.TargetLocation.Planet.Units).Returns(new List <IUnit>());

            var stationMapStub = new List <IPath> {
                pathStub.Object
            };

            var teleport = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(u => u.CurrentLocation).Returns(stationLocationStub.Object);
            unitToTeleportStub.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(false);
            // Act and Assert
            Assert.Throws <InsufficientResourcesException>(
                () => teleport.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object));
        }
Exemple #12
0
        public void TeleportUnit_WhenEverythingIsValid_ShouldCallUnitsPayMethodOnce()
        {
            //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(mockedCostToTravel.Object)).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 TeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);

            //Act
            teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationToTeleportTo.Object);
            //Assert
            mockedUnit.Verify(x => x.Pay(mockedCostToTravel.Object), Times.Once);
        }
        public void TestTeleportUnit_ShouldCallUnitToPay()
        {
            var mockedBusinessOwner = new Mock <IBusinessOwner>();
            var mockedPath          = new Mock <IPath>();

            var mockedDestination       = new Mock <ILocation>();
            var mockedDestinationPlanet = new Mock <IPlanet>();

            var mockedUnitThatIsThere = new Mock <IUnit>();

            mockedUnitThatIsThere.SetupGet(x => x.CurrentLocation).Returns(mockedDestination.Object);
            var collection = new List <IUnit>()
            {
            };

            mockedDestinationPlanet.SetupGet(x => x.Galaxy.Name).Returns("Milky Way");
            mockedDestinationPlanet.SetupGet(x => x.Name).Returns("Mars");
            mockedDestinationPlanet.SetupGet(x => x.Units).Returns(collection);

            mockedDestination.SetupGet(x => x.Planet).Returns(mockedDestinationPlanet.Object);
            mockedDestination.SetupGet(x => x.Coordinates.Latitude).Returns(15);
            mockedDestination.SetupGet(x => x.Coordinates.Longtitude).Returns(22);

            var mockedLocation = new Mock <ILocation>();

            var mockedUnit          = new Mock <IUnit>();
            var mockedCurrentPlanet = new Mock <IPlanet>();

            mockedCurrentPlanet.SetupGet(x => x.Galaxy.Name).Returns("Milky Way");
            mockedCurrentPlanet.SetupGet(x => x.Name).Returns("Mars");
            mockedLocation.SetupGet(x => x.Planet).Returns(mockedCurrentPlanet.Object);

            var mockedResource = new Mock <IResources>();

            mockedResource.SetupGet(x => x.GoldCoins).Returns(15);
            mockedResource.SetupGet(x => x.SilverCoins).Returns(15);
            mockedResource.SetupGet(x => x.BronzeCoins).Returns(15);

            mockedPath.SetupGet(x => x.TargetLocation).Returns(mockedDestination.Object);
            mockedPath.SetupGet(x => x.Cost).Returns(mockedResource.Object);

            var map = new List <IPath>()
            {
                mockedPath.Object
            };
            var teleportStation = new TeleportStation(mockedBusinessOwner.Object, map, mockedLocation.Object);

            mockedUnit.SetupGet(x => x.CurrentLocation).Returns(mockedLocation.Object);
            mockedUnit.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true);
            mockedUnit.Setup(x => x.Pay(It.IsAny <IResources>())).Returns(mockedResource.Object);
            mockedCurrentPlanet.SetupGet(x => x.Units).Returns(new List <IUnit>()
            {
                mockedUnit.Object
            });

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

            mockedUnit.Verify(x => x.Pay(It.IsAny <IResources>()), Times.Once);
        }
        public void RemoveTheUnitFromTheListOFUnitsOfThePreviousLocation_WhenUnitIsTeleported()
        {
            // Arrange
            var businessOwnerMock  = new Mock <IBusinessOwner>();
            var galacticMap        = new List <IPath>();
            var locationMock       = new Mock <ILocation>();
            var unitMock           = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            var stationPlanetMock = new Mock <IPlanet>();
            var targetPlanetMock  = new Mock <IPlanet>();

            var stationGalaxyMock = new Mock <IGalaxy>();
            var targetGalaxyMock  = new Mock <IGalaxy>();

            locationMock.SetupGet(x => x.Planet.Name).Returns("Earth");
            locationMock.SetupGet(x => x.Planet.Galaxy.Name).Returns("Chiki-riki");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Earth");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Chiki-riki");

            unitMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true);
            unitMock.SetupGet(x => x.Resources.GoldCoins).Returns(10);
            unitMock.SetupGet(x => x.Resources.BronzeCoins).Returns(10);
            unitMock.SetupGet(x => x.Resources.SilverCoins).Returns(10);

            targetLocationMock.SetupGet(x => x.Planet.Name).Returns("Mars");
            targetLocationMock.SetupGet(x => x.Planet.Galaxy.Name).Returns("Ne Chiki-riki");
            targetLocationMock.SetupGet(x => x.Coordinates.Latitude).Returns(1);
            targetLocationMock.SetupGet(x => x.Coordinates.Longtitude).Returns(1);

            var pathMock = new Mock <IPath>();

            pathMock.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Mars");
            pathMock.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Ne Chiki-riki");
            var units = new List <IUnit>();

            pathMock.SetupGet(x => x.TargetLocation.Planet.Units).Returns(units);
            var resourceMock = new Mock <IResources>();

            resourceMock.SetupGet(x => x.GoldCoins).Returns(10);
            resourceMock.SetupGet(x => x.BronzeCoins).Returns(10);
            resourceMock.SetupGet(x => x.SilverCoins).Returns(10);
            pathMock.SetupGet(x => x.Cost).Returns(resourceMock.Object);
            galacticMap.Add(pathMock.Object);

            unitMock.SetupGet(x => x.CurrentLocation.Planet.Units).Returns(new List <IUnit>()
            {
            });
            unitMock.Setup(x => x.Pay(It.IsAny <IResources>())).Returns(resourceMock.Object);

            var station = new TeleportStation(businessOwnerMock.Object, galacticMap, locationMock.Object);

            // Act
            station.TeleportUnit(unitMock.Object, targetLocationMock.Object);

            // Assert
            unitMock.Verify(x => x.CurrentLocation.Planet.Units.Remove(unitMock.Object), Times.Once);
        }
Exemple #15
0
        public void TeleportUnit_ShouldAccessUnitToTeleportPay_WhenInputParametersAreValid()
        {
            // Arrange
            var mockOwner           = new Mock <IBusinessOwner>();
            var mockGalacticMap     = new List <IPath>();
            var mockLocationStation = new Mock <ILocation>();
            var mockPlanetStation   = new Mock <IPlanet>();
            var mockGalaxyStation   = new Mock <IGalaxy>();

            mockPlanetStation.SetupGet(mock => mock.Name).Returns("planetStation");
            mockPlanetStation.SetupGet(mock => mock.Galaxy).Returns(mockGalaxyStation.Object);
            mockPlanetStation.SetupGet(mock => mock.Units).Returns(new List <IUnit>());
            mockGalaxyStation.SetupGet(mock => mock.Name).Returns("galaxyStation");
            mockLocationStation.SetupGet(mock => mock.Planet).Returns(mockPlanetStation.Object);

            var mockGalaxy = new Mock <IGalaxy>();

            mockGalaxy.SetupGet(mock => mock.Name).Returns("galaxy");

            var mockPlanet = new Mock <IPlanet>();

            mockPlanet.SetupGet(mock => mock.Name).Returns("planet");
            mockPlanet.SetupGet(mock => mock.Galaxy).Returns(mockGalaxy.Object);
            mockPlanet.SetupGet(mock => mock.Units).Returns(new List <IUnit>()
            {
            });

            var mockLocationPath = new Mock <ILocation>();

            mockLocationPath.SetupGet(mock => mock.Planet).Returns(mockPlanet.Object);

            var mockPathToDestination = new Mock <IPath>();

            mockPathToDestination.SetupGet(mock => mock.TargetLocation).Returns(mockLocationPath.Object);
            mockGalacticMap.Add(mockPathToDestination.Object);

            var mockUnitToTeleport = new Mock <IUnit>();

            mockUnitToTeleport.SetupGet(mock => mock.CurrentLocation).Returns(mockLocationStation.Object);
            mockUnitToTeleport.Setup(mock => mock.CanPay(It.IsAny <IResources>())).Returns(true);
            mockUnitToTeleport.Setup(mock => mock.Pay(It.IsAny <IResources>())).Returns(new Mock <IResources>().Object);

            var mockTargetLocation = new Mock <ILocation>();

            mockTargetLocation.SetupGet(mock => mock.Planet).Returns(mockPlanet.Object);
            mockTargetLocation.SetupGet(mock => mock.Coordinates.Longtitude).Returns((double)0);
            mockTargetLocation.SetupGet(mock => mock.Coordinates.Longtitude).Returns((double)0);

            var teleportStation = new TeleportStation(
                mockOwner.Object, mockGalacticMap, mockLocationStation.Object);

            // Act
            teleportStation.TeleportUnit(mockUnitToTeleport.Object, mockTargetLocation.Object);

            // Assert unit.Pay method was accessed.
            mockUnitToTeleport.Verify(mock => mock.Pay(It.IsAny <IResources>()), Times.Once());
        }
Exemple #16
0
        public void RequirePaymentFromUnit_WhenAllValidationsPass()
        {
            var owner       = new Mock <IBusinessOwner>();
            var galacticMap = new List <IPath>();
            var location    = new Mock <ILocation>();

            location.SetupGet(x => x.Planet.Name).Returns("Gosho");
            location.SetupGet(x => x.Planet.Galaxy.Name).Returns("Gosho");
            location.SetupGet(x => x.Coordinates.Latitude).Returns(1);
            location.SetupGet(x => x.Coordinates.Longtitude).Returns(1);
            var cost = new Mock <IResources>();

            cost.SetupGet(x => x.BronzeCoins).Returns(1);
            cost.SetupGet(x => x.GoldCoins).Returns(1);
            cost.SetupGet(x => x.SilverCoins).Returns(1);

            var teleportStation = new TeleportStation
                                      (owner.Object, galacticMap, location.Object);

            var unitInPath = new Mock <IUnit>();

            unitInPath.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Gosho");
            unitInPath.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Gosho");
            unitInPath.SetupGet(x => x.CurrentLocation.Coordinates.Latitude).Returns(1);
            unitInPath.SetupGet(x => x.CurrentLocation.Coordinates.Longtitude).Returns(2);

            var UnitsInPath = new List <IUnit>()
            {
                unitInPath.Object
            };

            var unit = new Mock <IUnit>();

            unit.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Gosho");
            unit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Gosho");
            unit.SetupGet(x => x.Resources.GoldCoins).Returns(12);
            unit.SetupGet(x => x.Resources.BronzeCoins).Returns(12);
            unit.SetupGet(x => x.Resources.SilverCoins).Returns(12);
            unit.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true);
            unit.Setup(x => x.Pay(It.IsAny <IResources>())).Returns(cost.Object);
            unit.Setup(x => x.CurrentLocation).Returns(location.Object);
            unit.Setup(x => x.PreviousLocation).Returns(location.Object);
            unit.Setup(x => x.CurrentLocation.Planet.Units).Returns(UnitsInPath);


            var path = new Mock <IPath>();

            path.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Gosho");
            path.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Gosho");
            path.SetupGet(x => x.TargetLocation.Planet.Units).Returns(UnitsInPath);
            path.SetupGet(x => x.Cost).Returns(cost.Object);
            galacticMap.Add(path.Object);

            teleportStation.TeleportUnit(unit.Object, location.Object);

            unit.Verify(x => x.Pay(It.IsAny <IResources>()), Times.Once);
        }
Exemple #17
0
        public void ThrowTeleportOutOfRangeException_WithSpecificStringMsg_WhenUnitTOTeleportUsingTeleportStation_FromDistantLocation(string galaxyName1,
                                                                                                                                      string galaxyName2,
                                                                                                                                      string plannetName1,
                                                                                                                                      string plannetName2)
        {
            var mockedOwner           = Mock.Create <IBusinessOwner>();
            var ListOfPaths           = new List <IPath>();
            var mockedStationLocation = Mock.Create <ILocation>();

            Mock.Arrange(() => mockedStationLocation.Coordinates).Returns(Mock.Create <IGPSCoordinates>());
            var stationPlanet = Mock.Create <IPlanet>();

            Mock.Arrange(() => stationPlanet.Galaxy.Name).Returns(galaxyName1);
            Mock.Arrange(() => stationPlanet.Name).Returns(plannetName1);

            Mock.Arrange(() => mockedStationLocation.Planet).Returns(stationPlanet);

            var unitMockedLocation = Mock.Create <ILocation>();

            Mock.Arrange(() => unitMockedLocation.Coordinates).Returns(Mock.Create <IGPSCoordinates>());
            var unitPlannet = Mock.Create <IPlanet>();

            Mock.Arrange(() => unitPlannet.Galaxy.Name).Returns(galaxyName2);
            Mock.Arrange(() => unitPlannet.Name).Returns(plannetName2);

            Mock.Arrange(() => unitMockedLocation.Planet).Returns(unitPlannet);

            var mockedUnitToTeleport = Mock.Create <IUnit>();

            Mock.Arrange(() => mockedUnitToTeleport.CurrentLocation).Returns(unitMockedLocation);

            var targetLocation = Mock.Create <ILocation>();
            var mockedPath     = Mock.Create <IPath>();

            Mock.Arrange(() => mockedPath.TargetLocation).Returns(targetLocation);
            Mock.Arrange(() => mockedPath.Cost).Returns(Mock.Create <IResources>());

            ListOfPaths.Add(mockedPath);

            var station = new TeleportStation(mockedOwner, ListOfPaths, mockedStationLocation);

            var expectedExceptionMsg = "unitToTeleport.CurrentLocation";
            var result = string.Empty;

            try
            {
                station.TeleportUnit(mockedUnitToTeleport, targetLocation);
            }
            catch (TeleportOutOfRangeException ex)
            {
                result = ex.Message;
            }

            StringAssert.Contains(expectedExceptionMsg, result);
        }
Exemple #18
0
        public void ThrowInsufficientResourcesExceptionWithProperMessage_WhenUnitCannotPayTeleportation()
        {
            var owner       = new Mock <IBusinessOwner>();
            var galacticMap = new List <IPath>();
            var location    = new Mock <ILocation>();

            location.SetupGet(x => x.Planet.Name).Returns("Gosho");
            location.SetupGet(x => x.Planet.Galaxy.Name).Returns("Gosho");
            location.SetupGet(x => x.Coordinates.Latitude).Returns(1);
            location.SetupGet(x => x.Coordinates.Longtitude).Returns(1);

            var teleportStation = new TeleportStation
                                      (owner.Object, galacticMap, location.Object);
            var expectedMessage = "FREE LUNCH";

            var unit = new Mock <IUnit>();

            unit.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Gosho");
            unit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Gosho");
            unit.SetupGet(x => x.Resources.GoldCoins).Returns(2);
            unit.SetupGet(x => x.Resources.BronzeCoins).Returns(2);
            unit.SetupGet(x => x.Resources.SilverCoins).Returns(2);


            var unitInPath = new Mock <IUnit>();

            unitInPath.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Gosho");
            unitInPath.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Gosho");
            unitInPath.SetupGet(x => x.CurrentLocation.Coordinates.Latitude).Returns(1);
            unitInPath.SetupGet(x => x.CurrentLocation.Coordinates.Longtitude).Returns(2);

            var cost = new Mock <IResources>();

            cost.SetupGet(x => x.BronzeCoins).Returns(5);
            cost.SetupGet(x => x.GoldCoins).Returns(5);
            cost.SetupGet(x => x.SilverCoins).Returns(5);

            var UnitsInPath = new List <IUnit>()
            {
                unitInPath.Object
            };
            var path = new Mock <IPath>();

            path.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Gosho");
            path.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Gosho");
            path.SetupGet(x => x.TargetLocation.Planet.Units).Returns(UnitsInPath);
            path.SetupGet(x => x.Cost).Returns(cost.Object);
            galacticMap.Add(path.Object);

            var exc = Assert.Throws <InsufficientResourcesException>
                          (() => teleportStation.TeleportUnit(unit.Object, location.Object));

            StringAssert.Contains(expectedMessage, exc.Message);
            // It got worse...
        }
        public void ThrowLocationNotFoundExceptionWithMessageWithStringGalaxy_WhenTryingToTeleportUnitToGalaxtWhichIsNotFoundInCurrentStation()
        {
            // arrange
            var ownerStub = new Mock <IBusinessOwner>();

            // setting up stations current location
            var    stationLocationStub       = new Mock <ILocation>();
            string stationLocationPlanetName = "Mars";
            string stationLocationGalaxyName = "Milky Way";

            stationLocationStub.Setup(x => x.Planet.Name)
            .Returns(stationLocationPlanetName);
            stationLocationStub.Setup(x => x.Planet.Galaxy.Name)
            .Returns(stationLocationGalaxyName);

            // setting up unit to teleport
            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(x => x.CurrentLocation)
            .Returns(stationLocationStub.Object);

            // setting up target location
            var    targetLocationStub       = new Mock <ILocation>();
            string targetLocationGalaxyName = "SomeGalaxy";

            targetLocationStub.Setup(x => x.Planet.Galaxy.Name)
            .Returns(targetLocationGalaxyName);

            // setting up path for the galactic map
            var    pathStub         = new Mock <IPath>();
            string targetGalaxyName = "OtherGalaxy";

            pathStub.Setup(x => x.TargetLocation.Planet.Galaxy.Name)
            .Returns(targetGalaxyName);

            // setting up galactic map
            var galacticMapStub = new List <IPath>()
            {
                pathStub.Object
            };

            var station = new TeleportStation(
                ownerStub.Object,
                galacticMapStub,
                stationLocationStub.Object);

            string expectedMessageEx = "Galaxy";

            // act and assert
            var ex = Assert.Throws <LocationNotFoundException>(
                () => station.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object));

            StringAssert.Contains(expectedMessageEx, ex.Message);
        }
Exemple #20
0
        public void ThrowArgumentNullException_IFTargetLocationIsNull()
        {
            var mockedOwner      = Mock.Create <IBusinessOwner>();
            var mockedLocation   = Mock.Create <ILocation>();
            var emptyListOfPaths = new List <IPath>();

            var mockedUnitToTeleport = Mock.Create <IUnit>();

            var station = new TeleportStation(mockedOwner, emptyListOfPaths, mockedLocation);

            Assert.Throws <ArgumentNullException>(() => station.TeleportUnit(mockedUnitToTeleport, null));
        }
Exemple #21
0
        public void ThrowLocationNotFoundException_WithMsgThatContainstPlanet_WhenTryToTeleportToGalaxyThatIsNotInTheList()
        {
            var anotherPlanetName        = "Casiopea";
            var targetLocationName       = "someRandomString";
            var targetLocationGalaxyName = "JustAnotherRandomString";
            var curentLocationName       = "namename";
            var curentGalaxyName         = "galaxyname";

            var mockedOwner        = Mock.Create <IBusinessOwner>();
            var stationListOfPaths = new List <IPath>();
            var mockedExsistedPath = Mock.Create <IPath>();

            Mock.Arrange(() => mockedExsistedPath.TargetLocation.Planet.Galaxy.Name).Returns(targetLocationGalaxyName);
            Mock.Arrange(() => mockedExsistedPath.TargetLocation.Planet.Name).Returns(anotherPlanetName);
            Mock.Arrange(() => mockedExsistedPath.Cost).Returns(Mock.Create <IResources>());

            stationListOfPaths.Add(mockedExsistedPath);

            var mockedStationLocation = Mock.Create <ILocation>();

            Mock.Arrange(() => mockedStationLocation.Coordinates).Returns(Mock.Create <IGPSCoordinates>());
            var stationPlanet = Mock.Create <IPlanet>();

            Mock.Arrange(() => stationPlanet.Galaxy.Name).Returns(curentGalaxyName);
            Mock.Arrange(() => stationPlanet.Name).Returns(curentLocationName);

            Mock.Arrange(() => mockedStationLocation.Planet).Returns(stationPlanet);

            var mockedUnitToTeleport = Mock.Create <IUnit>();

            Mock.Arrange(() => mockedUnitToTeleport.CurrentLocation).Returns(mockedStationLocation);

            var mockedTargetLovation = Mock.Create <ILocation>();

            Mock.Arrange(() => mockedTargetLovation.Planet.Name).Returns(targetLocationName);
            Mock.Arrange(() => mockedTargetLovation.Planet.Galaxy.Name).Returns(targetLocationGalaxyName);

            var station = new TeleportStation(mockedOwner, stationListOfPaths, mockedStationLocation);

            var expected = "Planet";
            var result   = string.Empty;

            try
            {
                station.TeleportUnit(mockedUnitToTeleport, mockedTargetLovation);
            }
            catch (LocationNotFoundException ex)
            {
                result = ex.Message;
            }

            StringAssert.Contains(expected, result);
        }
Exemple #22
0
        public void TeleportUnit_ShouldThrowInsufficientResourcesException_WhenServiceCostsMoreThanUnitsResources()
        {
            var mockOwner           = new Mock <IBusinessOwner>();
            var mockGalacticMap     = new List <IPath>();
            var mockLocationStation = new Mock <ILocation>();
            var mockPlanetStation   = new Mock <IPlanet>();
            var mockGalaxyStation   = new Mock <IGalaxy>();

            mockPlanetStation.SetupGet(mock => mock.Name).Returns("planetStation");
            mockPlanetStation.SetupGet(mock => mock.Galaxy).Returns(mockGalaxyStation.Object);
            mockGalaxyStation.SetupGet(mock => mock.Name).Returns("galaxyStation");
            mockLocationStation.SetupGet(mock => mock.Planet).Returns(mockPlanetStation.Object);

            var mockGalaxy = new Mock <IGalaxy>();

            mockGalaxy.SetupGet(mock => mock.Name).Returns("galaxy");

            var mockPlanet = new Mock <IPlanet>();

            mockPlanet.SetupGet(mock => mock.Name).Returns("planet");
            mockPlanet.SetupGet(mock => mock.Galaxy).Returns(mockGalaxy.Object);
            mockPlanet.SetupGet(mock => mock.Units).Returns(new List <IUnit>()
            {
            });

            var mockLocationPath = new Mock <ILocation>();

            mockLocationPath.SetupGet(mock => mock.Planet).Returns(mockPlanet.Object);

            var mockPathToDestination = new Mock <IPath>();

            mockPathToDestination.SetupGet(mock => mock.TargetLocation).Returns(mockLocationPath.Object);
            mockGalacticMap.Add(mockPathToDestination.Object);

            // Arrange mock unit to teleport. Setup CanPay to return False explicitly. ( moq-ed bool returns false by default anyway ).
            var mockUnitToTeleport = new Mock <IUnit>();

            mockUnitToTeleport.SetupGet(mock => mock.CurrentLocation).Returns(mockLocationStation.Object);
            mockUnitToTeleport.Setup(mock => mock.CanPay(It.IsAny <IResources>())).Returns(false);

            var mockTargetLocation = new Mock <ILocation>();

            mockTargetLocation.SetupGet(mock => mock.Planet).Returns(mockPlanet.Object);
            mockTargetLocation.SetupGet(mock => mock.Coordinates.Longtitude).Returns((double)0);
            mockTargetLocation.SetupGet(mock => mock.Coordinates.Longtitude).Returns((double)0);

            var teleportStation = new TeleportStation(
                mockOwner.Object, mockGalacticMap, mockLocationStation.Object);

            // Act and Assert.
            Assert.That(() => teleportStation.TeleportUnit(mockUnitToTeleport.Object, mockTargetLocation.Object),
                        Throws.InstanceOf <InsufficientResourcesException>().With.Message.Contains("FREE LUNCH"));
        }
        public void ThrowArgumentNullExceptionWhenLocaltionIsNull()
        {
            //Arrange
            var ownerMock    = Mock.Create <IBusinessOwner>();
            var locationMock = Mock.Create <ILocation>();
            var unitMock     = Mock.Create <IUnit>();
            var mapMock      = Mock.Create <IEnumerable <IPath> >();
            var sut          = new TeleportStation(ownerMock, mapMock, locationMock);

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => sut.TeleportUnit(unitMock, null));
        }
Exemple #24
0
        public void TeleportUnit_WhenTeleportingToAlreadyTakenLocation_ShouldThrowInvalidTeleportationLocationExceptionWithCorrectMessage()
        {
            //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");
            mockedLocation.SetupGet(x => x.Coordinates.Latitude).Returns(1);
            mockedLocation.SetupGet(x => x.Coordinates.Longtitude).Returns(1);
            var mockedUnitTwo = new Mock <IUnit>();

            mockedUnitTwo.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.Coordinates.Latitude).Returns(1);
            mockedLocationToTeleportTo.SetupGet(x => x.Coordinates.Longtitude).Returns(1);

            mockedLocationToTeleportTo.SetupGet(x => x.Planet.Galaxy).Returns(mockedUnitGalaxy.Object);
            var mockedUnit = new Mock <IUnit>();

            mockedUnit.Setup(x => x.CurrentLocation).Returns(mockedLocationToTeleportTo.Object);

            var mockedGalacticMap = new List <IPath>();
            var mockedPath        = new Mock <IPath>();

            mockedPath.SetupGet(x => x.TargetLocation).Returns(mockedLocationToTeleportTo.Object);
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Units).Returns(new List <IUnit>()
            {
                mockedUnit.Object
            });
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Milky Way");
            mockedPath.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Earth");
            var mockedResource = new Mock <IResources>();

            mockedPath.SetupGet(x => x.Cost).Returns(mockedResource.Object);

            mockedGalacticMap.Add(mockedPath.Object);
            var teleportStation = new TeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);
            //Act and Assert
            var ex = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(mockedUnitTwo.Object, mockedLocationToTeleportTo.Object));

            StringAssert.Contains("units will overlap", ex.Message);
        }
Exemple #25
0
        public void ThrowArgumentNullExceptionWithMessageContainingUnitToTeleport_WhenUnitToTeleportIsNull()
        {
            var owner           = new Mock <IBusinessOwner>();
            var galacticMap     = new List <IPath>();
            var location        = new Mock <ILocation>();
            var teleportStation = new TeleportStation(owner.Object, galacticMap, location.Object);
            var expectedMessage = "unitToTeleport";

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

            StringAssert.Contains(expectedMessage, exc.Message);
        }
        public void ThrowArgumentNullException_WhenUnitToTeleportIsNull()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();
            var stationMapStub   = new List <IPath> {
                new Mock <IPath>().Object
            };
            var stationLocationStub = new Mock <ILocation>();
            var teleport            = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            // Act and Assert
            Assert.Throws <ArgumentNullException>(() => teleport.TeleportUnit(null, stationLocationStub.Object));
        }
        public void ThrowArgumentNullExceptionWithSpecificMessage_WhenILocationToTeleportIsNull()
        {
            // Arrange
            var businessOwnerMock = new Mock <IBusinessOwner>();
            var galacticMapMock   = new Mock <IEnumerable <IPath> >();
            var locationMock      = new Mock <ILocation>();
            var station           = new TeleportStation(businessOwnerMock.Object, galacticMapMock.Object, locationMock.Object);
            var unitMock          = new Mock <IUnit>();

            // Act & Assert
            var ex = Assert.Throws <ArgumentNullException>(() => station.TeleportUnit(unitMock.Object, null));

            StringAssert.Contains("destination", ex.Message);
        }
Exemple #28
0
        public void TeleportUnit_WhenUnitDoesntHaveEnoughResourcesToTeleport_ShouldThrowInsufficientResourcesExceptionWithCorrectMessage()
        {
            //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(1);
            mockedMoneyForUnit.SetupGet(x => x.GoldCoins).Returns(0);
            mockedMoneyForUnit.SetupGet(x => x.SilverCoins).Returns(0);
            mockedUnit.SetupGet(x => x.Resources).Returns(mockedMoneyForUnit.Object);
            var mockedCostToTravel = new Mock <IResources>();

            mockedCostToTravel.SetupGet(x => x.BronzeCoins).Returns(500000);
            mockedCostToTravel.SetupGet(x => x.GoldCoins).Returns(500000);
            mockedCostToTravel.SetupGet(x => x.SilverCoins).Returns(500000);
            mockedPath.SetupGet(x => x.Cost).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>());
            mockedGalacticMap.Add(mockedPath.Object);
            var teleportStation = new TeleportStation(mockedBusinessOwner.Object, mockedGalacticMap, mockedLocation.Object);
            //Act and Assert
            var ex = Assert.Throws <InsufficientResourcesException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocationToTeleportTo.Object));

            StringAssert.Contains("FREE LUNCH", ex.Message);
        }
        public void ThrowInvalidTeleportationLocationExceptionWithSpecificMessage_WhenTargetLocationIsAlreadyTaken()
        {
            // Arrange
            var businessOwnerMock  = new Mock <IBusinessOwner>();
            var galacticMap        = new List <IPath>();
            var locationMock       = new Mock <ILocation>();
            var unitMock           = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            var stationPlanetMock = new Mock <IPlanet>();
            var targetPlanetMock  = new Mock <IPlanet>();

            var stationGalaxyMock = new Mock <IGalaxy>();
            var targetGalaxyMock  = new Mock <IGalaxy>();

            locationMock.SetupGet(x => x.Planet.Name).Returns("Earth");
            locationMock.SetupGet(x => x.Planet.Galaxy.Name).Returns("Chiki-riki");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Earth");
            unitMock.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Chiki-riki");

            targetLocationMock.SetupGet(x => x.Planet.Name).Returns("Mars");
            targetLocationMock.SetupGet(x => x.Planet.Galaxy.Name).Returns("Ne Chiki-riki");
            targetLocationMock.SetupGet(x => x.Coordinates.Latitude).Returns(1);
            targetLocationMock.SetupGet(x => x.Coordinates.Longtitude).Returns(1);

            var pathMock = new Mock <IPath>();

            pathMock.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Mars");
            pathMock.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Ne Chiki-riki");

            var otherUnitMock = new Mock <IUnit>();

            otherUnitMock.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Mars");
            otherUnitMock.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Ne Chiki-riki");
            otherUnitMock.SetupGet(x => x.CurrentLocation.Coordinates.Latitude).Returns(1);
            otherUnitMock.SetupGet(x => x.CurrentLocation.Coordinates.Longtitude).Returns(1);
            pathMock.SetupGet(x => x.TargetLocation.Planet.Units).Returns(new List <IUnit>()
            {
                otherUnitMock.Object
            });
            galacticMap.Add(pathMock.Object);

            var station = new TeleportStation(businessOwnerMock.Object, galacticMap, locationMock.Object);

            // Act & Assert
            var ex = Assert.Throws <InvalidTeleportationLocationException>(() => station.TeleportUnit(unitMock.Object, targetLocationMock.Object));

            StringAssert.Contains("units will overlap", ex.Message);
        }
        public void ThrowWithMessageContainingTheStringUnitsWillOverlap_WhenTryToTeleportUnitToLocationWhichAnotherUnitHasAlreadyTaken()
        {
            // Arrange
            var stationOwnerStub = new Mock <IBusinessOwner>();

            var stationLocationStub = new Mock <ILocation>();

            stationLocationStub.SetupGet(l => l.Planet.Galaxy.Name).Returns("Milky way");
            stationLocationStub.SetupGet(l => l.Planet.Name).Returns("Earth");
            stationLocationStub.SetupGet(l => l.Coordinates.Latitude).Returns(94.00);
            stationLocationStub.SetupGet(l => l.Coordinates.Longtitude).Returns(17.00);

            var targetLocationStub = new Mock <ILocation>();

            targetLocationStub.SetupGet(d => d.Planet.Galaxy.Name).Returns("Andromeda");
            targetLocationStub.SetupGet(d => d.Planet.Name).Returns("Kobe");
            targetLocationStub.SetupGet(d => d.Coordinates.Latitude).Returns(94.00);
            targetLocationStub.SetupGet(d => d.Coordinates.Longtitude).Returns(17.00);

            var unitAlreadyAtTargetLocationStub = new Mock <IUnit>();

            unitAlreadyAtTargetLocationStub.Setup(u => u.CurrentLocation).Returns(targetLocationStub.Object);

            var pathStub = new Mock <IPath>();

            pathStub.SetupGet(p => p.TargetLocation.Planet.Galaxy.Name).Returns("Andromeda");
            pathStub.SetupGet(p => p.TargetLocation.Planet.Name).Returns("Kobe");
            pathStub.SetupGet(p => p.TargetLocation.Planet.Units).Returns(new List <IUnit> {
                unitAlreadyAtTargetLocationStub.Object
            });

            var stationMapStub = new List <IPath> {
                pathStub.Object
            };

            var teleport = new TeleportStation(stationOwnerStub.Object, stationMapStub, stationLocationStub.Object);

            var unitToTeleportStub = new Mock <IUnit>();

            unitToTeleportStub.Setup(u => u.CurrentLocation).Returns(stationLocationStub.Object);
            try
            {   // Act
                teleport.TeleportUnit(unitToTeleportStub.Object, targetLocationStub.Object);
            }
            catch (InvalidTeleportationLocationException ex)
            {   // Assert
                StringAssert.Contains("units will overlap", ex.Message);
            }
        }