public async void Edit_RedirectToAction()
        {
            // Arrange
            Apartment apartment = new Apartment {
                Id = 1
            };

            Mock <ApartmentRepository> mockApartamentRepository = new Mock <ApartmentRepository>();

            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.Edit(apartment.Id, apartment, null);

            // Assert
            Assert.NotNull(result);
            RedirectToActionResult redirect = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal(nameof(ApartmentsController.Index), redirect.ActionName);
            Assert.Null(redirect.ControllerName);
        }
        public async void EditModelIsNotValid_ViewResult()
        {
            // Arrange
            Apartment apartment = new Apartment {
                Id = 1
            };

            Mock <IUnitOfWork>   mockIUnitOfWork  = new Mock <IUnitOfWork>();
            Mock <IFileService>  mockIFileService = new Mock <IFileService>();
            ApartmentsController controller       = new ApartmentsController(mockIUnitOfWork.Object, mockIFileService.Object);

            controller.ModelState.AddModelError("RentEndDate", "Bad date!");

            // Act
            IActionResult result = await controller.Edit(apartment.Id, apartment, null);

            // 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 Edit_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.Edit(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 EditIdIsNull_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.Edit(null);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <NotFoundResult>(result);
        }
        public async void EditIdsAreDifferent_NotFoundResult()
        {
            // Arrange
            int       id        = 1;
            Apartment apartment = new Apartment {
                Id = 7, Name = "NewApartament"
            };

            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.Edit(id, apartment, null);

            // Assert
            Assert.NotNull(result);
            Assert.IsType <NotFoundResult>(result);
        }