public async Task VacationEditTestConcurrency()
        {
            VacationController controller = DependencyResolver.Current.GetService <VacationController>();
            VacationDto        model      = await EditVacation(controller);

            model.DateTo = model.DateTo.Value.AddDays(1);
            ActionResult result1 = await controller.Edit(model);

            Assert.IsTrue(result1 is RedirectToRouteResult);

            ViewResult result2 = await controller.Edit(model) as ViewResult;

            Assert.IsNotNull(result2);
            Assert.IsFalse(controller.ModelState.IsValid);
        }
        public async Task VacationEdit()
        {
            VacationController controller = DependencyResolver.Current.GetService <VacationController>();
            VacationDto        model      = await EditVacation(controller);

            model.DateTo = model.DateTo.Value.AddDays(1);
            ActionResult result = await controller.Edit(model);

            Assert.IsTrue(result is RedirectToRouteResult);
        }
        public async Task VacationEditMergeAndDelete()
        {
            VacationController controller = DependencyResolver.Current.GetService <VacationController>();
            VacationDto        model      = await EditVacation(controller, 4);

            model.EmployeeFirstName = "First1";
            model.EmployeeLastName  = "Last1";
            ActionResult result = await controller.Edit(model);

            Assert.IsTrue(result is RedirectToRouteResult);
        }
        public async Task VacationEditTestDateConstraint()
        {
            VacationController controller = DependencyResolver.Current.GetService <VacationController>();
            VacationDto        model      = await EditVacation(controller);

            DateTime?dateFrom = model.DateFrom;

            model.DateFrom = model.DateTo;
            model.DateTo   = dateFrom;
            ViewResult result = await controller.Edit(model) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsFalse(controller.ModelState.IsValid);
        }
        public async Task VacationEditTestDateTrigger()
        {
            VacationController controller = DependencyResolver.Current.GetService <VacationController>();
            VacationDto        model1     = await EditVacation(controller);

            VacationDto model2 = await EditVacation(controller, 2);

            Assert.IsTrue(model1.EmployeeID == model2.EmployeeID);

            model2.DateFrom = model1.DateFrom;
            ViewResult result = await controller.Edit(model2) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsFalse(controller.ModelState.IsValid);
        }
        public void PostEditVacationNotNullEmployeeUnpaidVacation_true()
        {
            //Arrange
            VacationController controller = new VacationController(mock.Object);

            //Act
            int    id      = 6;
            string oldFrom = "12.07.2014";
            string oldTo   = "28.07.2014";
            string newFrom = "15.09.2014";
            string newTo   = "30.09.2014";
            string type    = "UnpaidVacation";

            bool result = controller.Edit(id, oldFrom, oldTo, newFrom, newTo, type);

            //Assert
            Assert.IsTrue(result);
        }
        public void PostEditVacationNotNullEmployeeBadTypeCorrectDate_false()
        {
            //Arrange
            VacationController controller = new VacationController(mock.Object);

            //Act
            int    id      = 1;
            string oldfrom = "01.01.2014";
            string oldTo   = "15.01.2014";
            string newFrom = "01.02.2014";
            string newTo   = "15.02.2014";
            string type    = "Bad Type";

            bool result = controller.Edit(id, oldfrom, oldTo, newFrom, newTo, type);

            //Assert
            Assert.IsFalse(result);
        }
        public void PostEditVacationNotNullEmployeeBadTypeBadDate_false()
        {
            //Arrange
            VacationController controller = new VacationController(mock.Object);
            Vacation           vacation   = new Vacation {
                EmployeeID = 0
            };

            //Act
            int    id       = 1;
            string fromDate = "";
            string toDate   = "";
            string oldfrom  = "";
            string oldTo    = "";
            string type     = "Bad Type";

            bool result = controller.Edit(id, oldfrom, oldTo, fromDate, toDate, type);

            //Assert
            Assert.IsFalse(result);
            mock.Verify(m => m.SaveVacation(vacation), Times.Never);
        }
        private async Task <VacationDto> EditVacation(VacationController controller, int id = 1)
        {
            ViewResult result = await controller.Edit(id) as ViewResult;

            return(result.Model as VacationDto);
        }