//        [Test]
        /// <summary>
        /// Test correct behaviour occurs when the asset owner does not own the sitting parcel water rights
        /// </summary>
        public void TestAssetParcelWaterRightsNotOwned()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 10 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable = 18, WaterRightsOwner = p1 };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterAvailable = 14, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 20, Field = f1 };
            bp1.AddGameAsset(h1);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(18));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(14));
            Assert.That(p1.Water, Is.EqualTo(32));

            allocator.ChangeAllocation(h1, p1, h1.WaterUsage);

            Assert.That(h1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(20));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(0));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(12));
            Assert.That(p1.Water, Is.EqualTo(12));
        }
        /// <summary>
        /// Test a partial undo of allocated water
        /// </summary>
        //        [Test]
        public void TestUndoPartial()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 15, DevelopmentRightsOwner = p1, WaterRightsOwner = p1 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable =  8, WaterRightsOwner = p1 };
            Field field1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "field1") { BuyPoint = bp1 };
            Factory f1 = new Factory("Factory1", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 10, Field = field1 };
            bp1.AddGameAsset(f1);

            allocator.ChangeAllocation(f1, p1, f1.WaterUsage);
            allocator.ChangeAllocation(f1, p1, 6);

            Assert.That(f1.WaterAllocated, Is.EqualTo(6));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(9));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
        }
        //        [Test]
        public void TestNotEnoughWaterWithAnotherParcel()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 10, WaterRightsOwner = p1 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable =  8, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 25, Field = f1 };
            bp1.AddGameAsset(h1);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
            Assert.That(p1.Water, Is.EqualTo(18));

            bool exceptionThrown = false;
            try
            {
                allocator.ChangeAllocation(h1, p1, h1.WaterUsage);
            }
            catch (WaterWarsGameLogicException)
            {
                exceptionThrown = true;
            }

            Assert.That(exceptionThrown, Is.True);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(10));
            Assert.That(bp2.WaterAvailable, Is.EqualTo(8));
            Assert.That(p1.Water, Is.EqualTo(18));
        }
        //        [Test]
        public void TestUndoOwnsOtherParcelWaterRights()
        {
            TestHelpers.InMethod();
            //log4net.Config.XmlConfigurator.Configure();

            ParcelOrientedAllocator allocator = new ParcelOrientedAllocator();

            Player p1 = new Player("Alfred", UUID.Parse("00000000-0000-0000-0000-000000000001"));
            BuyPoint bp1 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000010")) { WaterAvailable = 15, DevelopmentRightsOwner = p1 };
            BuyPoint bp2 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000020")) { WaterAvailable =  8, WaterRightsOwner = p1 };
            BuyPoint bp3 = new BuyPoint(UUID.Parse("00000000-0000-0000-0000-000000000030")) { WaterAvailable =  5, WaterRightsOwner = p1 };
            Field f1 = new Field(UUID.Parse("00000000-0000-0000-0001-000000000000"), "f1") { BuyPoint = bp1 };
            Houses h1 = new Houses("Houses", UUID.Parse("00000000-0000-0000-0010-000000000000"), Vector3.Zero, 1) { WaterUsage = 10, Field = f1 };
            bp1.AddGameAsset(h1);

            allocator.ChangeAllocation(h1, p1, h1.WaterUsage);
            allocator.ChangeAllocation(h1, p1, 0);

            Assert.That(h1.WaterAllocated, Is.EqualTo(0));
            Assert.That(bp1.WaterAvailable, Is.EqualTo(15));

            // We take water from the richest parcel first.  But when we undo, water is distributed back evenly.
            Assert.That(bp2.WaterAvailable, Is.EqualTo(5));
            Assert.That(bp3.WaterAvailable, Is.EqualTo(8));
        }
示例#5
0
        public void TestChosenAssetType()
        {
            TestHelpers.InMethod();

            BuyPoint bp1 = new BuyPoint(UUID.Zero);
            Assert.That(bp1.ChosenGameAssetTemplate, Is.EqualTo(AbstractGameAsset.None));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(0));
            Assert.That(bp1.Factories.Count, Is.EqualTo(0));

            Factory f1
                = new Factory("factory1", UUID.Parse("00000000-0000-0000-0000-000000000101"), Vector3.Zero);
            bp1.AddGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            Factory f2
                = new Factory("factory2", UUID.Parse("00000000-0000-0000-0000-000000000201"), Vector3.Zero);
            bp1.AddGameAsset(f2);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            bool gotExpectedException = false;
            Houses h1 = new Houses("houses1", UUID.Parse("00000000-0000-0000-0000-000000001001"), Vector3.Zero);
            try
            {
                bp1.AddGameAsset(h1);
            }
            catch (Exception)
            {
                gotExpectedException = true;
            }

            Assert.That(gotExpectedException, Is.True);
            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            gotExpectedException = false;
            try
            {
                bp1.RemoveGameAsset(h1);
            }
            catch (Exception)
            {
                gotExpectedException = true;
            }

            Assert.That(gotExpectedException, Is.True);
            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(2));
            Assert.That(bp1.Factories.Count, Is.EqualTo(2));

            bp1.RemoveGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            bp1.RemoveGameAsset(f1);

            Assert.That(bp1.ChosenGameAssetTemplate.Type, Is.EqualTo(AbstractGameAssetType.Factory));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(1));
            Assert.That(bp1.Factories.Count, Is.EqualTo(1));

            bp1.RemoveGameAsset(f2);

            Assert.That(bp1.ChosenGameAssetTemplate, Is.EqualTo(AbstractGameAsset.None));
            Assert.That(bp1.GameAssets.Count, Is.EqualTo(0));
            Assert.That(bp1.Factories.Count, Is.EqualTo(0));
        }