public void ThrowLocationNotFoundException_WhenTryingToTeleportUnitToPlanetWhichDoesntExistInTheGalacticMapOfTheTeleportStation() { // Arrange var expectedExceptionMessage = "Planet"; var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns("DifferentPlanetName"); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); var planetaryUnitsList = new List <IUnit> { planetaryUnitMock.Object }; pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(planetaryUnitsList); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); // Act & Assert var exc = Assert.Throws <LocationNotFoundException>( () => teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object)); var actualExceptionMessage = exc.Message; // Assert StringAssert.Contains(expectedExceptionMessage, actualExceptionMessage); }
public void ThrowTeleportOutOfRangeException_WhenUnitIsTryingToUseTheTeleportStationFromPlanetOrGalaxyDifferentThanThatOfTheStationItself() { // Arrange var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var teleportStationMapMock = new Mock <IEnumerable <IPath> >(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns("PLANET-1"); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns("GALAXY-1"); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns("PLANET-2"); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("GALAXY-2"); var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock.Object, teleportStationLocationMock.Object); var expectedExceptionMessage = "unitToTeleport.CurrentLocation"; // Act & Assert var exc = Assert.Throws <TeleportOutOfRangeException>( () => teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object)); var actualExceptionMessage = exc.Message; // Assert StringAssert.Contains(expectedExceptionMessage, actualExceptionMessage); }
public void TeleportUnitShouldThrowTeleportOutOfRangeExceptionWhenUnitTryingToUseTeleportStationFromDistantLoc() { //Arrange var unit = new Mock <IUnit>(); var objUnit = unit.Object; var destinLoc = new Mock <ILocation>(); var objDestinLoc = destinLoc.Object; var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalacticMap = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var objOwner = mockedOwner.Object; var objGalacticMap = mockedGalacticMap.Object; var objStationLocation = mockedLocation.Object; unit.Setup(u => u.CurrentLocation.Planet.Name).Returns("Braxis"); unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns("Outer Galaxy"); mockedLocation.Setup(loc => loc.Planet.Name).Returns("Mar Sara"); mockedLocation.Setup(loc => loc.Planet.Galaxy.Name).Returns("Inner Galaxy"); var teleportStation = new ExtendedTeleportStation(objOwner, objGalacticMap, objStationLocation); //Act var exception = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(objUnit, objDestinLoc)); var actualMessage = exception.Message; var expectedSubstr = "unitToTeleport.CurrentLocation"; //Assert StringAssert.Contains(expectedSubstr, actualMessage); }
public void ObtainAPayment_WhenTheUnitIsReadyForTeleportation() { // Arrange var unitToTeleportMock = new Mock <IUnit>(); var targetLocationMock = new Mock <ILocation>(); ExtendedTeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation(); TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location); TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location, TeleportStationConstants.OtherLongtitude, TeleportStationConstants.OtherLatitude); unitToTeleportMock.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(u => u.Pay(TeleportStationHelpers.Path.Cost)).Returns(TeleportStationHelpers.Path.Cost); IUnit expectedUnitToTeleport = unitToTeleportMock.Object; ILocation expectedTargetLocation = targetLocationMock.Object; // Act teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation); uint actualBronzeCoins = teleportStation.Resources.BronzeCoins; uint actualSilverCoins = teleportStation.Resources.SilverCoins; uint actualGoldCoins = teleportStation.Resources.GoldCoins; // Assert Assert.AreEqual(TeleportStationConstants.BronzeCoins, actualBronzeCoins); Assert.AreEqual(TeleportStationConstants.SilverCoins, actualSilverCoins); Assert.AreEqual(TeleportStationConstants.GoldCoins, actualGoldCoins); }
public void ThrowInvalidTeleportationLocationException_WhenTryingToTeleportUnitToLocationWhichIsAlreadyTakenByAnotherUnit() { // Arrange var expectedExceptionMessage = "units will overlap"; var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); var planetaryUnitsList = new List <IUnit> { planetaryUnitMock.Object }; pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(planetaryUnitsList); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); // Act & Assert var exc = Assert.Throws <InvalidTeleportationLocationException>( () => teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object)); var actualExceptionMessage = exc.Message; // Assert StringAssert.Contains(expectedExceptionMessage, actualExceptionMessage); }
public void TeleportUnitShouldThrowLocationNotFoundWhenGalaxyNotFound() { //Arrange var stationOwner = new Mock <IBusinessOwner>(); var planet = "Mar Sara"; var galaxy = "Inner Galaxy"; var longitude = 20.00; var latitude = 10.00; //var knownTargetLoc = new Mock<ILocation>(); //knownTargetLoc.Setup(l => l.Planet.Name).Returns(planet); //knownTargetLoc.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); //knownTargetLoc.Setup(l => l.Coordinates.Longtitude).Returns(longitude); //knownTargetLoc.Setup(l => l.Coordinates.Latitude).Returns(latitude); var path = new Mock <IPath>(); path.Setup(p => p.Cost.BronzeCoins).Returns(10); path.Setup(p => p.Cost.GoldCoins).Returns(20); path.Setup(p => p.Cost.SilverCoins).Returns(30); //path.Setup(p => p.TargetLocation.Coordinates.Longtitude).Returns(longitude); //path.Setup(p => p.TargetLocation.Coordinates.Latitude).Returns(latitude); path.Setup(p => p.TargetLocation.Planet.Name).Returns(planet); path.Setup(p => p.TargetLocation.Planet.Galaxy.Name).Returns("Solar System"); var stationMap = new List <IPath> { path.Object }; var stationLoc = new Mock <ILocation>(); var station = new ExtendedTeleportStation(stationOwner.Object, stationMap, stationLoc.Object); var unit = new Mock <IUnit>(); unit.Setup(u => u.CurrentLocation.Planet.Name).Returns(planet); unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns(galaxy); unit.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(longitude); unit.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(latitude); var destination = new Mock <ILocation>(); destination.Setup(l => l.Planet.Name).Returns(planet); destination.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); destination.Setup(l => l.Coordinates.Latitude).Returns(latitude); destination.Setup(l => l.Coordinates.Longtitude).Returns(longitude); stationLoc.Setup(l => l.Planet.Name).Returns(planet); stationLoc.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); //Act var exception = Assert.Throws <LocationNotFoundException>(() => station.TeleportUnit(unit.Object, destination.Object)); var message = exception.Message; var expectedSubstring = "Galaxy"; //Assert StringAssert.Contains(expectedSubstring, message); }
public void ThrowArgumentNullException_WhenTheParameterTargetLocationIsNull() { // Arrange var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var teleportStationMapMock = new Mock <IEnumerable <IPath> >(); var unitToTeleportMock = new Mock <IUnit>(); var targetLocation = (ILocation)null; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock.Object, teleportStationLocationMock.Object); var expectedExceptionMessage = "destination"; // Act & Assert var exc = Assert.Throws <ArgumentNullException>( () => teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocation)); var actualExceptionMessage = exc.Message; // Assert StringAssert.Contains(expectedExceptionMessage, actualExceptionMessage); }
public void SetupAllOfTheProvidedFields_WhenValidParametersArePased() { // Arrange var locationMock = new Mock <ILocation>(); var ownerMock = new Mock <IBusinessOwner>(); var mapMock = new Mock <IEnumerable <IPath> >(); var expectedMap = mapMock.Object; var expectedOwner = ownerMock.Object; var expectedLocation = locationMock.Object; // Act var teleportStation = new ExtendedTeleportStation(expectedOwner, expectedMap, expectedLocation); var actualOwner = teleportStation.Owner; var actualMap = teleportStation.GalacticMap; var actualLocation = teleportStation.Location; // Assert Assert.AreSame(expectedOwner, actualOwner); Assert.AreSame(expectedLocation, actualLocation); Assert.AreSame(expectedMap, actualMap); }
public void TeleportUnitShouldThrowArgumentNullExceptionWhenIUnitUnitToTeleportNull() { //Arrange var location = new Mock <ILocation>(); var objLocation = location.Object; var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalacticMap = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var objOwner = mockedOwner.Object; var objGalacticMap = mockedGalacticMap.Object; var objStationLocation = mockedLocation.Object; var teleportStation = new ExtendedTeleportStation(objOwner, objGalacticMap, objStationLocation); //Act var exception = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(null, objLocation)); var actualMessage = exception.Message; var expectedSubstr = "unitToTeleport"; //Assert StringAssert.Contains(expectedSubstr, actualMessage); }
public void ConstructorShouldSetAllProvidedFields() { //Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalacticMap = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var expectedOwner = mockedOwner.Object; var expectedGalacticMap = mockedGalacticMap.Object; var expectedLocation = mockedLocation.Object; //Act var teleportStation = new ExtendedTeleportStation(expectedOwner, expectedGalacticMap, expectedLocation); var actualOwner = teleportStation.Owner; var actualGalacticMap = teleportStation.GalacticMap; var actualLocation = teleportStation.Location; //Assert Assert.AreEqual(expectedOwner, actualOwner); Assert.AreEqual(expectedGalacticMap, actualGalacticMap); Assert.AreEqual(expectedLocation, actualLocation); }
internal static ExtendedTeleportStation ArrangeTeleportStation() { var ownerMock = new Mock <IBusinessOwner>(); var locationMock = new Mock <ILocation>(); var pathMock = new Mock <IPath>(); var unitMock = new Mock <IUnit>(); ownerMock.Setup(o => o.IdentificationNumber).Returns(TeleportStationConstants.IdentificationNumber); locationMock.Setup(l => l.Planet.Galaxy.Name).Returns(TeleportStationConstants.Galaxy); locationMock.Setup(l => l.Planet.Name).Returns(TeleportStationConstants.Location); locationMock.Setup(l => l.Coordinates.Longtitude).Returns(TeleportStationConstants.Longtitude); locationMock.Setup(l => l.Coordinates.Latitude).Returns(TeleportStationConstants.Latitude); IBusinessOwner expectedOwner = ownerMock.Object; IEnumerable <IPath> expectedMap = ArrangeGalacticMock(ref pathMock, ref unitMock); ILocation expectedLocation = locationMock.Object; ExtendedTeleportStation teleportStation = new ExtendedTeleportStation(expectedOwner, expectedMap, expectedLocation); return(teleportStation); }
public void SetUpAllTheProdivedFields_WhenNewInstanceIsCreated() { // Arrange var ownerMock = new Mock <IBusinessOwner>(); var galacticMapMock = new Mock <IEnumerable <IPath> >(); var locationMock = new Mock <ILocation>(); IBusinessOwner expectedOwner = ownerMock.Object; IEnumerable <IPath> expectedMap = galacticMapMock.Object; ILocation expectedLocation = locationMock.Object; // Act ExtendedTeleportStation teleportStation = new ExtendedTeleportStation(expectedOwner, expectedMap, expectedLocation); IBusinessOwner actualOwner = teleportStation.Owner; IEnumerable <IPath> actualMap = teleportStation.GalacticMap; ILocation actualLocation = teleportStation.Location; // Assert Assert.AreEqual(expectedOwner, actualOwner); Assert.AreEqual(expectedMap, actualMap); Assert.AreEqual(expectedLocation, actualLocation); }
public void TeleportUnitWithNullDestinationshouldThrowMessageShouldContainDestination() { //Arrange var unit = new Mock <IUnit>(); var objUnit = unit.Object; var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalacticMap = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var objOwner = mockedOwner.Object; var objGalacticMap = mockedGalacticMap.Object; var objStationLocation = mockedLocation.Object; var teleportStation = new ExtendedTeleportStation(objOwner, objGalacticMap, objStationLocation); //Act var exception = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(objUnit, null)); var actualMessage = exception.Message; var expectedSubstr = "destination"; //Assert StringAssert.Contains(expectedSubstr, actualMessage); }
public void RemoveTheTeleportedUnitFromTheListsOfUnitsOfTheCurrentLocation_WhenTheUnitIsReadyForTeleportation() { // Arrange var unitToTeleportMock = new Mock <IUnit>(); var targetLocationMock = new Mock <ILocation>(); ExtendedTeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation(); TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location); TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location, TeleportStationConstants.OtherLongtitude, TeleportStationConstants.OtherLatitude); unitToTeleportMock.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(u => u.Pay(TeleportStationHelpers.Path.Cost)).Returns(TeleportStationHelpers.Path.Cost); IUnit expectedUnitToTeleport = unitToTeleportMock.Object; ILocation expectedTargetLocation = targetLocationMock.Object; // Act teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation); // Assert TeleportStationHelpers.UnitsMock.Verify(u => u.Remove(unitToTeleportMock.Object), Times.Once()); }
public void ReturnTheTotalAmountOfProfits_WhenTheArgumentPassedIsTheActualOwner() { // Arrange var unitToTeleportMock = new Mock <IUnit>(); var targetLocationMock = new Mock <ILocation>(); var ownerMock = new Mock <IBusinessOwner>(); ExtendedTeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation(); TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location); TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location, TeleportStationConstants.OtherLongtitude, TeleportStationConstants.OtherLatitude); ownerMock.Setup(o => o.IdentificationNumber).Returns(TeleportStationConstants.IdentificationNumber); unitToTeleportMock.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(u => u.Pay(TeleportStationHelpers.Path.Cost)).Returns(TeleportStationHelpers.Path.Cost); IUnit expectedUnitToTeleport = unitToTeleportMock.Object; ILocation expectedTargetLocation = targetLocationMock.Object; IBusinessOwner expectedOwner = ownerMock.Object; teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation); uint expectedBronzeCoins = teleportStation.Resources.BronzeCoins; uint expectedSilverCoins = teleportStation.Resources.SilverCoins; uint expectedGoldCoins = teleportStation.Resources.GoldCoins; // Act IResources resources = teleportStation.PayProfits(expectedOwner); uint actualBronzeCoins = resources.BronzeCoins; uint actualSilverCoins = resources.SilverCoins; uint actualGoldCoins = resources.GoldCoins; // Assert Assert.AreEqual(expectedBronzeCoins, actualBronzeCoins); Assert.AreEqual(expectedSilverCoins, actualSilverCoins); Assert.AreEqual(expectedGoldCoins, actualGoldCoins); }
public void ThrowInsufficientResourcesException_WhenTryingToTeleportUnitButTheServiceCostsMoreThanTheUnitCurrentAvailableResources() { // Arrange var expectedExceptionMessage = "FREE LUNCH"; var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude + 15d); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude + 15d); var planetaryUnitsList = new List <IUnit> { planetaryUnitMock.Object }; pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(planetaryUnitsList); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); unitToTeleportMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(false); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); // Act & Assert var exc = Assert.Throws <InsufficientResourcesException>( () => teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object)); var actualExceptionMessage = exc.Message; // Assert StringAssert.Contains(expectedExceptionMessage, actualExceptionMessage); }
public void ReturnTheTotalAmountOfProfitsGeneratedUsingTheTeleportUnitService_WhenTheArgumentPassedRepresentsTheActualOwnerOfTheTeleportStation() { // Arrange var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); teleportStationOwnerMock.Setup(x => x.IdentificationNumber).Returns(12412); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude + 15d); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude + 15d); var targetLocationPlanetaryUnitsCollectionEnumeratorMock = new Mock <IEnumerator <IUnit> >(); targetLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns(planetaryUnitMock.Object) .Callback( () => targetLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns((IUnit)null)); var targetLocationPlanetaryUnitsCollectionMock = new Mock <IList <IUnit> >(); targetLocationPlanetaryUnitsCollectionMock.Setup(x => x.GetEnumerator()).Returns(targetLocationPlanetaryUnitsCollectionEnumeratorMock.Object); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(targetLocationPlanetaryUnitsCollectionMock.Object); var currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock = new Mock <IEnumerator <IUnit> >(); currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns(unitToTeleportMock.Object) .Callback( () => currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns((IUnit)null)); var currentUnitLocationPlanetaryUnitsCollectionMock = new Mock <IList <IUnit> >(); currentUnitLocationPlanetaryUnitsCollectionMock.Setup(x => x.GetEnumerator()).Returns(currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock.Object); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); var initialTeleportStationResources = teleportStation.Resources.Clone(); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); unitToTeleportMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(x => x.Pay(pathMock.Object.Cost)).Returns(pathMock.Object.Cost); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Units).Returns(currentUnitLocationPlanetaryUnitsCollectionMock.Object); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); var expectedResourcesAmount = new Mock <IResources>(); expectedResourcesAmount.Setup(x => x.BronzeCoins).Returns(500); expectedResourcesAmount.Setup(x => x.SilverCoins).Returns(400); expectedResourcesAmount.Setup(x => x.GoldCoins).Returns(300); teleportStation.Resources.Add(expectedResourcesAmount.Object); // Act var actualResourcesAmount = teleportStation.PayProfits(teleportStationOwnerMock.Object); // Assert Assert.AreEqual(expectedResourcesAmount.Object.BronzeCoins, actualResourcesAmount.BronzeCoins); Assert.AreEqual(expectedResourcesAmount.Object.SilverCoins, actualResourcesAmount.SilverCoins); Assert.AreEqual(expectedResourcesAmount.Object.GoldCoins, actualResourcesAmount.GoldCoins); }
public void ObtainPaymentFromTheUnitThatIsBeingTeleportedWithTheAmountOfPathCost_WhenTheValidationsPassSuccessfullyAndTheUnitsIsReadyForTeleportation() { // Arrange var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude + 15d); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude + 15d); var planetaryUnitsList = new List <IUnit> { planetaryUnitMock.Object }; pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(planetaryUnitsList); var currentUnitLocationPlanetaryUnitsList = new List <IUnit> { unitToTeleportMock.Object }; var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); var initialTeleportStationResources = teleportStation.Resources.Clone(); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); unitToTeleportMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(x => x.Pay(pathMock.Object.Cost)).Returns(pathMock.Object.Cost); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Units).Returns(currentUnitLocationPlanetaryUnitsList); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); var expectedBronzeCoins = initialTeleportStationResources.BronzeCoins + pathMock.Object.Cost.BronzeCoins; var expectedSilverCoins = initialTeleportStationResources.SilverCoins + pathMock.Object.Cost.SilverCoins; var expectedGoldCoins = initialTeleportStationResources.GoldCoins + pathMock.Object.Cost.GoldCoins; // Act teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object); var actualBronzeCoins = teleportStation.Resources.BronzeCoins; var actualSilverCoins = teleportStation.Resources.SilverCoins; var actualGoldcoins = teleportStation.Resources.GoldCoins; // Assert Assert.AreEqual(expectedBronzeCoins, actualBronzeCoins); Assert.AreEqual(expectedSilverCoins, actualSilverCoins); Assert.AreEqual(expectedGoldCoins, actualGoldcoins); }
public void TeleportUnitShouldRequirePaymentFromUnitToTeleportForServicesAfterValidationsBeforeTeleport() { //Arrange var planet = "Chau Sara"; var galaxy = "Inner Galaxy"; var longitude = 10.00; var latitude = 20.00; var stationLoc = new Mock <ILocation>(); stationLoc.Setup(l => l.Planet.Name).Returns(planet); stationLoc.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); var stationOwner = new Mock <IBusinessOwner>(); var path = new Mock <IPath>(); path.Setup(p => p.Cost.BronzeCoins).Returns(5); path.Setup(p => p.Cost.GoldCoins).Returns(5); path.Setup(p => p.Cost.SilverCoins).Returns(5); path.Setup(p => p.TargetLocation.Planet.Name).Returns(planet); path.Setup(p => p.TargetLocation.Planet.Galaxy.Name).Returns(galaxy); var destination = new Mock <ILocation>(); destination.Setup(l => l.Planet.Name).Returns(planet); destination.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); destination.Setup(l => l.Coordinates.Latitude).Returns(latitude); destination.Setup(l => l.Coordinates.Longtitude).Returns(longitude); var unitAtDestination = new Mock <IUnit>(); unitAtDestination.Setup(u => u.CurrentLocation.Planet.Name).Returns("Chau Sara"); unitAtDestination.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns("Outer region"); unitAtDestination.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(longitude); unitAtDestination.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(latitude); var destinationUnitList = new List <IUnit> { unitAtDestination.Object }; path.Setup(p => p.TargetLocation.Planet.Units).Returns(destinationUnitList); var stationMap = new List <IPath> { path.Object }; var station = new ExtendedTeleportStation(stationOwner.Object, stationMap, stationLoc.Object); var unit = new Mock <IUnit>(); unit.Setup(u => u.CurrentLocation.Planet.Name).Returns(planet); unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns(galaxy); unit.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(longitude); unit.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(latitude); unit.Setup(u => u.Resources.BronzeCoins).Returns(10); unit.Setup(u => u.Resources.GoldCoins).Returns(10); unit.Setup(u => u.Resources.SilverCoins).Returns(10); unit.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); unit.Setup(u => u.Pay(path.Object.Cost)).Returns(path.Object.Cost); var initialLocUnits = new List <IUnit> { unit.Object }; unit.Setup(u => u.CurrentLocation.Planet.Units).Returns(initialLocUnits); //Act station.TeleportUnit(unit.Object, destination.Object); //Assert unit.Verify(u => u.Pay(unit.Object.Pay(path.Object.Cost)), Times.Once()); }
public void TeleportUnitShouldThrowInsufficientResourcesExceptionButServiceCostsMoreThanUnitResources() { //Arrange var planet = "Mar Sara"; var galaxy = "Inner Galaxy"; var longitude = 20.00; var latitude = 10.00; var stationLoc = new Mock <ILocation>(); stationLoc.Setup(l => l.Planet.Name).Returns(planet); stationLoc.Setup(l => l.Planet.Galaxy.Name).Returns(galaxy); //stationLoc.Setup(l => l.Coordinates.Longtitude).Returns(longitude); //stationLoc.Setup(l => l.Coordinates.Latitude).Returns(latitude); var path = new Mock <IPath>(); path.Setup(p => p.Cost.SilverCoins).Returns(20); path.Setup(p => p.Cost.GoldCoins).Returns(20); path.Setup(p => p.Cost.BronzeCoins).Returns(20); path.Setup(p => p.TargetLocation.Planet.Name).Returns("Chau Sara"); path.Setup(p => p.TargetLocation.Planet.Galaxy.Name).Returns("Outer Rim"); var stationmap = new List <IPath> { path.Object }; var stationOwner = new Mock <IBusinessOwner>(); var unit = new Mock <IUnit>(); unit.Setup(u => u.CurrentLocation.Planet.Name).Returns(planet); unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns(galaxy); unit.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(longitude); unit.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(latitude); unit.Setup(u => u.Resources.BronzeCoins).Returns(10); unit.Setup(u => u.Resources.GoldCoins).Returns(10); unit.Setup(u => u.Resources.SilverCoins).Returns(10); var unitsOnPlanet = new List <IUnit> { unit.Object }; path.Setup(p => p.TargetLocation.Planet.Units).Returns(unitsOnPlanet); var destination = new Mock <ILocation>(); destination.Setup(l => l.Planet.Name).Returns("Chau Sara"); destination.Setup(l => l.Planet.Galaxy.Name).Returns("Outer Rim"); destination.Setup(l => l.Coordinates.Longtitude).Returns(100.00); destination.Setup(l => l.Coordinates.Latitude).Returns(200.00); var substring = "FREE LUNCH"; var station = new ExtendedTeleportStation(stationOwner.Object, stationmap, stationLoc.Object); //Act var exception = Assert.Throws <InsufficientResourcesException>(() => station.TeleportUnit(unit.Object, destination.Object)); var message = exception.Message; //Assert StringAssert.Contains(substring, message); }
public void SetTheUnitToTeleportCurrentLocationToTargetLocation_WhenTheValidationsPassAndTheUnitIsBeingTeleported() { // Arrange var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude + 15d); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude + 15d); var planetaryUnitsList = new List <IUnit> { planetaryUnitMock.Object }; var currentUnitLocationPlanetaryUnitsList = new List <IUnit> { unitToTeleportMock.Object }; var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(planetaryUnitsList); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); var initialTeleportStationResources = teleportStation.Resources.Clone(); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); unitToTeleportMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(x => x.Pay(pathMock.Object.Cost)).Returns(pathMock.Object.Cost); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Units).Returns(currentUnitLocationPlanetaryUnitsList); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); // Act teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object); // Assert unitToTeleportMock.VerifySet(x => x.CurrentLocation = targetLocationMock.Object, Times.Once()); }
public void TeleportUnitShouldThrowInvalidTeleportationLocationWithSubstringUnitsWillOverlap() { //Arrange var unit = new Mock <IUnit>(); var objUnit = unit.Object; var unitAtDestin = new Mock <IUnit>(); var objUnitAtDestin = unitAtDestin.Object; var destinLoc = new Mock <ILocation>(); var mockedOwner = new Mock <IBusinessOwner>(); //var mockedGalacticMap = new Mock<IEnumerable<IPath>>(); var mockedStationLoc = new Mock <ILocation>(); var objOwner = mockedOwner.Object; var objStationLocation = mockedStationLoc.Object; //unit.Setup(u => u.CurrentLocation.Planet.Name).Returns("Braxis"); //unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns("Outer Galaxy"); var destinPlanet = "Char Sara"; var destinGalaxy = "Inner Galaxy"; var destinLong = 20.00; var destinLat = 10.00; unitAtDestin.Setup(u => u.CurrentLocation.Planet.Name).Returns(destinPlanet); unitAtDestin.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns(destinGalaxy); unitAtDestin.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(destinLong); unitAtDestin.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(destinLat); destinLoc.Setup(loc => loc.Planet.Name).Returns(destinPlanet); destinLoc.Setup(loc => loc.Planet.Galaxy.Name).Returns(destinGalaxy); destinLoc.Setup(loc => loc.Coordinates.Longtitude).Returns(destinLong); destinLoc.Setup(loc => loc.Coordinates.Latitude).Returns(destinLat); unit.Setup(u => u.CurrentLocation.Planet.Name).Returns(destinPlanet); unit.Setup(u => u.CurrentLocation.Planet.Galaxy.Name).Returns(destinGalaxy); unit.Setup(u => u.CurrentLocation.Coordinates.Longtitude).Returns(destinLong); unit.Setup(u => u.CurrentLocation.Coordinates.Latitude).Returns(destinLat); var path = new Mock <IPath>(); path.Setup(p => p.TargetLocation.Planet.Name).Returns(destinPlanet); path.Setup(p => p.TargetLocation.Planet.Galaxy.Name).Returns(destinGalaxy); path.Setup(p => p.Cost.BronzeCoins).Returns(10); path.Setup(p => p.Cost.GoldCoins).Returns(20); path.Setup(p => p.Cost.SilverCoins).Returns(30); var destinPlanetUnitCollection = new List <IUnit> { objUnitAtDestin }; //var objDestinPlanetUnitCollection = destinPlanetUnitCollection.Object; path.Setup(p => p.TargetLocation.Planet.Units).Returns(destinPlanetUnitCollection); var objPath = path.Object; var mockedGalacticMap = new List <IPath> { objPath }; var objDestinLoc = destinLoc.Object; var teleportStation = new ExtendedTeleportStation(objOwner, mockedGalacticMap, objStationLocation); mockedStationLoc.Setup(l => l.Planet.Name).Returns(destinPlanet); mockedStationLoc.Setup(l => l.Planet.Galaxy.Name).Returns(destinGalaxy); //Act var exception = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(objUnit, objDestinLoc)); var actualMessage = exception.Message; var expectedSubstr = "units will overlap"; //Assert StringAssert.Contains(expectedSubstr, actualMessage); }
public void RemoveTheUnitToTeleportFromTheListOfUnitsOfItsCurrentPlanet_WhenTheValidationsPassAndTheUnitIsBeingTeleported() { // Arrange var planetName = "P1"; var galaxyName = "G1"; var longtitude = 45d; var latitude = 45d; var teleportStationLocationMock = new Mock <ILocation>(); var teleportStationOwnerMock = new Mock <IBusinessOwner>(); var targetLocationMock = new Mock <ILocation>(); var unitToTeleportMock = new Mock <IUnit>(); var planetaryUnitMock = new Mock <IUnit>(); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); planetaryUnitMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude + 15d); planetaryUnitMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude + 15d); var targetLocationPlanetaryUnitsCollectionEnumeratorMock = new Mock <IEnumerator <IUnit> >(); targetLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns(planetaryUnitMock.Object) .Callback( () => targetLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns((IUnit)null)); var targetLocationPlanetaryUnitsCollectionMock = new Mock <IList <IUnit> >(); targetLocationPlanetaryUnitsCollectionMock.Setup(x => x.GetEnumerator()).Returns(targetLocationPlanetaryUnitsCollectionEnumeratorMock.Object); var pathMock = new Mock <IPath>(); pathMock.Setup(x => x.Cost.BronzeCoins).Returns(10); pathMock.Setup(x => x.Cost.SilverCoins).Returns(10); pathMock.Setup(x => x.Cost.GoldCoins).Returns(10); pathMock.Setup(x => x.TargetLocation.Planet.Name).Returns(planetName); pathMock.Setup(x => x.TargetLocation.Planet.Galaxy.Name).Returns(galaxyName); pathMock.Setup(x => x.TargetLocation.Planet.Units).Returns(targetLocationPlanetaryUnitsCollectionMock.Object); var currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock = new Mock <IEnumerator <IUnit> >(); currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns(unitToTeleportMock.Object) .Callback( () => currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock .Setup(x => x.Current) .Returns((IUnit)null)); var currentUnitLocationPlanetaryUnitsCollectionMock = new Mock <IList <IUnit> >(); currentUnitLocationPlanetaryUnitsCollectionMock.Setup(x => x.GetEnumerator()).Returns(currentUnitLocationPlanetaryUnitsCollectionEnumeratorMock.Object); var teleportStationMapMock = new List <IPath> { pathMock.Object }; var teleportStation = new ExtendedTeleportStation(teleportStationOwnerMock.Object, teleportStationMapMock, teleportStationLocationMock.Object); var initialTeleportStationResources = teleportStation.Resources.Clone(); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Name).Returns(planetName); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Galaxy.Name).Returns(galaxyName); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Latitude).Returns(latitude); unitToTeleportMock.Setup(x => x.CurrentLocation.Coordinates.Longtitude).Returns(longtitude); unitToTeleportMock.Setup(x => x.CanPay(It.IsAny <IResources>())).Returns(true); unitToTeleportMock.Setup(x => x.Pay(pathMock.Object.Cost)).Returns(pathMock.Object.Cost); unitToTeleportMock.Setup(x => x.CurrentLocation.Planet.Units).Returns(currentUnitLocationPlanetaryUnitsCollectionMock.Object); targetLocationMock.Setup(x => x.Planet.Name).Returns(planetName); targetLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); targetLocationMock.Setup(x => x.Coordinates.Latitude).Returns(latitude); targetLocationMock.Setup(x => x.Coordinates.Longtitude).Returns(longtitude); teleportStationLocationMock.Setup(x => x.Planet.Name).Returns(planetName); teleportStationLocationMock.Setup(x => x.Planet.Galaxy.Name).Returns(galaxyName); // Act teleportStation.TeleportUnit(unitToTeleportMock.Object, targetLocationMock.Object); // Assert currentUnitLocationPlanetaryUnitsCollectionMock.Verify(x => x.Remove(unitToTeleportMock.Object), Times.Once()); }