Exemple #1
0
        public void Index()
        {
            // Arrange
            DateDiffController controller = new DateDiffController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemple #2
0
        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");
        }
Exemple #3
0
        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");
        }
Exemple #4
0
        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);
        }