public ActionResult Create(WorkingDay w)
 {
     if (ModelState.IsValid)
     {
         _iRepository.Add(w);
         return RedirectToRoute("WorkingDayIndex");
     }
     return View("Create", w);
 }
 public ActionResult Edit(int id, WorkingDay wd)
 {
     if (ModelState.IsValid)
     {
         _iRepository.Update(wd);
         //return RedirectToAction("Index", "WorkingDay");
         return RedirectToRoute("WorkingDayIndex");
     }
     return View("Edit", wd);
 }
        public void AddTest()
        {
            //Arrange
            WorkingDay newWd = new WorkingDay();
            newWd.WorkingDayId = 99;
            newWd.DayDate = DateTime.Now;
            int countBeforeAdd = _workingDays.Count();

            _mockRepository.Setup(wd => wd.Add(newWd)).Callback(() =>
                {
                    var list = _workingDays.ToList();
                    list.Add(newWd);
                    _workingDays = list.AsEnumerable<WorkingDay>();
                }
            );

            //Act
            _repository.Add(newWd);
            int countAfterAdd = _workingDays.Count();

            //Assert
            Assert.AreEqual(countBeforeAdd+1, countAfterAdd);
        }
        public void DetailsTest()
        {
            //Arrange
            WorkingDay workingDay = new WorkingDay
            {
                WorkingDayId = 1,
                ContractId = 1,
                WorkTravelStartLocationId = 1,
                WorkTravelDestinationId = 2,
                Notes = "This is a test"
            };
            _mockRepository.Setup<WorkingDay>(r => r.FindById(1)).Returns(workingDay);

            //Act
            ViewResult result = _controller.Details(1) as ViewResult;
            WorkingDay resultmodel = result.Model as WorkingDay;
            //Assert
            Assert.IsNotNull(resultmodel);
            Assert.AreEqual(workingDay.ContractId, resultmodel.ContractId);
            Assert.AreEqual("Details", result.ViewName);
        }
        public void EditPostTest_ValidObject()
        {
            //Arrange
            WorkingDay workingDay = new WorkingDay();

            //Act
            var result = _controller.Edit(1, workingDay);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual("WorkingDayIndex", ((RedirectToRouteResult)result).RouteName);
        }
        public void EditPostTest_InvalidObject()
        {
            //Arrange
            _controller.ModelState.AddModelError("Just an error", "Your object is not valid!");
            WorkingDay workingDay = new WorkingDay();

            //Act
            ViewResult result = _controller.Edit(1, workingDay) as ViewResult;

            //Assert
            Assert.AreEqual("Edit", result.ViewName);
        }