public async void DetailsApartamentIsNull_NotFoundResult() { // Arrange Apartment apartment = new Apartment { Id = 7, Name = "NewApartament" }; Mock <ApartmentRepository> mockApartamentRepository = new Mock <ApartmentRepository>(); mockApartamentRepository .Setup(ar => ar.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(null as Apartment)); Mock <IUnitOfWork> mockIUnitOfWork = new Mock <IUnitOfWork>(); mockIUnitOfWork .Setup(uw => uw.GetRepository <Apartment, ApartmentRepository>()) .Returns(mockApartamentRepository.Object); Mock <IFileService> mockIFileService = new Mock <IFileService>(); ApartmentsController controller = new ApartmentsController(mockIUnitOfWork.Object, mockIFileService.Object); // Act IActionResult result = await controller.Details(apartment.Id); // Assert Assert.NotNull(result); Assert.IsType <NotFoundResult>(result); }
public async void DetailsIdIsNull_NotFoundResult() { // Arrange Mock <IUnitOfWork> mockIUnitOfWork = new Mock <IUnitOfWork>(); Mock <IFileService> mockIFileService = new Mock <IFileService>(); ApartmentsController controller = new ApartmentsController(mockIUnitOfWork.Object, mockIFileService.Object); // Act IActionResult result = await controller.Details(null); // Assert Assert.NotNull(result); Assert.IsType <NotFoundResult>(result); }
public async void Details_ViewResult() { // Arrange Apartment apartment = new Apartment { Id = 7 }; Mock <ApartmentRepository> mockApartamentRepository = new Mock <ApartmentRepository>(); mockApartamentRepository .Setup(ar => ar.GetAsync(It.IsAny <int>(), It.IsAny <string>())) .Returns(Task.FromResult(apartment)); Mock <IUnitOfWork> mockIUnitOfWork = new Mock <IUnitOfWork>(); mockIUnitOfWork .Setup(uw => uw.GetRepository <Apartment, ApartmentRepository>()) .Returns(mockApartamentRepository.Object); Mock <IFileService> mockIFileService = new Mock <IFileService>(); ApartmentsController controller = new ApartmentsController(mockIUnitOfWork.Object, mockIFileService.Object); // Act IActionResult result = await controller.Details(apartment.Id); // Assert Assert.NotNull(result); ViewResult viewResult = Assert.IsType <ViewResult>(result); Assert.NotNull(viewResult.Model); Apartment ap = Assert.IsType <Apartment>(viewResult.Model); Assert.Equal(apartment, ap); Assert.Null(viewResult.ViewName); }