public void FindCatFromDatabase() { //Arrange we want a repo, fill it with a cat, then be able to find one by running the Find() method on its name IAnimalRepository testrepo = DataTestService.GetInMemoryRepo(); var cat = new Cat() { Name = "TestKitty", Description = "A fine test kitty", Gender = Gender.Other, SpeciesId = 0, Species = new Species { Name = "Testspecies", Description = "A species to test with", SpeciesId = 0 } }; testrepo.Save(cat); string searchString = "Test"; //Act we want to retrieve the cat, using its name var result = testrepo.Find(searchString); Assert.NotEmpty(result); //We do not want result to be empty of elements Assert.Equal(cat.Name, result.First().Name.ToString()); //We expect there to only be one Cat in the list, i.e. the first element. }
public void CatWithSameIDOverWritesCurrentCatInDB() { 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"; testrepo.Save(sameCat); Assert.Single(testrepo.Get()); Assert.Equal(sameCat.Name, testrepo.Get(1).Name); }
public void DeleteCatFromDatabase() { //Arrange IAnimalRepository testrepo = DataTestService.GetInMemoryRepo(); var cat = new Cat() { Name = "TestKitty", Description = "A fine test candidate", Species = new Species { Name = "TestSpecies", Description = "A test species" }, SpeciesId = 0 }; testrepo.Save(cat); //Act testrepo.Delete(testrepo.Get(1).CatId); //Delete the cat we added to the db //Assert Assert.Empty(testrepo.Get()); //Assert that the database collection is empty }
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 }
public void TestAddMethodWithTwoPositiveNumbers() { DataTestService testService = new DataTestService(); int result = testService.Add(2, 5); Assert.Equal(7, result); }
public void TestIndexMethodReturnsObjects() { var mockRepo = new Mock<ISpeciesRepository>(); mockRepo.Setup(repo => repo.Get()) .Returns(DataTestService.GetTestSpecies()); var controller = new SpeciesController(mockRepo.Object); // Act var result = controller.Index(); // Assert var viewResult = Assert.IsType<ViewResult>(result); var model = Assert.IsAssignableFrom<IEnumerable<Species>>( viewResult.ViewData.Model); Assert.Equal(2, model.Count()); }
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()); }
public void TestIndexMethodReturnsObjects() { // Arrange var mockRepo = new Mock <ISpeciesRepository>(); //create mock repo mockRepo.Setup(repo => repo.Get()) .Returns(DataTestService.GetTestSpecies()); //Creates test species in mock repo and sends in the hardcoded test data to the tested class var controller = new SpeciesController(mockRepo.Object); //Use the species controller // Act var result = controller.Index(); //We are not doing async so no await. This will run the method in question // Assert var viewResult = Assert.IsType <ViewResult>(result); //Expect a view to be the output of the method var model = Assert.IsAssignableFrom <IEnumerable <Species> >( //asserts that we get a Species back viewResult.ViewData.Model); Assert.Equal(2, model.Count()); //Asserts that we get two items back from the list from the model }
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); }
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 }
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); }