Exemplo n.º 1
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);
        }
Exemplo 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);
        }
Exemplo n.º 3
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);
        }