public void EditGet_CannotEdit_InvalidEmployeeID() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); // Act - call the action method var result = (HttpNotFoundResult)target.Edit(15); VisaRegistrationDate visaRegDate = mock.Object.VisaRegistrationDates.Where(m => m.EmployeeID == 15).FirstOrDefault(); // Assert - check the result Assert.IsInstanceOf(typeof(HttpNotFoundResult), result); Assert.AreEqual(404, result.StatusCode); Assert.IsNull(visaRegDate); }
public void EditPost_CannotEdit_InvalidVisaRegistrationDate() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); VisaRegistrationDate visaRegDate = new VisaRegistrationDate(); // Act - call the action method target.ModelState.AddModelError("error", "error"); var result = target.Edit(visaRegDate); // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(visaRegDate, 1), Times.Never); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.AreEqual("", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(RegistrationDateViewModel), ((ViewResult)result).ViewData.Model); }
public void EditPost_ValidModelConcurrency_ErrorReturned() { //Arrange VisaRegistrationDateController controller = new VisaRegistrationDateController(mock.Object, messengerMock.Object); string modelError = "The record you attempted to edit " + "was modified by another user after you got the original value. The " + "edit operation was canceled."; VisaRegistrationDate visaRegDate = mock.Object.VisaRegistrationDates.Where(p => p.EmployeeID == 1).FirstOrDefault(); mock.Setup(m => m.SaveVisaRegistrationDate(visaRegDate, visaRegDate.EmployeeID)).Throws(new DbUpdateConcurrencyException()); //Act var result = controller.Edit(visaRegDate); string data = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target; //Assert mock.Verify(d => d.SaveVisaRegistrationDate(visaRegDate, visaRegDate.EmployeeID), Times.Once()); Assert.AreEqual(typeof(JsonResult), result.GetType()); Assert.AreEqual(modelError, data); }
public void EditGet_CanEdit_ValidEmployeeIDSearchStruingEmpty() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); MvcApplication.JSDatePattern = "dd.mm.yyyy"; // Act - call the action method var result = target.Edit(5) as ViewResult; RegistrationDateViewModel visaRegDate = (RegistrationDateViewModel)result.ViewData.Model; // Assert - check the result Assert.AreEqual("", result.ViewName); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.IsNotNull(result.ViewData.Model); Assert.AreEqual(5, visaRegDate.EmployeeID); Assert.AreEqual("Daolson Ivan (daol) from RAAA4", result.ViewBag.EmployeeInformation); Assert.AreEqual("", result.ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", result.ViewBag.JSDatePattern); }
public void EditPost_CanEdit_ValidVisaRegistrationDate() { // Arrange - create the controller VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); VisaRegistrationDate visaRegDate = new VisaRegistrationDate { EmployeeID = 5, RegistrationDate = new DateTime(2013, 04, 01), VisaType = "D10" }; MvcApplication.JSDatePattern = "dd.mm.yyyy"; target.ControllerContext = controllerContext.Object; // Act - call the action method var result = target.Edit(visaRegDate); // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(visaRegDate, 5), Times.Once); Assert.AreEqual("TableViewVisasAndPermitsBTM", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(List <Employee>), ((ViewResult)result).Model); Assert.AreEqual("", ((ViewResult)result).ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", ((ViewResult)result).ViewBag.JSDatePattern); }