Ejemplo n.º 1
0
        public void UpdateFarmTest()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

            //If there's no farm, insert one
            if (InMemoryContext.Farms.Count() == 0)
            {
                InMemoryContext.Farms.Add(new Farm {
                    Name = "Another test farm", AppleTrees = AppleTreeDbInitializer.InitialiseTrees()
                });
                InMemoryContext.SaveChanges();
            }

            //Create an instance of FarmHelper and pass the in memory context as a parameter
            FarmHelper farmHelper = new FarmHelper(InMemoryContext);

            //Get the first in memory farm
            var farm = InMemoryContext.Farms.FirstOrDefault();

            //Change a property
            farm.Name = "Updated another test farm";
            //Update the farm
            farmHelper.UpdateFarm(farm);

            //Assert
            Assert.AreEqual("Updated another test farm", InMemoryContext.Farms.FirstOrDefault().Name);
        }
Ejemplo n.º 2
0
        public void CreateFarmTestsWithObjectAsParameter()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

            //Create an instance of FarmHelper and pass the in memory context as a parameter
            FarmHelper farmHelper = new FarmHelper(InMemoryContext);

            //Delete all farms
            farmHelper.DeleteFarmAll();

            //Check if the database is empty
            Assert.AreEqual(InMemoryContext.Farms.Count(), 0);



            //Create an in memory farm
            var farm = new Farm {
                Name       = "Second Testfarm",
                AppleTrees = AppleTreeDbInitializer.InitialiseTrees()
            };

            farmHelper.CreateFarm(farm);

            //Check if farm was inserted
            Assert.AreEqual(InMemoryContext.Farms.Count(), 1);

            //Check the inserted farm's properties
            Assert.AreEqual("Second Testfarm", InMemoryContext.Farms.FirstOrDefault().Name);
            Assert.AreEqual(10, InMemoryContext.Farms.FirstOrDefault().AppleTrees.Count);
        }
Ejemplo n.º 3
0
        public void CreateFarmAndGetFarmAllTests()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

            //Create an instance of FarmHelper and pass the in memory context as a parameter
            FarmHelper farmHelper = new FarmHelper(InMemoryContext);

            farmHelper.DeleteFarmAll();

            //Check if the database is empty
            Assert.AreEqual(InMemoryContext.Farms.Count(), 0);

            //Create an in memory farm
            var farm = farmHelper.CreateFarm("Testfarm", AppleTreeDbInitializer.InitialiseTrees());

            //Check if farm was inserted
            Assert.AreEqual(InMemoryContext.Farms.Count(), 1);

            //Check the inserted farm's properties
            Assert.AreEqual("Testfarm", InMemoryContext.Farms.FirstOrDefault().Name);
            Assert.AreEqual(10, InMemoryContext.Farms.FirstOrDefault().AppleTrees.Count);

            ObservableCollection <Farm> farms = new ObservableCollection <Farm>(farmHelper.GetFarmAll());

            Assert.AreEqual(farms.FirstOrDefault().AppleTrees.Count, 10);
        }
Ejemplo n.º 4
0
        public void DeleteFarmAllTest()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

            //Create an instance of FarmHelper and pass the in memory context as a parameter
            FarmHelper farmHelper = new FarmHelper(InMemoryContext);

            //If there's no farm, insert one
            if (InMemoryContext.AppleTrees.Count() == 0)
            {
                InMemoryContext.Farms.Add(new Farm {
                    Name = "Lets delete this farm", AppleTrees = AppleTreeDbInitializer.InitialiseTrees()
                });
                InMemoryContext.SaveChanges();
            }

            //Check if there are farms
            Assert.IsTrue(InMemoryContext.AppleTrees.Count() > 0);

            //Delete them
            farmHelper.DeleteFarmAll();

            //Check for correct deletion
            Assert.AreEqual(InMemoryContext.Farms.Count(), 0);
        }
Ejemplo n.º 5
0
        protected override void Laneclear()
        {
            if (this.Config["Laneclear"]["W"].Enabled)
            {
                var result = FarmHelper.GetCircularClearLocation(W.Range, W.Width, 2);
                if (result != null && result.numberOfMinionsHit >= 2)
                {
                    W.Cast(result.CastPosition);
                }
            }

            if (this.Config["Laneclear"]["Q"].Enabled)
            {
                var range = Q.IsCharging ? Q.Range : Q.ChargedMaxRange;

                var result = FarmHelper.GetLineClearLocation(range, Q.Width);

                if (result != null)
                {
                    if (result.numberOfMinionsHit >= 2)
                    {
                        Q.Cast(result.CastPosition);
                    }

                    else if (Q.IsCharging && result.numberOfMinionsHit >= 1 && Q.ChargePercent > 80)
                    {
                        Q.Cast(result.CastPosition);
                    }
                }
            }

            if (this.E.Ready && this.Config["Laneclear"]["E"].Enabled)
            {
                if (!this.Orbwalker.IsWindingUp && !Orbwalker.CanAttack())
                {
                    var minion = ObjectManager.Get <Obj_AI_Base>().Where(x => x.IsValidSpellTarget(E.Range) && HealthPrediction.Implementation.GetPrediction(x, (int)(E.Delay * 1000 + Player.Distance(x) / E.Speed * 1000)) <= Player.GetSpellDamage(x, SpellSlot.E) && E.GetPrediction(x).HitChance >= E.HitChance).FirstOrDefault();
                    if (minion != null)
                    {
                        var pred = E.GetPrediction(minion);
                        E.Cast(pred.CastPosition);
                    }
                }
            }
        }
        public static List <Farm> InitialiseFarms()
        {
            AppleTreeDbContext con = new AppleTreeDbContext();

            if (con.Farms.Count() == 0)
            {
                FarmHelper helper = new FarmHelper(con);

                List <Farm> farms = new List <Farm>
                {
                    new Farm
                    {
                        Name       = "First Farm",
                        AppleTrees = InitialiseTrees()
                    },
                    new Farm
                    {
                        Name       = "Second Farm",
                        AppleTrees = InitialiseTrees()
                    },
                    new Farm
                    {
                        Name       = "Third Farm",
                        AppleTrees = InitialiseTrees()
                    }
                };

                foreach (Farm farm in farms)
                {
                    if (!con.Farms.Where(c => c.Name == farm.Name).Any())
                    {
                        helper.CreateFarm(farm);
                    }
                }
                return(farms);
            }
            return(null);
        }