Ejemplo n.º 1
0
        public void CatWithSameIDOverWritesCurrentCatInDB()
        {
            //Arrange
            IAnimalRepository testrepo = DataTestService.GetInMemoryRepo();

            var cat = new Cat()
            {
                Name        = "TestKitty",
                Description = "A fine test candidate"
            };

            testrepo.Save(cat);

            var sameCat = testrepo.Get(1);

            sameCat.Name = "TestKitty2";

            //Act
            testrepo.Save(sameCat);

            //Assert

            Assert.Single(testrepo.Get());                    //We want there to still only be a single item in the list, since it should be overwritten
            Assert.Equal(sameCat.Name, testrepo.Get(1).Name); //We want the name to have been updated
        }
Ejemplo n.º 2
0
        public void DeleteCatFromDatabase()
        {
            
            IAnimalRepository testrepo = DataTestService.GetInMemoryRepo();

            var cat = new Cat()
            {
                Name = "TestKitty",
                Description = "A fine test candidate"
            };

            testrepo.Save(cat);

            
            testrepo.Delete(testrepo.Get(1).CatId); 

            
            Assert.Empty(testrepo.Get()); 
        }
Ejemplo n.º 3
0
        public void AddNewCatToDatabase()
        {
            

            IAnimalRepository testRepo = DataTestService.GetInMemoryRepo(); 

            var cat = new Cat() 
            {
                Name = "TestKitty",
                Description = "A fine test candidate"
            };

            

            testRepo.Save(cat);

            

            Assert.Single(testRepo.Get()); 
            Assert.Equal(cat.Name, testRepo.Get(1).Name); 

        }
Ejemplo n.º 4
0
        public void AddNewCatToDatabase()
        {
            //Arrange We need to get a test version of the Animal Repository

            IAnimalRepository testRepo = DataTestService.GetInMemoryRepo(); //Get test repo


            var cat = new Cat() //Create test cat
            {
                Name        = "TestKitty",
                Description = "A fine test candidate"
            };

            //Act We want to run the Save method of the repository

            testRepo.Save(cat);

            //Assert We want to make sure that the repository has saved the test object

            Assert.Single(testRepo.Get());                //We expect to have one single item in our repo
            Assert.Equal(cat.Name, testRepo.Get(1).Name); //We expect the item to have the name of the test item
        }
Ejemplo n.º 5
0
        public void GetCatFromDatabase()
        {
            //Arrange we need a test repo and a cat saved to the testrepo

            IAnimalRepository testrepo = DataTestService.GetInMemoryRepo();

            var cat = new Cat()
            {
                Name        = "TestKitty",
                Description = "A fine test candidate"
            };

            testrepo.Save(cat);

            //Act we want the returned cat to be equal to the one put into the database

            var result = testrepo.Get(1);

            //Assert

            Assert.Equal(cat, result);
        }