public void Index() { // Arrange DateDiffController controller = new DateDiffController(); // Act ViewResult result = controller.Index() as ViewResult; // Assert Assert.IsNotNull(result); }
public void NoInputProvided() { DateDiffController controller = new DateDiffController(); DateViewModel model = new DateViewModel() { FromDate = "", ToDate = "" }; // Act ViewResult result = controller.OnSubmit(model) as ViewResult; // Assert Assert.IsNotNull(result); var resultModel = result.Model as DateViewModel; Assert.AreEqual(controller.ModelState["FromDate"].Errors[0].ErrorMessage, "Please Enter Valid Date in dd/MM/yyyy format"); }
public void FromDateLessThanToDate() { DateDiffController controller = new DateDiffController(); DateViewModel model = new DateViewModel() { FromDate = "02/02/2018", ToDate = "01/02/2018" }; // Act ViewResult result = controller.OnSubmit(model) as ViewResult; // Assert Assert.IsNotNull(result); var resultModel = result.Model as DateViewModel; Assert.AreEqual(controller.ModelState["FromDate"].Errors[0].ErrorMessage, "From Date should be less than To Date"); }
public void GetDifferenceWithValidDates() { // Arrange DateDiffController controller = new DateDiffController(); DateViewModel model = new DateViewModel() { FromDate = "02/02/2018", ToDate = "04/02/2018" }; // Act ViewResult result = controller.OnSubmit(model) as ViewResult; // Assert Assert.IsNotNull(result); var resultModel = result.Model as DateViewModel; Assert.AreEqual(resultModel.TotalDays, 2); }