Ejemplo n.º 1
0
        public void AcceptSearchNotEnoughCredits()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            Good contrabandGood         = (from g in db.Goods
                                           where g.Contraband
                                           select g).FirstOrDefault();
            Good nonContrabandGood = (from g in db.Goods
                                      where !g.Contraband
                                      select g).FirstOrDefault();

            // Add contraband and non-contraband good to player 2
            player2.Ship.AddGood(contrabandGood.GoodId, 5);
            player2.Ship.AddGood(nonContrabandGood.GoodId, 5);

            // Give player 2 no money to pay fine
            player2.Ship.Credits = 0;

            // Player 1 starts search
            combat.StartSearch();

            // Player 2 accepts search
            combat.AcceptSearch();

            ShipGood good1 = player2.Ship.GetGood(contrabandGood.GoodId);

            Assert.That(good1.Quantity, Is.EqualTo(0), "Player 2 should have 0 of the contraband good now");
            ShipGood good2 = player2.Ship.GetGood(nonContrabandGood.GoodId);

            Assert.That(good2.Quantity, Is.EqualTo(5), "Player 2 should still have 5 of the non-contraband good now");
        }
Ejemplo n.º 2
0
        public void Create10000Players()
        {
            string baseEmail            = "*****@*****.**";
            string baseUserName         = "******";
            string basePlayerName       = "stressTestPlayer";
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            CosmoMongerMembershipProvider provider = new CosmoMongerMembershipProvider();
            MembershipCreateStatus        status;

            Race skummRace = (from r in db.Races
                              where r.Name == "Skumm"
                              select r).SingleOrDefault();

            for (int i = 0; i < 50000; i++)
            {
                CosmoMongerMembershipUser testUser = (CosmoMongerMembershipUser)provider.CreateUser(i + baseUserName, "test1000", i + baseEmail, null, null, true, null, out status);
                Assert.IsNotNull(testUser, "Test User was created. status = {0}", new object[] { status });

                User testUserModel = testUser.GetUserModel();
                Assert.IsNotNull(testUserModel, "Able to get model object for user");

                Player testPlayer = testUserModel.CreatePlayer(i + basePlayerName, skummRace);
                foreach (Good good in db.Goods)
                {
                    ShipGood shipGood = new ShipGood();
                    shipGood.Ship     = testPlayer.Ship;
                    shipGood.Good     = good;
                    shipGood.Quantity = 0;

                    db.ShipGoods.InsertOnSubmit(shipGood);
                }
                db.SubmitChanges();
            }
        }
Ejemplo n.º 3
0
        public ActionResult SellGoods(int goodId, int quantity, int price)
        {
            ShipGood shipGood = this.ControllerGame.CurrentPlayer.Ship.GetGood(goodId);

            if (shipGood != null)
            {
                try
                {
                    shipGood.Sell(this.ControllerGame.CurrentPlayer.Ship, quantity, price);
                    return(RedirectToAction("ListGoods"));
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    // Log this exception
                    ExceptionPolicy.HandleException(ex, "Controller Policy");

                    if (ex.ParamName == "price")
                    {
                        // Go to the SellGoodsPriceChange view
                        // Price has changed on the good
                        // Confirm the player still wants to sell the good
                        ViewData["goodId"]   = goodId;
                        ViewData["quantity"] = quantity;
                        ViewData["oldPrice"] = price;
                        ViewData["goodName"] = shipGood.Good.Name;

                        // Try to get the current price
                        SystemGood systemGood = this.ControllerGame.CurrentPlayer.Ship.CosmoSystem.GetGood(goodId);
                        if (systemGood != null)
                        {
                            ViewData["newPrice"] = systemGood.Price;
                        }

                        return(View("SellGoodsPriceChange"));
                    }
                    else
                    {
                        ModelState.AddModelError("quantity", ex.Message, quantity);
                    }
                }
                catch (InvalidOperationException ex)
                {
                    // Log this exception
                    ExceptionPolicy.HandleException(ex, "Controller Policy");

                    ModelState.AddModelError("goodId", ex.Message, quantity);
                }
            }
            else
            {
                ModelState.AddModelError("goodId", "Good is not bought in the system", goodId);
            }

            return(View());
        }
Ejemplo n.º 4
0
        public void AcceptSurrenderWithGoods()
        {
            // Add good 1 to player 1
            player1.Ship.AddGood(1, 10);

            combat.OfferSurrender();
            combat.AcceptSurrender();

            ShipGood good1 = player2.Ship.GetGood(1);

            Assert.That(good1.Quantity, Is.EqualTo(10), "Player 2 should have 10 of good 1 now");
        }
Ejemplo n.º 5
0
        public void PickupCargo()
        {
            // Add good 1 to player 1
            player1.Ship.AddGood(1, 10);

            combat.JettisonCargo();
            combat.PickupCargo();

            ShipGood good1 = player2.Ship.GetGood(1);

            Assert.That(good1.Quantity, Is.EqualTo(10), "Player 2 should have 10 of good 1 now");
        }
