コード例 #1
0
        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);
        }
コード例 #2
0
        public void ThrowArgumentNullException_WhenDestinationIsNull()
        {
            // Arrange
            var   unitToTeleportMock     = new Mock <IUnit>();
            IUnit expectedUnitToTeleport = unitToTeleportMock.Object;

            string exceptionMessage = "destination";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(expectedUnitToTeleport, null));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }
コード例 #3
0
        public void ThrowArgumentNullException_WhenUnitToTeleportIsNull()
        {
            // Arrange
            var       targetLocationMock     = new Mock <ILocation>();
            ILocation expectedTargetLocation = targetLocationMock.Object;

            string exceptionMessage = "unitToTeleport";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <ArgumentNullException>(() => teleportStation.TeleportUnit(null, expectedTargetLocation));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }
コード例 #4
0
        public void ThrowTeleportOutOfRangeException_WhenAUnitIsUsingTheStationFromADistantLocation()
        {
            // Arrange
            var unitToTeleportMock = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.TargetGalaxy, TeleportStationConstants.TargetLocation);

            IUnit     expectedUnitToTeleport = unitToTeleportMock.Object;
            ILocation expectedTargetLocation = targetLocationMock.Object;

            string exceptionMessage = "unitToTeleport.CurrentLocation";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <TeleportOutOfRangeException>(() => teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }
コード例 #5
0
        public void ThrowLocationNotFoundException_WhenGalaxyIsNotFoundInTheLocationsList()
        {
            // Arrange
            var unitToTeleportMock = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location);
            TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.TargetGalaxy, TeleportStationConstants.Location, TeleportStationConstants.Longtitude, TeleportStationConstants.Latitude);

            IUnit     expectedUnitToTeleport = unitToTeleportMock.Object;
            ILocation expectedTargetLocation = targetLocationMock.Object;

            string exceptionMessage = "Galaxy";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <LocationNotFoundException>(() => teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }
コード例 #6
0
        public void ThrowInvalidTeleportationLocationException_WhenTeleportingAUnitToATakenLocation()
        {
            // Arrange
            var unitToTeleportMock = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location);
            TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location, TeleportStationConstants.Longtitude, TeleportStationConstants.Latitude);

            IUnit     expectedUnitToTeleport = unitToTeleportMock.Object;
            ILocation expectedTargetLocation = targetLocationMock.Object;

            string exceptionMessage = "units will overlap";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <InvalidTeleportationLocationException>(() => teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public void ThrowInsufficientResourcesException_WhenTeleportingAUnitCostsMoreThanTheCurrentAvailableResources()
        {
            // Arrange
            var unitToTeleportMock = new Mock <IUnit>();
            var targetLocationMock = new Mock <ILocation>();

            unitToTeleportMock.Setup(u => u.CanPay(It.IsAny <IResources>())).Returns(false);

            TeleportStationHelpers.SetupUnitToTeleport(ref unitToTeleportMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location);
            TeleportStationHelpers.SetupTargetLocation(ref targetLocationMock, TeleportStationConstants.Galaxy, TeleportStationConstants.Location, TeleportStationConstants.OtherLongtitude, TeleportStationConstants.OtherLatitude);

            IUnit     expectedUnitToTeleport = unitToTeleportMock.Object;
            ILocation expectedTargetLocation = targetLocationMock.Object;

            string exceptionMessage = "FREE LUNCH";

            TeleportStation teleportStation = TeleportStationHelpers.ArrangeTeleportStation();

            // Act
            Exception exception = Assert.Throws <InsufficientResourcesException>(() => teleportStation.TeleportUnit(expectedUnitToTeleport, expectedTargetLocation));

            // Assert
            Assert.That(exception.Message, Does.Contain(exceptionMessage));
        }