Esempio n. 1
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();
            }
        }
Esempio n. 2
0
        public void CreatePlayer()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            CosmoMongerMembershipProvider provider = new CosmoMongerMembershipProvider();
            MembershipCreateStatus        status;
            CosmoMongerMembershipUser     testUser = (CosmoMongerMembershipUser)provider.CreateUser(this.baseTestUsername, "test1000", this.baseTestEmail, null, null, true, null, out status);

            Assert.IsNotNull(testUser, "Test User is created");

            Assert.AreEqual(this.baseTestUsername, testUser.UserName, "Test User has correct username");
            Assert.AreEqual(this.baseTestEmail, testUser.Email, "Test User has correct e-mail");

            testUser = (CosmoMongerMembershipUser)provider.GetUser(this.baseTestUsername, false);
            Assert.IsNotNull(testUser, "Test User exists in the database");
            Assert.AreEqual(this.baseTestUsername, testUser.UserName, "Test User has correct username");
            Assert.AreEqual(this.baseTestEmail, testUser.Email, "Test User has correct e-mail");

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

            Assert.IsNotNull(humanRace, "Human Race exists in database");

            User testUserModel = testUser.GetUserModel();

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

            Player testPlayer = testUserModel.CreatePlayer(this.baseTestUsername, humanRace);

            Assert.IsNotNull(testPlayer, "Test Player is created");

            Assert.AreEqual(true, testPlayer.Alive, "Test Player is alive");
            Assert.AreEqual(this.baseTestUsername, testPlayer.Name, "Test Player has correct name");
        }
Esempio n. 3
0
        public void AttackAtSameTimeThread()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            Player player1 = db.Players.Where(p => p.PlayerId == player1Id).Single();
            Player player2 = db.Players.Where(p => p.PlayerId == player2Id).Single();

            for (int i = 0; i < 100; i++)
            {
                try
                {
                    player1.Ship.Attack(player2.Ship);
                    player1.Ship.InProgressCombat.Status = Combat.CombatStatus.ShipDestroyed;
                    player1AttackCount++;
                }
                catch (ArgumentException ex)
                {
                    Assert.That(ex.Message, Is.Not.Null, "Check for exception message");
                }
                catch (InvalidOperationException ex)
                {
                    Assert.That(ex.Message, Is.Not.Null, "Check for exception message");
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Cleaner NPC. Looks for inactive users and makes sure that are not stuck in travel.
        /// </summary>
        public override void DoAction()
        {
            // Mark the next time traveling players will need cleaning
            if (!this.SetNextActionDelay(new TimeSpan(0, NpcCleaner.MinutesBetweenCleanerSweeps, 0)))
            {
                // Another thread has made changes to this Npc, should exit
                return;
            }

            // Find traveling ships past due & players who haven't been active for the past minute
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            var shipsNeedingCleaning    = (from p in db.Players
                                           where p.Ship.TargetSystemArrivalTime < DateTime.UtcNow &&
                                           p.LastPlayed.AddMinutes(1) < DateTime.UtcNow
                                           select p.Ship);

            foreach (Ship ship in shipsNeedingCleaning)
            {
                // Check that the ship is not in combat
                if (ship.InProgressCombat == null)
                {
                    // Fix travel state
                    ship.CheckIfTraveling();
                }
            }
        }
Esempio n. 5
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");
        }
Esempio n. 6
0
        /// <summary>
        /// Create the ship for the NPC
        /// </summary>
        public override void Setup()
        {
            base.Setup();

            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Select a random race
            Race npcRace = this.rnd.SelectOne(db.Races);

            // Assign the race
            this.npcRow.Race = npcRace;

            // We only start in systems with the same race
            IQueryable <CosmoSystem> possibleStartingSystems = (from s in db.CosmoSystems
                                                                where s.Race == npcRace
                                                                select s);
            CosmoSystem startingSystem = this.rnd.SelectOne(possibleStartingSystems);

            // Randomly select a base ship model
            BaseShip startingShipModel = this.rnd.SelectOne(db.BaseShips);

            // Create the NPC ship
            Ship npcShip = startingSystem.CreateShip(startingShipModel.Name);

            this.npcRow.Ship = npcShip;

            // Randomly assign upgrades
            npcShip.JumpDrive = this.rnd.SelectOne(db.JumpDrives);
            npcShip.Shield    = this.rnd.SelectOne(db.Shields);
            npcShip.Weapon    = this.rnd.SelectOne(db.Weapons);

            // Set the next travel time to now
            this.npcRow.NextTravelTime = DateTime.UtcNow;
        }
Esempio n. 7
0
        private void SetPlayerRace(Player player, string raceName)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Assign the correct race
            player.Race = (from r in db.Races
                           where r.Name == raceName
                           select r).SingleOrDefault();
        }
