public void Index() { var dogOwnerViewModelMapper = new Mock <IDogOwnerViewModelMapper>(); var dogOwner = new DogOwner() { OwnerName = "Qwe", DogNameList = new List <string> { "q", "w", "e" } }; var dogOwners = new List <DogOwner> { dogOwner }; var dogOwnerListViewModel = new DogOwnerListViewModel { DogOwnerViewModels = dogOwners.Select(e => new DogOwnerViewModel { OwnerName = e.OwnerName, DogNames = e.DogNameList }).ToList() }; dogOwnerViewModelMapper.Setup(x => x.GetAllDogOwners()).Returns(dogOwnerListViewModel); //Arrange RobsDogsController controller = new RobsDogsController(dogOwnerViewModelMapper.Object); //Act ViewResult result = controller.Index() as ViewResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(dogOwnerListViewModel, result.Model); //Should be testing / verifying call to GetAllDogOwners and subsequent methods down the stack. //Moq is installed to help you. }
public void DogOwnersName() { var controller = new RobsDogsController(); var result = controller.Index() as ViewResult; var model = (DogOwnerListViewModel)result.Model; string dogOwner = model.DogOwnerViewModels[0].OwnerName; Assert.AreEqual("Rob", dogOwner); }
public void DogOwnersDogCount() { var controller = new RobsDogsController(); var result = controller.Index() as ViewResult; var model = (DogOwnerListViewModel)result.Model; var count = model.DogOwnerViewModels.Count; Assert.AreEqual(3, count); }
public void Index() { // Arrange RobsDogsController controller = new RobsDogsController(mockPetOwnerVMMapper.Object); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); // Should be testing/verifying call to GetAllDogOwners and subsequent methods down the stack. // Moq is installed to help you. }
public void ListOfDogNames() { List <string> actualDogs = new List <string>() { "Willow", "Nook", "Sox" }; var controller = new RobsDogsController(); var result = controller.Index() as ViewResult; var model = (DogOwnerListViewModel)result.Model; List <string> modelDogs = new List <string>() { model.DogOwnerViewModels[0].DogNames[0], model.DogOwnerViewModels[1].DogNames[0], model.DogOwnerViewModels[2].DogNames[0] }; Assert.AreEqual(actualDogs[0], modelDogs[0]); Assert.AreEqual(actualDogs[1], modelDogs[1]); Assert.AreEqual(actualDogs[2], modelDogs[2]); }
public void Index() { // Arrange service.Setup(c => c.GetAllDogOwners()).Returns(model); mapper.Setup(c => c.MapDogOwners(It.IsAny <List <DogOwner> >())).Returns(viewModel); RobsDogsController controller = new RobsDogsController(mapper.Object, service.Object); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); var mappedviewmodel = result.Model as DogOwnerListViewModel; Assert.AreSame(viewModel, mappedviewmodel); // Should be testing/verifying call to GetAllDogOwners and subsequent methods down the stack. service.Verify(x => x.GetAllDogOwners(), Times.Once); mapper.Verify(x => x.MapDogOwners(model), Times.Once); // Moq is installed to help you. }
public void Index() { // Arrange RobsDogsController controller = new RobsDogsController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); // Should be testing/verifying call to GetAllDogOwners and subsequent methods down the stack. // Moq is installed to help you. // ==================================================================================================== // Create test to ensure the expected 3/All records are returned. // ---------------------------------------------------------------------------------------------------- // Arrange var mockDogOwnerViewModelMapper = new Mock <Services.DogOwnerService>(); // Act List <Entities.DogOwner> actual = mockDogOwnerViewModelMapper.Object.GetAllDogOwners(); // getting records direct from entity Data.DogOwnerRepository expectedRepository = new Data.DogOwnerRepository(); List <Entities.DogOwner> expectedRecords = expectedRepository.GetAllDogOwners(); // Assert - Checking the expected results are not blank Assert.IsNotNull(expectedRecords); // Assert - Checking that results returned by service are not blank Assert.IsNotNull(actual); // Assert - Checking same amount of records in both data sets Assert.AreEqual(expectedRecords.Count, actual.Count); // Assert - Checking that correct number of records are returned Assert.AreEqual(actual.Count, mnEXPECTEDTOTALRECORDS); }
public void Index() { // Arrange var mockRepo = new Mock <IDogOwnerService>(); mockRepo .Setup(r => r.GetAllDogOwners()) .Returns(GetTestDogOwners()); RobsDogsController controller = new RobsDogsController(mockRepo.Object); // Act ViewResult result = controller.Index() as ViewResult; var repo = mockRepo.Object; // Assert Assert.IsNotNull(result); Assert.IsNotNull(repo); Assert.IsNotNull(repo.GetAllDogOwners()); Assert.IsInstanceOfType(repo.GetAllDogOwners(), typeof(List <DogOwner>)); Assert.IsTrue(repo.GetAllDogOwners().Count > 0); }
public async Task Index() { // Arrange var mockRepo = new Mock <IDogOwnerRepository>(); mockRepo .Setup(r => r.GetAllDogOwners()) .ReturnsAsync(GetTestDogOwners()); var controller = new RobsDogsController(mockRepo.Object); // Act var result = controller.GetAllDogOwners(); var repo = mockRepo.Object; // Assert Assert.IsNotNull(result); Assert.IsNotNull(repo); Assert.IsNotNull(repo.GetAllDogOwners()); Assert.IsInstanceOfType(await repo.GetAllDogOwners(), typeof(List <DogOwner>)); Assert.IsTrue((await repo.GetAllDogOwners()).Any()); }