public void Status_Can_Edit_Valid_Changes()
        {
            // Arrange
            Mock <ILogger <StatusesController> > mockLogger           = new Mock <ILogger <StatusesController> >();
            Mock <IStatusRepository>             mockStatusRepository = new Mock <IStatusRepository>();
            Mock <ITempDataDictionary>           tempData             = new Mock <ITempDataDictionary>();

            mockStatusRepository.Setup(m => m.GetStatuses).Returns(new Status[] {
                new Status {
                    StatusId = 1, Name = "S1"
                },
                new Status {
                    StatusId = 2, Name = "S2"
                },
                new Status {
                    StatusId = 3, Name = "S3"
                },
            }.AsQueryable <Status>());

            StatusesController controller = new StatusesController(mockLogger.Object, mockStatusRepository.Object)
            {
                TempData = tempData.Object
            };

            // Act
            IActionResult result1 = controller.Edit(new Status {
                StatusId = 1, Name = "S1"
            });
            IActionResult result2 = controller.Edit(new Status {
                StatusId = 2, Name = "S2"
            });
            IActionResult result3 = controller.Edit(new Status {
                StatusId = 3, Name = "S3"
            });

            // Assert
            Assert.AreEqual("List", (result1 as RedirectToActionResult).ActionName);
            Assert.AreEqual("List", (result2 as RedirectToActionResult).ActionName);
            Assert.AreEqual("List", (result3 as RedirectToActionResult).ActionName);
        }
        public void Status_Cannot_Edit_Nonexistent()
        {
            // Arrange
            Mock <ILogger <StatusesController> > mockLogger           = new Mock <ILogger <StatusesController> >();
            Mock <IStatusRepository>             mockStatusRepository = new Mock <IStatusRepository>();

            StatusesController controller = new StatusesController(mockLogger.Object, mockStatusRepository.Object);

            // Act
            Status result = GetViewModel <Status>(controller.Edit(4));

            // Assert
            Assert.IsNull(result);
        }
        public void Status_Cannot_Edit_Invalid_Changes()
        {
            // Arrange
            Status status = new Status {
                StatusId = 2, Name = ""
            };

            Mock <ILogger <StatusesController> > mockLogger           = new Mock <ILogger <StatusesController> >();
            Mock <IStatusRepository>             mockStatusRepository = new Mock <IStatusRepository>();

            StatusesController controller = new StatusesController(mockLogger.Object, mockStatusRepository.Object);

            controller.ModelState.AddModelError("error", "error");

            // Act
            IActionResult result = controller.Edit(status);

            // Assert
            mockStatusRepository.Verify(m => m.EditStatus(It.IsAny <Status>()), Times.Never());
        }