public async void Delete_ViewResult() { // 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(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.Delete(apartment.Id); // Assert Assert.NotNull(result); ViewResult viewResult = Assert.IsType <ViewResult>(result); Assert.NotNull(viewResult.Model); Apartment apartmentModel = Assert.IsType <Apartment>(viewResult.Model); Assert.Same(apartment, apartmentModel); Assert.Null(viewResult.ViewName); }
public async void DeleteIdIsNull_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.Delete(null); // Assert Assert.NotNull(result); Assert.IsType <NotFoundResult>(result); }