Beispiel #1
0
        public void UpdateAppleTreeTest()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

            //If there's no tree, insert one
            if (InMemoryContext.AppleTrees.Count() == 0)
            {
                InMemoryContext.AppleTrees.Add(new AppleTree {
                    WaterConsumption = 100, AppleYield = 200, FertilizingAgent = Fertilizer.Medium
                });
                InMemoryContext.SaveChanges();
            }

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

            //Get the first in memory apple tree
            var appletree = InMemoryContext.AppleTrees.FirstOrDefault();

            //Change a property
            appletree.WaterConsumption = 200;
            //Update the tree
            appleTreeHelper.UpdateTree(appletree);

            //Assert
            Assert.AreEqual(200, InMemoryContext.AppleTrees.FirstOrDefault().WaterConsumption);
        }
Beispiel #2
0
        public void CreateAppleTreeAndGetAppleTreeAllTests()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

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

            appleTreeHelper.DeleteAppleTreeAll();

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



            //Create an in memory apple tree
            var appletree = appleTreeHelper.CreateAppleTree(100, 110, Fertilizer.Medium);

            //Check if tree was inserted
            Assert.AreEqual(InMemoryContext.AppleTrees.Count(), 1);

            //Check the inserted tree's properties
            Assert.AreEqual(100, InMemoryContext.AppleTrees.FirstOrDefault().AppleYield);
            Assert.AreEqual(110, InMemoryContext.AppleTrees.FirstOrDefault().WaterConsumption);
            Assert.AreEqual(Fertilizer.Medium, InMemoryContext.AppleTrees.FirstOrDefault().FertilizingAgent);
        }
Beispiel #3
0
        public void CreateAppleTreeTestsWithObjectAsParameter()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

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

            appleTreeHelper.DeleteAppleTreeAll();

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

            //Create an in memory tree
            var tree = new AppleTree
            {
                AppleYield       = 200,
                WaterConsumption = 220,
                FertilizingAgent = Fertilizer.Strong
            };

            appleTreeHelper.CreateAppleTree(tree);

            //Check if tree was inserted
            Assert.AreEqual(InMemoryContext.AppleTrees.Count(), 1);

            //Check the inserted tree's properties
            Assert.AreEqual(200, InMemoryContext.AppleTrees.FirstOrDefault().AppleYield);
            Assert.AreEqual(220, InMemoryContext.AppleTrees.FirstOrDefault().WaterConsumption);
            Assert.AreEqual(Fertilizer.Strong, InMemoryContext.AppleTrees.FirstOrDefault().FertilizingAgent);
        }
Beispiel #4
0
        public void DeleteAppleTreeAllTest()
        {
            //Instantiate a new DbContext with the in memory database
            var InMemoryContext = new AppleTreeDbContext(options);

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

            //If there's no tree, insert one
            if (InMemoryContext.AppleTrees.Count() == 0)
            {
                InMemoryContext.AppleTrees.Add(new Commons.AppleTree {
                    WaterConsumption = 100, AppleYield = 200, FertilizingAgent = Fertilizer.Medium
                });
                InMemoryContext.SaveChanges();
            }

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

            //Delete them
            appleTreeHelper.DeleteAppleTreeAll();

            //Check for correct deletion
            Assert.AreEqual(InMemoryContext.AppleTrees.Count(), 0);
        }