public void GetEmployeeData_StringABRAKADABRA_NothingFound() { //Arrange VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); // Act - call the action method var result = target.GetEmployeeData(mock.Object.Employees.ToList(), "ABRAKADABRA"); // Assert - check the result Assert.AreEqual(0, result.ToArray().Length); }
public void GetEmployeeData_String0801_SelectedEmployees() { //Arrange VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); // Act - call the action method var result = target.GetEmployeeData(mock.Object.Employees.ToList(), "8/1/2012"); // Assert - check the result Assert.AreEqual(1, result.ToArray().Length); Assert.AreEqual("Zarose", result.ToArray()[0].LastName); CollectionAssert.AllItemsAreInstancesOfType(result.ToList(), typeof(Employee)); }
public void GetEmployeeData_StringEmpty_AllEmployees() { //Arrange VisaRegistrationDateController target = new VisaRegistrationDateController(mock.Object, messengerMock.Object); // Act - call the action method var result = target.GetEmployeeData(mock.Object.Employees.ToList(), ""); // Assert - check the result Assert.AreEqual(24, result.ToArray().Length); Assert.AreEqual("Kowwood", result.ToArray()[0].LastName); Assert.AreEqual("Only", result.ToArray()[6].LastName); CollectionAssert.AllItemsAreInstancesOfType(result.ToList(), typeof(Employee)); }
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 CreatePost_CannotCreate_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"); ViewResult result = target.Create(visaRegDate) as ViewResult; // Assert - check the result mock.Verify(m => m.SaveVisaRegistrationDate(It.IsAny <VisaRegistrationDate>(), It.IsAny <int>()), Times.Never); Assert.IsInstanceOf(typeof(RegistrationDateViewModel), result.ViewData.Model); Assert.IsInstanceOf(typeof(ViewResult), result); }
public void DeletePost_ValidVisaRegistrationDate() { // 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.DeleteConfirmed(1, "as"); // Assert - check the result mock.Verify(m => m.DeleteVisaRegistrationDate(1), Times.Once); Assert.AreEqual("TableViewVisasAndPermitsBTM", ((ViewResult)result).ViewName); Assert.IsInstanceOf(typeof(List <Employee>), ((ViewResult)result).Model); Assert.AreEqual("as", ((ViewResult)result).ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", ((ViewResult)result).ViewBag.JSDatePattern); }
public void CreateGet_VisaRegistrationDateOf_ExistingEmployeeSearchStringEmpty() { // 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.Create(5) as ViewResult; VisaRegistrationDate visaRegDate = (VisaRegistrationDate)result.ViewData.Model; // Assert - check the result Assert.AreEqual("", result.ViewName); Assert.AreEqual("", result.ViewBag.SearchString); Assert.AreEqual("dd.mm.yyyy", result.ViewBag.JSDatePattern); Assert.IsInstanceOf(typeof(ViewResult), result); Assert.AreEqual("Daolson Ivan (daol) from RAAA4", result.ViewBag.EmployeeInformation); Assert.IsNull(visaRegDate); }
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_ValidEmployeeID() { // 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, "st") 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("st", 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); }