Ejemplo n.º 6
0
        public void SellNotSold()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Setup player
            Player      testPlayer     = this.CreateTestPlayer();
            Ship        testShip       = testPlayer.Ship;
            CosmoSystem startingSystem = testShip.CosmoSystem;
            GameManager manager        = new GameManager(testPlayer.User.UserName);

            // Store the player starting cash
            int playerStartingCash = testPlayer.Ship.Credits;

            // Add some water to this ship for us to sell
            Good water = (from g in db.Goods
                          where g.Name == "Water"
                          select g).SingleOrDefault();

            Assert.That(water, Is.Not.Null, "We should have a Water good");
            ShipGood shipGood = new ShipGood();

            shipGood.Good     = water;
            shipGood.Quantity = 10;
            shipGood.Ship     = testShip;
            testShip.ShipGoods.Add(shipGood);

            // Verify that the good is for sell in the current system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            if (systemWater != null)
            {
                // Remove the good from the system
                db.SystemGoods.DeleteOnSubmit(systemWater);
                db.SubmitChanges();
            }
            try
            {
                shipGood.Sell(testShip, 10, systemWater.Price);
            }
            catch (InvalidOperationException ex)
            {
                // Correct
                Assert.That(ex, Is.Not.Null, "InvalidOperationException should be valid");
                return;
            }
            Assert.Fail("Player should not been able to sell in the system when the good was not sold in the system");
        }
Ejemplo n.º 7
0
        public void SellNotEnoughGoods()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Setup player
            Player      testPlayer     = this.CreateTestPlayer();
            Ship        testShip       = testPlayer.Ship;
            CosmoSystem startingSystem = testShip.CosmoSystem;
            GameManager manager        = new GameManager(testPlayer.User.UserName);

            // Add some water to this ship for us to sell
            Good water = (from g in db.Goods
                          where g.Name == "Water"
                          select g).SingleOrDefault();

            Assert.That(water, Is.Not.Null, "We should have a Water good");
            ShipGood shipGood = new ShipGood();

            shipGood.Good     = water;
            shipGood.Quantity = 10;
            shipGood.Ship     = testShip;
            testShip.ShipGoods.Add(shipGood);
            db.SubmitChanges();

            // Verify that the good is for sell in the current system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            if (systemWater == null)
            {
                startingSystem.AddGood(water.GoodId, 0);
                systemWater = startingSystem.GetGood(water.GoodId);
            }

            try
            {
                shipGood.Sell(testShip, 20, systemWater.Price);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                Assert.That(ex.ParamName, Is.EqualTo("quantity"), "Quantity to sell should be the invalid argument");
                return;
            }

            Assert.Fail("Player should not been able to sell more goods than aboard");
        }
Ejemplo n.º 8
0
        public void Sell()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Setup player
            Player      testPlayer     = this.CreateTestPlayer();
            Ship        testShip       = testPlayer.Ship;
            CosmoSystem startingSystem = testShip.CosmoSystem;
            GameManager manager        = new GameManager(testPlayer.User.UserName);

            // Store the player starting cash
            int playerStartingCash = testPlayer.Ship.Credits;

            // Add some water to this ship for us to sell
            Good water = (from g in db.Goods
                          where g.Name == "Water"
                          select g).SingleOrDefault();

            Assert.That(water, Is.Not.Null, "We should have a Water good");
            ShipGood shipGood = new ShipGood();

            shipGood.Good     = water;
            shipGood.Quantity = 10;
            shipGood.Ship     = testShip;
            testShip.ShipGoods.Add(shipGood);

            // Verify that the good is for sell in the current system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            if (systemWater == null)
            {
                startingSystem.AddGood(water.GoodId, 0);
                systemWater = startingSystem.GetGood(water.GoodId);
            }
            int playerProfit        = systemWater.Price * 10;
            int systemStartingCount = systemWater.Quantity;

            shipGood.Sell(testShip, 10, systemWater.Price);

            Assert.That(systemWater.Quantity, Is.EqualTo(systemStartingCount + 10), "System should now have 10 more water goods");
            Assert.That(testPlayer.Ship.Credits, Is.EqualTo(playerStartingCash + playerProfit), "Player should have more cash credits now after selling");
        }
Ejemplo n.º 9
0
        public void AcceptSearchNoGoods()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            Good nonContrabandGood      = (from g in db.Goods
                                           where !g.Contraband
                                           select g).FirstOrDefault();

            // Add non-contraband good to player 2
            player2.Ship.AddGood(nonContrabandGood.GoodId, 5);

            // Player 1 starts search
            combat.StartSearch();

            // Player 2 accepts search
            combat.AcceptSearch();

            ShipGood good2 = player2.Ship.GetGood(nonContrabandGood.GoodId);

            Assert.That(good2.Quantity, Is.EqualTo(5), "Player 2 should still have 5 of the non-contraband good now");
        }