Esempio n. 8
0
        /// <summary>
        /// Updates the system good price.
        /// </summary>
        private void UpdateSystemGoodPrice()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            foreach (SystemGood good in db.SystemGoods)
            {
                // Get the total number of this good type avaiable in all systems
                int targetTotal     = good.Good.TargetCount;
                int systemsWithGood = (from s in good.Good.SystemGoods
                                       where s.Quantity > 0
                                       select s).Count();
                double newPriceMultipler;

                // pre 2-21-09 way
                // newPriceMultipler = this.CalculatePriceMultipler(targetTotal, systemsWithGood, good.Quantity);
                // new way post 2-21-09
                newPriceMultipler = this.CalculatePriceMultipler(targetTotal, systemsWithGood, good.Quantity);

                double oldPriceMultipler = good.PriceMultiplier;

                // Take average of previous and current price multipler
                good.PriceMultiplier = (oldPriceMultipler + newPriceMultipler) / 2.0;

                Dictionary <string, object> props = new Dictionary <string, object>
                {
                    { "SystemId", good.SystemId },
                    { "GoodId", good.GoodId },
                    { "PriceMultiplier", good.PriceMultiplier },
                    { "NewPriceMultipler", newPriceMultipler },
                    { "OldPriceMultipler", oldPriceMultipler }
                };
                Logger.Write("Adjusting Good Price", "NPC", 400, 0, TraceEventType.Verbose, "Adjusting Good Price", props);

                try
                {
                    // Send changes to database
                    db.SubmitChanges(ConflictMode.ContinueOnConflict);
                }
                catch (ChangeConflictException ex)
                {
                    ExceptionPolicy.HandleException(ex, "SQL Policy");

                    // Another thread has made changes to this SystemGood row,
                    // which could be from someone buying or selling the good at a system
                    // Best case to resolve this would be to simply start over in the price calculatation,
                    // the previous price no longer valid.
                    foreach (ObjectChangeConflict occ in db.ChangeConflicts)
                    {
                        // Refresh current values from database
                        occ.Resolve(RefreshMode.OverwriteCurrentValues);
                    }

                    continue;
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Does the action.
        /// </summary>
        public override void DoAction()
        {
            if (!this.SetNextActionDelay(NpcShipBase.DelayBeforeNextAction))
            {
                return;
            }

            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            Ship npcShip = this.npcRow.Ship;

            // Check if we are still traveling
            npcShip.CheckIfTraveling();

            // Check if we are currently in combat
            if (npcShip.InProgressCombat != null)
            {
                // In Combat!
                this.DoCombat();
            }
            else if (this.npcRow.NextTravelTime < DateTime.UtcNow)
            {
                // Check if we need to give this pirate some credits
                if (npcShip.Credits < BaseCreditAmount)
                {
                    // Poor pirate has no gold, give him some to start
                    npcShip.Credits = BaseCreditAmount;
                }

                // Attack?
                if (this.rnd.SelectByProbablity(new bool[] { true, false }, new double[] { 0.50, 0.50 }))
                {
                    this.DoAttack();
                }
                else
                {
                    this.DoTravel();
                }

                this.SetNextTravelTime();
            }
            else
            {
                /*
                 * Dictionary<string, object> props = new Dictionary<string, object>
                 * {
                 *  { "NpcId", this.npcRow.NpcId },
                 *  { "NextTravelTime", this.npcRow.NextTravelTime },
                 *  { "UtcNow", DateTime.UtcNow }
                 * };
                 * Logger.Write("Waiting for NextTravelTime", "NPC", 200, 0, TraceEventType.Verbose, "Pirate Wait", props);
                 */
            }

            db.SaveChanges();
        }
Esempio n. 10
0
        /// <summary>
        /// Sets the delay before the next action will be taken for this Npc again.
        /// </summary>
        /// <param name="delay">The delay before the next scheduled action.</param>
        /// <returns>true is time has been set, false if another thread has already ran (Npc should exit)</returns>
        protected bool SetNextActionDelay(TimeSpan delay)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Mark the next time this NPC will need to do an action
            this.npcRow.NextActionTime = DateTime.UtcNow.Add(delay);

            db.SaveChanges();

            return(true);
        }
Esempio n. 11
0
        public void SchrodinoidHomeSystem()
        {
            // Test that the created Schrodinoid player starts in the correct home system
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

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

            this.CheckPlayerHomeSystem(schrodinoidRace);
        }
Esempio n. 12
0
        public void DecapodianHomeSystem()
        {
            // Test that the created Decapodian player starts in the correct home system
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

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

            this.CheckPlayerHomeSystem(decapodianRace);
        }
Esempio n. 13
0
        public void BinariteHomeSystem()
        {
            // Test that the created Binarite player starts in the correct home system
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

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

            this.CheckPlayerHomeSystem(binariteRace);
        }
Esempio n. 14
0
        public void LINQSingle()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            for (int i = 0; i < LOOP_COUNT; i++)
            {
                Player topPlayer = (from p in db.Players
                                    where p.PlayerId == 1
                                    select p).SingleOrDefault();
            }
        }
