public void ThrowLocationNotFoundExceptionWithMassageGalaxy_WhenCalaxyIsNotInListOFTheTeleportStation() { // Arrange var messageExceptionSubstring = "Galaxy"; var mockeOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); mockedPath.SetupGet(x => x.TargetLocation.Planet.Galaxy.Name).Returns("Milk"); mockedPath.SetupGet(x => x.TargetLocation.Planet.Name).Returns("Mars"); var mockedGalacticMap = new List <IPath> { mockedPath.Object }; var mockedLocation = new Mock <ILocation>(); var teleportStation = new MockedTeleportStation(mockeOwner.Object, mockedGalacticMap, mockedLocation.Object); var mockedUnit = new Mock <IUnit>(); var mockedPlanet = new Mock <IPlanet>(); mockedUnit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Meee"); mockedUnit.SetupGet(x => x.CurrentLocation.Planet.Name).Returns("Mas"); mockedLocation.SetupGet(x => x.Planet.Galaxy.Name).Returns("Meee"); mockedLocation.SetupGet(x => x.Planet.Name).Returns("Mas"); // Act and Assert // var firstLocation= var exception = Assert.Throws <LocationNotFoundException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocation.Object)); StringAssert.Contains(messageExceptionSubstring, exception.Message); }
public void ObtainPayment_WhenUnitIsReadyForTeleportation() { 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 MockedTeleportStation (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); Assert.True(teleportStation.Resources.BronzeCoins == 1 && teleportStation.Resources.GoldCoins == 1 && teleportStation.Resources.SilverCoins == 1); }
public void SetAllFields_WhenTeleportStationIsCreatedWithValidParameters() { var owner = new Mock <IBusinessOwner>(); var galacticMap = new List <IPath>(); var location = new Mock <ILocation>(); var teleportStation = new MockedTeleportStation(owner.Object, galacticMap, location.Object); Assert.AreSame(owner.Object, teleportStation.Owner); Assert.AreSame(location.Object, teleportStation.Location); Assert.AreSame(galacticMap, teleportStation.GalacticMap); }
public void ThrowArgumentNullException_WhenIUnitUnitToTeleportIsNull_WithMassageCaontainigunitToTeleport() { // Arrange var messageExceptionSubstring = "unitToTeleport"; var mockeOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedGalacticMap = new List <IPath> { mockedPath.Object }; var mockedLocation = new Mock <ILocation>(); var teleportStation = new MockedTeleportStation(mockeOwner.Object, mockedGalacticMap, mockedLocation.Object); // Act and Assert var exception = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(null, It.IsAny <ILocation>())); StringAssert.Contains(messageExceptionSubstring, exception.Message); }
public void TestConstructor_PassValidParameters_ShouldInitialiseCorrectly() { var mockedBusinessOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedLocation = new Mock <ILocation>(); var map = new List <IPath>() { mockedPath.Object }; var station = new MockedTeleportStation (mockedBusinessOwner.Object, map, mockedLocation.Object); Assert.AreSame(mockedBusinessOwner.Object, station.Owner); Assert.AreSame(mockedLocation.Object, station.Location); Assert.AreSame(map, station.GalacticMap); Assert.IsInstanceOf <TeleportStation>(station); }
public void SetUpAllFields_whenValidParametersArePassed() { // Arrange var mockeOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedGalacticMap = new List <IPath> { mockedPath.Object }; var mockedLocation = new Mock <ILocation>(); //Act var teleportStation = new MockedTeleportStation(mockeOwner.Object, mockedGalacticMap, mockedLocation.Object); var actualOwner = teleportStation.Owner; var actualMap = teleportStation.GlacticMap; var actualLocation = teleportStation.Location; // Assert Assert.AreEqual(mockeOwner.Object, actualOwner); Assert.AreEqual(mockedGalacticMap, actualMap); Assert.AreEqual(mockedLocation.Object, actualLocation); }
public void ThrowInvalidTeleportationLocationExceptionWithMassageUnitsWillOverlap_WhenLocationIsAlllreadyTaken() { // Arrange var messageExceptionSubstring = "units will overlap"; var mockeOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedGalacticMap = new List <IPath> { mockedPath.Object }; var mockedLocation = new Mock <ILocation>(); var teleportStation = new MockedTeleportStation(mockeOwner.Object, mockedGalacticMap, mockedLocation.Object); var mockedUnit = new Mock <IUnit>(); var mockedPlanet = new Mock <IPlanet>(); mockedUnit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Mars"); mockedLocation.SetupGet(x => x.Planet.Galaxy.Name).Returns("Earth"); // Act and Assert var exception = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocation.Object)); StringAssert.Contains(messageExceptionSubstring, exception.Message); }
public void ThrowTeleportOutOfRangeExceptionWithMassage_UnitToTeleportCurrentLocation_WhenIUnitUnitToTeleportIsOnOtherlocation() { // Arrange var messageExceptionSubstring = "unitToTeleport.CurrentLocation"; var mockeOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedGalacticMap = new List <IPath> { mockedPath.Object }; var mockedLocation = new Mock <ILocation>(); var teleportStation = new MockedTeleportStation(mockeOwner.Object, mockedGalacticMap, mockedLocation.Object); var mockedUnit = new Mock <IUnit>(); var mockedPlanet = new Mock <IPlanet>(); mockedUnit.SetupGet(x => x.CurrentLocation.Planet.Galaxy.Name).Returns("Mars"); mockedLocation.SetupGet(x => x.Planet.Galaxy.Name).Returns("Earth"); // Act and Assert var exception = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(mockedUnit.Object, mockedLocation.Object)); StringAssert.Contains(messageExceptionSubstring, exception.Message); }
public void TestTeleportUnit_ShouldSetUnitToTeleportCurrentLocationToDestination() { var mockedBusinessOwner = new Mock <IBusinessOwner>(); var mockedPath = new Mock <IPath>(); var mockedDestination = new Mock <ILocation>(); var mockedDestinationPlanet = new Mock <IPlanet>(); 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); var mockedCoordinates = new Mock <IGPSCoordinates>(); mockedCoordinates.SetupGet(x => x.Longtitude).Returns(15); mockedCoordinates.SetupGet(x => x.Latitude).Returns(22); mockedDestination.SetupGet(x => x.Coordinates).Returns(mockedCoordinates.Object); 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 MockedTeleportStation(mockedBusinessOwner.Object, map, mockedLocation.Object); mockedLocation.SetupGet(x => x.Coordinates).Returns(It.IsAny <IGPSCoordinates>()); 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); Assert.AreSame(mockedUnit.Object.CurrentLocation, mockedDestination.Object); }
public void TestTeleportUnit_ShouldReceiveFunds() { 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 MockedTeleportStation(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 }); var bronze = teleportStation.Recources.BronzeCoins; var gold = teleportStation.Recources.GoldCoins; var silver = teleportStation.Recources.SilverCoins; teleportStation.TeleportUnit(mockedUnit.Object, mockedDestination.Object); Assert.IsTrue(teleportStation.Recources.BronzeCoins > bronze); Assert.IsTrue(teleportStation.Recources.SilverCoins > silver); Assert.IsTrue(teleportStation.Recources.GoldCoins > gold); }
public void TestPayProfits_PassValidOwner_ShouldPayCorrectly() { var mockedBusinessOwner = new Mock <IBusinessOwner>(); mockedBusinessOwner.SetupGet(x => x.IdentificationNumber).Returns(112); var mockedPath = new Mock <IPath>(); var mockedDestination = new Mock <ILocation>(); var mockedDestinationPlanet = new Mock <IPlanet>(); 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); var mockedCoordinates = new Mock <IGPSCoordinates>(); mockedCoordinates.SetupGet(x => x.Longtitude).Returns(15); mockedCoordinates.SetupGet(x => x.Latitude).Returns(22); mockedDestination.SetupGet(x => x.Coordinates).Returns(mockedCoordinates.Object); 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 MockedTeleportStation(mockedBusinessOwner.Object, map, mockedLocation.Object); mockedLocation.SetupGet(x => x.Coordinates).Returns(It.IsAny <IGPSCoordinates>()); 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); var profits = teleportStation.PayProfits(mockedBusinessOwner.Object); Assert.AreEqual(mockedResource.Object.BronzeCoins, profits.BronzeCoins); Assert.AreEqual(mockedResource.Object.SilverCoins, profits.SilverCoins); Assert.AreEqual(mockedResource.Object.GoldCoins, profits.GoldCoins); }