예제 #1
0
        public void Buy()
        {
            // Arrange
            SystemShip ship = this.CreateSystemShip();

            Mock <Ship> shipMock = new Mock <Ship>();

            // Trade value is 5500
            shipMock.Expect(s => s.TradeInValue)
            .Returns(5500).Verifiable();
            // Cargo space is 50, with 25 free
            shipMock.Expect(s => s.CargoSpaceTotal)
            .Returns(50).Verifiable();
            shipMock.Expect(s => s.CargoSpaceFree)
            .Returns(25).Verifiable();
            // Cash on hand is 5000
            shipMock.Expect(s => s.Credits)
            .Returns(5000).Verifiable();

            // Act
            ship.Buy(shipMock.Object);

            // Assert
            shipMock.Verify();
            // Cost of the ship should be 2000 credits
            shipMock.VerifySet(s => s.Credits, 5000 - 2000);
            Assert.That(ship.Quantity, Is.EqualTo(0), "Should be no ships left in the system of this model");
        }
예제 #2
0
        public ActionResult BuyShip(int shipId)
        {
            Ship       currentShip = this.ControllerGame.CurrentPlayer.Ship;
            SystemShip shipToBuy   = currentShip.CosmoSystem.GetBuyableShip(shipId);

            if (shipToBuy != null)
            {
                try
                {
                    shipToBuy.Buy(currentShip);

                    // Success, redirect to display the newly bought ship
                    return(RedirectToAction("ViewShip"));
                }
                catch (InvalidOperationException ex)
                {
                    // Log this exception
                    ExceptionPolicy.HandleException(ex, "Controller Policy");

                    ModelState.AddModelError("_FORM", ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("shipId", "Ship is no longer for sell in system", shipId);
            }

            // If we got down here, then an error was encountered
            // Get back to the list of ships
            return(this.ListShips());
        }
예제 #3
0
        public void BuyPlayerShipAddedToSystem()
        {
            // Arrange
            SystemShip ship           = this.CreateSystemShip();
            BaseShip   playerBaseShip = new BaseShip();

            Mock <Ship> shipMock = new Mock <Ship>();

            // Setup player base ship model
            shipMock.Expect(s => s.BaseShip)
            .Returns(playerBaseShip).Verifiable();
            // Trade value is 5500
            shipMock.Expect(s => s.TradeInValue)
            .Returns(5500).Verifiable();
            // Cargo space is 50, with 25 free
            shipMock.Expect(s => s.CargoSpaceTotal)
            .Returns(50).Verifiable();
            shipMock.Expect(s => s.CargoSpaceFree)
            .Returns(25).Verifiable();
            // Cash on hand is 5000
            shipMock.Expect(s => s.Credits)
            .Returns(5000).Verifiable();

            // Act
            ship.Buy(shipMock.Object);

            // Assert
            shipMock.Verify();
            // Cost of the ship should be 2000 credits
            shipMock.VerifySet(m => m.Credits, 5000 - 2000);
            Assert.That(ship.Quantity, Is.EqualTo(0), "Should be no ships left in the system of this model");
            Assert.That(ship.CosmoSystem.SystemShips.Where(m => m.BaseShip == playerBaseShip && m.Quantity == 1), Is.Not.Empty, "The players base ship should have been added to the system for sale");
        }
예제 #4
0
        public void Price()
        {
            // Arrange
            SystemShip ship = this.CreateSystemShip();

            // Act
            int price = ship.Price;

            // Assert
            Assert.That(price, Is.EqualTo(7500), "Price should be 75% of 10000 credits");
        }
예제 #5
0
        private SystemShip CreateSystemShip()
        {
            SystemShip ship = new SystemShip();

            ship.CosmoSystem         = new CosmoSystem();
            ship.BaseShip            = new BaseShip();
            ship.BaseShip.BasePrice  = 10000;
            ship.BaseShip.CargoSpace = 100;
            ship.PriceMultiplier     = 0.75;
            ship.Quantity            = 1;

            return(ship);
        }
예제 #6
0
        public void BuyNotEnoughCredits()
        {
            // Arrange
            SystemShip  ship     = this.CreateSystemShip();
            Mock <User> userMock = new Mock <User>();
            Mock <Ship> shipMock = new Mock <Ship>();

            // Trade value is 500
            shipMock.Expect(s => s.TradeInValue)
            .Returns(500).AtMostOnce().Verifiable();
            // Cash on hand is 5000
            shipMock.Expect(s => s.Credits)
            .Returns(5000).AtMostOnce().Verifiable();

            // Act, should throw an exception
            ship.Buy(shipMock.Object);
        }
예제 #7
0
        public void TradeInValueFromSystem()
        {
            // Arrange
            Ship ship = new Ship();

            ship.BaseShip           = new BaseShip();
            ship.BaseShip.BasePrice = 1000;
            // Blank upgrades
            ship.JumpDrive   = new JumpDrive();
            ship.Weapon      = new Weapon();
            ship.Shield      = new Shield();
            ship.CosmoSystem = new CosmoSystem();
            SystemShip systemShip = new SystemShip();

            systemShip.BaseShip        = ship.BaseShip;
            systemShip.PriceMultiplier = 2.0;
            ship.CosmoSystem.SystemShips.Add(systemShip);

            // Assert
            Assert.That(ship.TradeInValue, Is.EqualTo(1600), "Trade in value should equal 80% of 2x BaseShip value amount");
        }