Esempio n. 15
0
        public void LINQWhereObjectId()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            Player topPlayer            = db.Players.First();

            for (int i = 0; i < LOOP_COUNT; i++)
            {
                IQueryable <Player> matchingPlayer = (from p in db.Players
                                                      where p.PlayerId == topPlayer.PlayerId
                                                      select p);
            }
        }
Esempio n. 16
0
        private Player CreateTestPlayer(string baseTestUsername, string baseTestEmail, string baseTestPlayerName)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Default to Human race
            Race humanRace = (from r in db.Races
                              where r.Name == "Human"
                              select r).SingleOrDefault();

            Assert.IsNotNull(humanRace, "Human Race needs to be present in the database");

            return(this.CreateTestPlayer(baseTestUsername, baseTestEmail, baseTestPlayerName, humanRace));
        }
Esempio n. 17
0
        public void LINQToList()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            for (int i = 0; i < LOOP_COUNT; i++)
            {
                List <Player> players = (from p in db.Players
                                         where p.Alive
                                         select p).ToList();
                foreach (Player player in players)
                {
                    player.NetWorth++;
                }
            }
        }
Esempio n. 18
0
        private void SetPlayerShip(Player player, string shipName)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            // Assign the default base ship type
            BaseShip baseShip = (from bs in db.BaseShips
                                 where bs.Name == shipName
                                 select bs).SingleOrDefault();

            player.Ship.BaseShip = baseShip;

            // Setup default upgrades
            player.Ship.JumpDrive = player.Ship.BaseShip.InitialJumpDrive;
            player.Ship.Shield    = player.Ship.BaseShip.InitialShield;
            player.Ship.Weapon    = player.Ship.BaseShip.InitialWeapon;
        }
Esempio n. 19
0
        private Player CreateTestPlayer(string baseTestUsername, string baseTestEmail, string baseTestPlayerName, Race playerRace)
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            CosmoMongerMembershipProvider provider = new CosmoMongerMembershipProvider();
            MembershipCreateStatus        status;
            CosmoMongerMembershipUser     testUser = (CosmoMongerMembershipUser)provider.CreateUser(baseTestUsername, "test1000", baseTestEmail, 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");

            return(testUserModel.CreatePlayer(baseTestUsername, playerRace));
        }
Esempio n. 20
0
        public void GetSystemDistance()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            Player testPlayer = this.CreateTestPlayer();

            CosmoSystem [] inRangeSystems = testPlayer.Ship.GetInRangeSystems();
            int            range          = testPlayer.Ship.JumpDrive.Range;

            // Check the distance of all the in-range systems
            foreach (CosmoSystem system in inRangeSystems)
            {
                double distance = testPlayer.Ship.GetSystemDistance(system);
                Assert.That(distance, Is.LessThan(range), "All in range systems should be within JumpDrive range");
            }
        }
Esempio n. 21
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");
        }
