public void SetAllFields_WhenTeleportStationIsCreatedWithValidParameters() { var ownerMock = new Mock <IBusinessOwner>(); var galacticMapMock = new Mock <IEnumerable <IPath> >(); var locationMock = new Mock <ILocation>(); var teleportStationMock = new TeleportStationMock(ownerMock.Object, galacticMapMock.Object, locationMock.Object); Assert.AreSame(ownerMock.Object, teleportStationMock.Owner); Assert.AreSame(galacticMapMock.Object, teleportStationMock.GalacticMap); Assert.AreSame(locationMock.Object, teleportStationMock.Location); }
public void TeleportUnit_ShouldThrowInvalidTeleportationLocationExceptionWithExpectedMessage_WhenTryingToTeleportToAlreadyTakenLocation() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedLocation = new Mock <ILocation>(); var mockedPlanet = new Mock <IPlanet>(); var mockedGalaxy = new Mock <IGalaxy>(); var mockedUnit = new Mock <IUnit>(); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object }, mockedLocation.Object); var mockedUnitToTeleport = new Mock <IUnit>(); var mockedTargetLocation = new Mock <ILocation>(); var mockedTargetPlanet = new Mock <IPlanet>(); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var expectedExcMessage = "units will overlap"; // Act var exc = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object)); var actualExcMsg = exc.Message; // Assert StringAssert.Contains(expectedExcMessage, actualExcMsg); }
public void SetUpAllTheProvidedFields_WhenANewStationIsCreatedWithValidParams() { // Arrange var businessOwnerMock = new Mock <IBusinessOwner>(); var galacticMapMock = new Mock <IEnumerable <IPath> >(); var locationMock = new Mock <ILocation>(); // Act var station = new TeleportStationMock(businessOwnerMock.Object, galacticMapMock.Object, locationMock.Object); // Assert Assert.AreSame(businessOwnerMock.Object, station.Owner); Assert.AreSame(galacticMapMock.Object, station.GalacticMap); Assert.AreSame(locationMock.Object, station.Location); }
public void TeleportUnit_ShouldThrowArgumentNullExceptionWithExpectedMessage_WhenTargetLocationIsNull() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var expectedOwner = mockedOwner.Object; var expectedPath = mockedPath.Object; var expectedLocation = mockedLocation.Object; var teleportStation = new TeleportStationMock(expectedOwner, expectedPath, expectedLocation); var mockedTargetUnit = new Mock <IUnit>(); var targetUnitObj = mockedTargetUnit.Object; var expectedExcMessage = "destination"; // Act var exc = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(targetUnitObj, null)); var actualExcMsg = exc.Message; // Assert StringAssert.Contains(expectedExcMessage, actualExcMsg); }
public void SetTeleportStation_ShouldCreateValidStation_WhenValidParametersArePassedToTheConstructor() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var expectedOwner = mockedOwner.Object; var expectedPath = mockedPath.Object; var expectedLocation = mockedLocation.Object; var teleportStation = new TeleportStationMock(expectedOwner, expectedPath, expectedLocation); // Act var actualOwner = teleportStation.Owner; var actualPath = teleportStation.Path; var actualLocation = teleportStation.Location; // Assert Assert.AreSame(expectedOwner, actualOwner); Assert.AreSame(expectedPath, actualPath); Assert.AreSame(expectedLocation, actualLocation); }
public void TeleportUnit_ShouldThrowTeleportOutOfRangeExceptionWithExpectedMessage_WhenTeleportStationIsUsedForADistantLocation() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalacticMap = new Mock <IEnumerable <IPath> >(); var mockedLocation = new Mock <ILocation>(); var mockedPlanet = new Mock <IPlanet>(); var mockedGalaxy = new Mock <IGalaxy>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var teleportStation = new TeleportStationMock(mockedOwner.Object, mockedGalacticMap.Object, mockedLocation.Object); var mockedUnitToTeleport = new Mock <IUnit>(); var mockedTargetLocation = new Mock <ILocation>(); var mockedTargetPlanet = new Mock <IPlanet>(); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Milky way"); mockedTargetPlanet.SetupGet(p => p.Name).Returns("Earth"); var expectedExcMessage = "unitToTeleport.CurrentLocation"; // Act var exc = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object)); var actualExcMsg = exc.Message; // Assert StringAssert.Contains(expectedExcMessage, actualExcMsg); }
public void ObtainPaymentAndIncreaseResourses_WhenUnitPassesAllOfTheRequirements() { // 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"); pathMock.SetupGet(x => x.TargetLocation.Planet.Units).Returns(new List <IUnit>() { }); 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 TeleportStationMock(businessOwnerMock.Object, galacticMap, locationMock.Object); var initialGoldAmount = station.Resources.GoldCoins; var initialBronzeAmount = station.Resources.BronzeCoins; var initialSilverAmount = station.Resources.SilverCoins; var expectedGoldAmount = initialGoldAmount + pathMock.Object.Cost.GoldCoins; var expectedBronzeAmount = initialGoldAmount + pathMock.Object.Cost.BronzeCoins; var expectedSilverAmount = initialGoldAmount + pathMock.Object.Cost.SilverCoins; // Act station.TeleportUnit(unitMock.Object, targetLocationMock.Object); // Assert Assert.AreEqual(expectedGoldAmount, station.Resources.GoldCoins); Assert.AreEqual(expectedBronzeAmount, station.Resources.BronzeCoins); Assert.AreEqual(expectedSilverAmount, station.Resources.SilverCoins); }
public void ConstructorWorkingCorrectly() { var Teleportstation = new TeleportStationMock(); Assert.IsNotNull(Teleportstation); }
public void TeleportUnit_TeleportedUnitShouldBeRemovedFromTheUnitsOfTheCurrentPlanetLocation_WhenTeleportationIsASuccess() { // Arrange // Teleport Location var mockedOwner = new Mock <IBusinessOwner>(); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); var mockedCostResources = new Mock <IResources>(); mockedCostResources.SetupGet(r => r.BronzeCoins).Returns(1); mockedCostResources.SetupGet(r => r.SilverCoins).Returns(2); mockedCostResources.SetupGet(r => r.GoldCoins).Returns(3); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.Cost).Returns(mockedCostResources.Object); var mockedUnit = new Mock <IUnit>(); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); // Wanted Location var mockedWantedGPS = new Mock <IGPSCoordinates>(); mockedWantedGPS.SetupGet(g => g.Latitude).Returns(15.15); mockedWantedGPS.SetupGet(g => g.Longtitude).Returns(16.16); var mockedWantedGalaxy = new Mock <IGalaxy>(); mockedWantedGalaxy.SetupGet(g => g.Name).Returns("Some Galaxy"); var mockedWantedPlanet = new Mock <IPlanet>(); mockedWantedPlanet.SetupGet(p => p.Galaxy).Returns(mockedWantedGalaxy.Object); mockedWantedPlanet.SetupGet(p => p.Name).Returns("Some Planet"); mockedWantedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { }); var mockedWantedLocation = new Mock <ILocation>(); mockedWantedLocation.SetupGet(loc => loc.Planet).Returns(mockedWantedPlanet.Object); mockedWantedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedWantedGPS.Object); var mockedWantedPath = new Mock <IPath>(); mockedWantedPath.SetupGet(p => p.TargetLocation).Returns(mockedWantedLocation.Object); mockedWantedPath.Setup(p => p.TargetLocation).Returns(mockedWantedLocation.Object); mockedWantedPath.Setup(p => p.Cost).Returns(mockedCostResources.Object); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object, mockedWantedPath.Object }, mockedLocation.Object); // Current Location of Unit var mockedTargetGPS = new Mock <IGPSCoordinates>(); mockedTargetGPS.SetupGet(g => g.Latitude).Returns(13.13); mockedTargetGPS.SetupGet(g => g.Longtitude).Returns(14.14); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedTargetGPS.Object); var mockTargetUnitResources = new Mock <IResources>(); mockTargetUnitResources.Setup(r => r.BronzeCoins).Returns(2); mockTargetUnitResources.Setup(r => r.SilverCoins).Returns(3); mockTargetUnitResources.Setup(r => r.GoldCoins).Returns(4); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedUnitToTeleport.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); mockedUnitToTeleport.Setup(u => u.Pay(mockedCostResources.Object)).Returns(mockTargetUnitResources.Object); mockedTargetPlanet.SetupGet(p => p.Units).Returns(new List <IUnit> { mockedUnitToTeleport.Object }); // Act teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedWantedLocation.Object); // Assert Assert.AreEqual(0, mockedTargetPlanet.Object.Units.Count); }
public void TeleportUnit_TeleportStationShouldRequirePaymentForTeleportation_AndTheResourcesOfTheStationMustBeIncreasedByTheCostOfTheTeleportation() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); var mockedCostResources = new Mock <IResources>(); mockedCostResources.SetupGet(r => r.BronzeCoins).Returns(1); mockedCostResources.SetupGet(r => r.SilverCoins).Returns(2); mockedCostResources.SetupGet(r => r.GoldCoins).Returns(3); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.Cost).Returns(mockedCostResources.Object); var mockedUnit = new Mock <IUnit>(); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object }, mockedLocation.Object); var mockedTargetGPS = new Mock <IGPSCoordinates>(); mockedTargetGPS.SetupGet(g => g.Latitude).Returns(13.13); mockedTargetGPS.SetupGet(g => g.Longtitude).Returns(14.14); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedTargetGPS.Object); var mockTargetUnitResources = new Mock <IResources>(); mockTargetUnitResources.Setup(r => r.BronzeCoins).Returns(2); mockTargetUnitResources.Setup(r => r.SilverCoins).Returns(3); mockTargetUnitResources.Setup(r => r.GoldCoins).Returns(4); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedUnitToTeleport.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); mockedUnitToTeleport.Setup(u => u.Pay(mockedCostResources.Object)).Returns(mockTargetUnitResources.Object); mockedTargetPlanet.SetupGet(p => p.Units).Returns(new List <IUnit> { mockedUnitToTeleport.Object }); mockedUnitToTeleport.Setup(u => u.PreviousLocation); // Act teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object); // Assert Assert.AreEqual(2, teleportStation.Resources.BronzeCoins); Assert.AreEqual(3, teleportStation.Resources.SilverCoins); Assert.AreEqual(4, teleportStation.Resources.GoldCoins); }
public void TeleportUnit_ShouldRequirePaymentFromTeleportedUnit_WhenAllTheValidationsArePassedSuccessfully() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); var mockedCostResources = new Mock <IResources>(); mockedCostResources.SetupGet(r => r.BronzeCoins).Returns(1); mockedCostResources.SetupGet(r => r.SilverCoins).Returns(2); mockedCostResources.SetupGet(r => r.GoldCoins).Returns(3); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.Cost).Returns(mockedCostResources.Object); var mockedUnit = new Mock <IUnit>(); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object }, mockedLocation.Object); var mockedTargetGPS = new Mock <IGPSCoordinates>(); mockedTargetGPS.SetupGet(g => g.Latitude).Returns(13.13); mockedTargetGPS.SetupGet(g => g.Longtitude).Returns(14.14); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedTargetGPS.Object); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedUnitToTeleport.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); mockedUnitToTeleport.Setup(u => u.Pay(It.IsAny <IResources>())).Returns(new Resources()); mockedTargetPlanet.SetupGet(p => p.Units).Returns(new List <IUnit> { mockedUnitToTeleport.Object }); mockedUnitToTeleport.Setup(u => u.PreviousLocation); // Act teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object); // Assert mockedUnitToTeleport.Verify(u => u.Pay(mockedPath.Object.Cost), Times.Once()); }
public void TeleportUnit_ShouldThrowInsufficientResourcesExceptionWithExpectedMessage_WhenTryingToTeleportUnitThatCannotPayTheCost() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); var mockedCostResources = new Mock <IResources>(); mockedCostResources.SetupGet(r => r.BronzeCoins).Returns(20); mockedCostResources.SetupGet(r => r.SilverCoins).Returns(30); mockedCostResources.SetupGet(r => r.GoldCoins).Returns(40); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.Cost).Returns(mockedCostResources.Object); var mockedUnit = new Mock <IUnit>(); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object }, mockedLocation.Object); var mockedTargetGPS = new Mock <IGPSCoordinates>(); mockedTargetGPS.SetupGet(g => g.Latitude).Returns(13.13); mockedTargetGPS.SetupGet(g => g.Longtitude).Returns(14.14); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedTargetGPS.Object); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedUnitToTeleport.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(false); var expectedExcMessage = "FREE LUNCH"; // Act var exc = Assert.Throws <InsufficientResourcesException>(() => teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object)); var actualExcMsg = exc.Message; // Assert StringAssert.Contains(expectedExcMessage, actualExcMsg); }
public void TeleportUnit_ShouldThrowLocationNotFoundExceptionExceptionWithExpectedMessage_WhenTryingToTeleportToNotExistingPlanet() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); // var mockedGalacticGalaxy = new Mock <IGalaxy>(); mockedGalacticGalaxy.SetupGet(gg => gg.Name).Returns("Andromeda"); var mockedGalacticPlanet = new Mock <IPlanet>(); mockedGalacticPlanet.SetupGet(gp => gp.Galaxy).Returns(mockedGalacticGalaxy.Object); mockedGalacticPlanet.SetupGet(gp => gp.Name).Returns("Waldo"); var mockedGalacticLocation = new Mock <ILocation>(); mockedGalacticLocation.SetupGet(gloc => gloc.Planet).Returns(mockedGalacticPlanet.Object); var mockedGalacticPath = new Mock <IPath>(); mockedGalacticPath.SetupGet(gp => gp.TargetLocation).Returns(mockedGalacticLocation.Object); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedGalacticPath.Object }, mockedLocation.Object); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); var expectedExcMessage = "Planet"; // Act var exc = Assert.Throws <LocationNotFoundException>(() => teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object)); var actualExcMsg = exc.Message; // Assert StringAssert.Contains(expectedExcMessage, actualExcMsg); }
public void PayProfits_ReturnTheTotalAmountOfProfitsGeneratedUsingTheTeleportUnitService_WhenTheOwnerIsValid() { // Arrange var mockedOwner = new Mock <IBusinessOwner>(); mockedOwner.SetupGet(o => o.IdentificationNumber).Returns(1); var mockedGPS = new Mock <IGPSCoordinates>(); mockedGPS.SetupGet(g => g.Latitude).Returns(11.11); mockedGPS.SetupGet(g => g.Longtitude).Returns(12.12); var mockedGalaxy = new Mock <IGalaxy>(); mockedGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedPlanet = new Mock <IPlanet>(); mockedPlanet.SetupGet(p => p.Galaxy).Returns(mockedGalaxy.Object); mockedPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); var mockedLocation = new Mock <ILocation>(); mockedLocation.SetupGet(loc => loc.Planet).Returns(mockedPlanet.Object); mockedLocation.SetupGet(loc => loc.Coordinates).Returns(mockedGPS.Object); var mockedCostResources = new Mock <IResources>(); mockedCostResources.SetupGet(r => r.BronzeCoins).Returns(1); mockedCostResources.SetupGet(r => r.SilverCoins).Returns(2); mockedCostResources.SetupGet(r => r.GoldCoins).Returns(3); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(p => p.TargetLocation).Returns(mockedLocation.Object); mockedPath.SetupGet(p => p.Cost).Returns(mockedCostResources.Object); var mockedUnit = new Mock <IUnit>(); mockedUnit.SetupGet(u => u.CurrentLocation).Returns(mockedLocation.Object); mockedPlanet.SetupGet(p => p.Units).Returns(new List <IUnit>() { mockedUnit.Object }); var teleportStation = new TeleportStationMock(mockedOwner.Object, new[] { mockedPath.Object }, mockedLocation.Object); var mockedTargetGPS = new Mock <IGPSCoordinates>(); mockedTargetGPS.SetupGet(g => g.Latitude).Returns(13.13); mockedTargetGPS.SetupGet(g => g.Longtitude).Returns(14.14); var mockedTargetGalaxy = new Mock <IGalaxy>(); mockedTargetGalaxy.SetupGet(g => g.Name).Returns("Andromeda"); var mockedTargetPlanet = new Mock <IPlanet>(); mockedTargetPlanet.SetupGet(p => p.Name).Returns("KELT-2Ab"); mockedTargetPlanet.SetupGet(p => p.Galaxy).Returns(mockedTargetGalaxy.Object); var mockedTargetLocation = new Mock <ILocation>(); mockedTargetLocation.SetupGet(loc => loc.Planet).Returns(mockedTargetPlanet.Object); mockedTargetLocation.SetupGet(loc => loc.Coordinates).Returns(mockedTargetGPS.Object); var mockedUnitToTeleport = new Mock <IUnit>(); mockedUnitToTeleport.SetupGet(u => u.CurrentLocation).Returns(mockedTargetLocation.Object); mockedUnitToTeleport.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(true); mockedUnitToTeleport.Setup(u => u.Pay(mockedCostResources.Object)).Returns(mockedCostResources.Object); mockedTargetPlanet.SetupGet(p => p.Units).Returns(new List <IUnit> { mockedUnitToTeleport.Object }); mockedUnitToTeleport.Setup(u => u.PreviousLocation); // Act teleportStation.TeleportUnit(mockedUnitToTeleport.Object, mockedTargetLocation.Object); var result = teleportStation.PayProfits(mockedOwner.Object); // Assert Assert.AreEqual(1, result.BronzeCoins); Assert.AreEqual(2, result.SilverCoins); Assert.AreEqual(3, result.GoldCoins); }