public void CannotCreateInvalidTimeEntryFromForm() { // Establish Context var timeEntryFromForm = new TimeEntry(); var viewModelToExpect = new TimeEntryFormViewModel(); _timeEntryManagementService.Expect(r => r.SaveOrUpdate(Arg <TimeEntry> .Is.Anything)) .Return(ActionConfirmation.CreateFailureConfirmation("not saved")); _timeEntryManagementService.Expect( r => r.CreateFormViewModelFor(Arg <TimeEntry> .Is.Anything, Arg <string> .Is.Anything)) .Return(viewModelToExpect); _authenticationProvider.Expect(x => x.GetLoggedInUser()).Return("testuser"); _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return( PersonInstanceFactory.CreateValidTransientPerson()); // Act RedirectToRouteResult result = _timeEntriesController.Create(timeEntryFromForm).AssertActionRedirect().ToAction("Index"); // Assert //result.ViewData.Model.ShouldNotBeNull(); //(result.ViewData.Model as TimeEntryFormViewModel).ShouldNotBeNull(); //_timeEntriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString().ShouldEqual("updated"); }
public ActionResult Edit(int id) { TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModelFor(id, _authenticationProvider.GetLoggedInUser()); return(View(viewModel)); }
public ActionResult Index(string date) { TimeEntryFormViewModel formView = _timeEntryManagementService.CreateFormViewModel(GetWeekEndingDate(date), _authenticationProvider. GetLoggedInUser()); return(View(formView)); }
public ActionResult Create(DateTime weekEndingDate) { TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModel(weekEndingDate, _authenticationProvider.GetLoggedInUser()); return(View(viewModel)); }
public ActionResult Index(TimeEntry timeEntry) { TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModelFor(timeEntry, _authenticationProvider.GetLoggedInUser()); if (!viewModel.TimeEntry.SystemId.HasValue) { viewModel.RecentRequests.Clear(); } return(View(viewModel)); }
public TimeEntryFormViewModel CreateFormViewModelFor(TimeEntry timeEntry, string userName) { DateTime weekEndingDate = DateTime.Today; if (timeEntry != null && timeEntry.WeekEndingDate.HasValue) { weekEndingDate = timeEntry.WeekEndingDate.Value; } TimeEntryFormViewModel viewModel = CreateFormViewModel(weekEndingDate, userName); viewModel.TimeEntry = timeEntry; return(viewModel); }
public TimeEntryFormViewModel CreateFormViewModel(DateTime weekEndingDate, string userName) { var user = _personManagementService.GetByUserName(userName); var viewModel = new TimeEntryFormViewModel { WeekEndingDate = weekEndingDate, RecentRequests = _timeEntryRepository.GetRecentRequests(user.Id), Systems = _wrmsSystemRepository.GetActiveSystems(0, "Code", "Asc"), UserId = user.Id }; return(viewModel); }
public void CanInitEdit() { // Establish Context var viewModel = new TimeEntryFormViewModel(); _timeEntryManagementService.Expect( r => r.CreateFormViewModelFor(Arg <int> .Is.Anything, Arg <string> .Is.Anything)) .Return(viewModel); // Act ViewResult result = _timeEntriesController.Edit(1).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as TimeEntryFormViewModel).ShouldNotBeNull(); }
public void CanInitCreate() { // Establish Context var viewModel = new TimeEntryFormViewModel(); _timeEntryManagementService.Expect(r => r.CreateFormViewModel(DateTime.Today, "testuser")) .Return(viewModel); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser"); // Act ViewResult result = _timeEntriesController.Create(DateTime.Today).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as TimeEntryFormViewModel).ShouldNotBeNull(); (result.ViewData.Model as TimeEntryFormViewModel).TimeEntry.ShouldBeNull(); }
public void CanCreateFormViewModel() { // Establish Context var viewModelToExpect = new TimeEntryFormViewModel(); _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return( PersonInstanceFactory.CreateValidTransientPerson()); //_timeEntryRepository.Expect(x => x.GetRecentRequests(Arg<int>.Is.Anything)).Return(null); // Act TimeEntryFormViewModel viewModelRetrieved = _timeEntryManagementService.CreateFormViewModel(DateTime.Today, "testuser"); // Assert viewModelRetrieved.ShouldNotBeNull(); viewModelRetrieved.TimeEntry.ShouldBeNull(); }
public ActionResult Create(TimeEntry timeEntry) { int userId = GetCurrentUser().Id; timeEntry.LastUpdateTimeStamp = DateTime.Now; timeEntry.LastUpdateUser = userId; timeEntry.UserId = userId; timeEntry.Notes = Server.HtmlEncode(timeEntry.Notes); var timeEntryDateString = string.Empty; if (timeEntry.WeekEndingDate.HasValue) { timeEntryDateString = timeEntry.WeekEndingDate.Value.ToString("MM-dd-yyyy"); } if (ViewData.ModelState.IsValid) { ActionConfirmation saveOrUpdateConfirmation = _timeEntryManagementService.SaveOrUpdate(timeEntry); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString }))); } } else { timeEntry = null; } TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModelFor(timeEntry, _authenticationProvider.GetLoggedInUser()); //return !string.IsNullOrEmpty(timeEntryDateString) ? RedirectToAction(action, new { date = timeEntryDateString }) : RedirectToAction(action); return(RedirectToAction("Index", new RouteValueDictionary(new { action = "Index", date = timeEntryDateString }))); }
public void CannotUpdateInvalidTimeEntryFromForm() { // Establish Context var timeEntryFromForm = new TimeEntry(); var viewModelToExpect = new TimeEntryFormViewModel(); _timeEntryManagementService.Expect(r => r.UpdateWith(timeEntryFromForm, 0)) .Return(ActionConfirmation.CreateFailureConfirmation("not updated")); _timeEntryManagementService.Expect( r => r.CreateFormViewModelFor(Arg <TimeEntry> .Is.Anything, Arg <string> .Is.Anything)) .Return(viewModelToExpect); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser"); _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return( PersonInstanceFactory.CreateValidTransientPerson()); // Act ViewResult result = _timeEntriesController.Edit(timeEntryFromForm).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as TimeEntryFormViewModel).ShouldNotBeNull(); }
public void CanCreateFormViewModelForTimeEntry() { // Establish Context var viewModelToExpect = new TimeEntryFormViewModel(); _personManagementService.Expect(x => x.GetByUserName(Arg <string> .Is.Anything)).Return( PersonInstanceFactory.CreateValidTransientPerson()); TimeEntry timeEntry = TimeEntryInstanceFactory.CreateValidTransientTimeEntry(); _timeEntryRepository.Expect(r => r.Get(Arg <int> .Is.Anything)) .Return(timeEntry); // Act TimeEntryFormViewModel viewModelRetrieved = _timeEntryManagementService.CreateFormViewModelFor(1, "testuser"); // Assert viewModelRetrieved.ShouldNotBeNull(); viewModelRetrieved.TimeEntry.ShouldNotBeNull(); viewModelRetrieved.TimeEntry.ShouldEqual(timeEntry); }
public ActionResult Edit(TimeEntry timeEntry) { timeEntry.LastUpdateTimeStamp = DateTime.Now; timeEntry.LastUpdateUser = GetCurrentUser().Id; timeEntry.Notes = Server.HtmlEncode(timeEntry.Notes); if (ViewData.ModelState.IsValid) { ActionConfirmation updateConfirmation = _timeEntryManagementService.UpdateWith(timeEntry, timeEntry.Id); if (updateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = updateConfirmation.Message; return(RedirectToAction("Index")); } } TimeEntryFormViewModel viewModel = _timeEntryManagementService.CreateFormViewModelFor(timeEntry, _authenticationProvider.GetLoggedInUser()); return(View(viewModel)); }