Esempio n. 1
0
        public void TeleportUnit_ShouldSetUnitToTeleportCurretLocationToTargeLocation_WhenInputParamteresAreValid()
        {
            // 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 mockResourcesPayment = new Mock <IResources>();

            mockResourcesPayment.SetupGet(mock => mock.GoldCoins).Returns((uint)1);
            mockResourcesPayment.SetupGet(mock => mock.SilverCoins).Returns((uint)2);
            mockResourcesPayment.SetupGet(mock => mock.BronzeCoins).Returns((uint)3);

            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(mockResourcesPayment.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 ExposedProtectedFieldsMockTeleportStation(
                mockOwner.Object, mockGalacticMap, mockLocationStation.Object);

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

            // Assert that unitToTeleport CurrentLocation was accessed with the correct value.
            mockUnitToTeleport.VerifySet(mock => mock.CurrentLocation = mockTargetLocation.Object, Times.Once());
        }
Esempio n. 2
0
        public void TeleportUnit_ShouldRemoveUnitToTeleportFromCurrentLocationUnits_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>();
            var mockStationUnits    = new List <IUnit>();

            mockPlanetStation.SetupGet(mock => mock.Name).Returns("planetStation");
            mockPlanetStation.SetupGet(mock => mock.Galaxy).Returns(mockGalaxyStation.Object);
            mockPlanetStation.SetupGet(mock => mock.Units).Returns(mockStationUnits);
            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 mockPlanetListOfUnits = new List <IUnit>();
            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(mockPlanetListOfUnits);

            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 mockResourcesPayment = new Mock <IResources>();

            mockResourcesPayment.SetupGet(mock => mock.GoldCoins).Returns((uint)1);
            mockResourcesPayment.SetupGet(mock => mock.SilverCoins).Returns((uint)2);
            mockResourcesPayment.SetupGet(mock => mock.BronzeCoins).Returns((uint)3);

            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(mockResourcesPayment.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 ExposedProtectedFieldsMockTeleportStation(
                mockOwner.Object, mockGalacticMap, mockLocationStation.Object);

            // Arrange the unit to be removed
            mockStationUnits.Add(mockUnitToTeleport.Object);

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

            // Assert the unit was actually removed.
            CollectionAssert.DoesNotContain(mockStationUnits, mockUnitToTeleport.Object);
        }
Esempio n. 3
0
        public void TeleportUnit_ShouldAddResorcesToTeleportStationResources_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);

            // Arrange the payment.
            var mockResourcesPayment = new Mock <IResources>();

            mockResourcesPayment.SetupGet(mock => mock.GoldCoins).Returns((uint)1);
            mockResourcesPayment.SetupGet(mock => mock.SilverCoins).Returns((uint)2);
            mockResourcesPayment.SetupGet(mock => mock.BronzeCoins).Returns((uint)3);

            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(mockResourcesPayment.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 ExposedProtectedFieldsMockTeleportStation(
                mockOwner.Object, mockGalacticMap, mockLocationStation.Object);

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

            // Act
            var actualTeleportStationResources = teleportStation.Resources;

            // Assert that TeleportationStation has the same amount of resources as were received by the payment.
            Assert.That(actualTeleportStationResources,
                        Is.InstanceOf <IResources>()
                        .With.Property("GoldCoins").EqualTo((uint)1)
                        .And.Property("SilverCoins").EqualTo((uint)2)
                        .And.Property("BronzeCoins").EqualTo((uint)3));
        }