Esempio n. 22
0
        public void BankWithdrawNoBank()
        {
            // Arrange
            Player testPlayer = this.CreateTestPlayer();

            // Move the player to a system without a bank
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            CosmoSystem noBankSystem    = (from s in db.CosmoSystems
                                           where !s.HasBank
                                           select s).FirstOrDefault();

            Assert.That(noBankSystem, Is.Not.Null, "There should be at least one system in the galaxy without a bank");
            testPlayer.Ship.CosmoSystem = noBankSystem;

            // Act, should throw an exception
            testPlayer.BankWithdraw(1000);
        }
Esempio n. 23
0
        public void BuyNotEnoughCash()
        {
            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);

            // Reduce the player starting cash
            testPlayer.Ship.Credits = 10;

            // Check that the ship is empty
            Assert.That(testShip.ShipGoods.Count, Is.EqualTo(0), "Ship should start out with no goods on-board");

            // Add some water to the starting system for this ship to buy
            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");
            startingSystem.AddGood(water.GoodId, 20);

            // Verify that the good was added to the system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            Assert.That(systemWater, Is.Not.Null, "System should now have a water SystemGood");
            Assert.That(systemWater.Quantity, Is.GreaterThanOrEqualTo(20), "System should now have at least 20 water goods");

            int playerCost          = (int)(systemWater.PriceMultiplier * water.BasePrice) * systemWater.Quantity;
            int systemStartingCount = systemWater.Quantity;

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

            Assert.Fail("Player should not been able to buy more goods than they can afford");
        }
Esempio n. 24
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");
        }
Esempio n. 25
0
        public void FindUserJory()
        {
            Player      testPlayer = this.CreateTestPlayer();
            GameManager manager    = new GameManager(testPlayer.User.UserName);

            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();

            //db.Log = Console.Out;

            IEnumerable <User> users      = manager.FindUser("jory");
            IPagination <User> usersPaged = users.AsPagination(1);

            usersPaged.ToArray();

            //db.Log = null;

            Assert.That(users, Is.Not.Empty, "Should find me");
        }
Esempio n. 26
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");
        }
Esempio n. 27
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");
        }
Esempio n. 28
0
        public void AddGood()
        {
            CosmoMongerDbDataContext db = CosmoManager.GetDbContext();
            CosmoSystem firstSystem     = (from s in db.CosmoSystems select s).FirstOrDefault();

            Assert.That(firstSystem, Is.Not.Null, "We need at least one system in the galaxy");

            // Add some water to the the system
            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");
            firstSystem.AddGood(water.GoodId, 100);

            // Verify that the good was added to the system
            SystemGood systemWater = firstSystem.GetGood(water.GoodId);

            Assert.That(systemWater, Is.Not.Null, "System should now have a water SystemGood");
            Assert.That(systemWater.Quantity, Is.GreaterThanOrEqualTo(100), "System should now have at least 100 water goods");
        }
Esempio n. 29
0
        public void BuyNotEnoughGoods()
        {
            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);

            // Check that the ship is empty
            Assert.That(testShip.ShipGoods.Count, Is.EqualTo(0), "Ship should start out with no goods on-board");

            // Add some water to the starting system for this ship to buy
            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");
            startingSystem.AddGood(water.GoodId, 5);

            // Verify that the good was added to the system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            // Make sure only 5 are at the system
            systemWater.Quantity = 5;

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

            Assert.Fail("Player should not been able to buy more goods than at the system");
        }
Esempio n. 30
0
        public void Buy()
        {
            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;

            // Check that the ship is empty
            Assert.That(testShip.ShipGoods.Count, Is.EqualTo(0), "Ship should start out with no goods on-board");

            // Add some water to the starting system for this ship to buy
            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");
            startingSystem.AddGood(water.GoodId, 20);

            // Verify that the good was added to the system
            SystemGood systemWater = startingSystem.GetGood(water.GoodId);

            Assert.That(systemWater, Is.Not.Null, "System should now have a water SystemGood");
            Assert.That(systemWater.Quantity, Is.GreaterThanOrEqualTo(20), "System should now have at least 20 water goods");

            int playerCost          = systemWater.Price * 20;
            int systemStartingCount = systemWater.Quantity;

            systemWater.Buy(testShip, 20, systemWater.Price);

            Assert.That(systemWater.Quantity, Is.EqualTo(systemStartingCount - 20), "System should now have 20 few water goods");
            Assert.That(testPlayer.Ship.Credits, Is.EqualTo(playerStartingCash - playerCost), "Player should have less cash credits now after buying");
        }