コード例 #1
0
 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;
 }
コード例 #2
0
        public void CanDeleteTimeEntry()
        {
            // Establish Context
            var timeEntryToDelete = new TimeEntry();

            _timeEntryRepository.Expect(r => r.Get(1))
                .Return(timeEntryToDelete);

            // Act
            ActionConfirmation confirmation =
                _timeEntryManagementService.Delete(1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldBeNull();
        }
コード例 #3
0
ファイル: TimeEntryTests.cs プロジェクト: ryantornberg/wrms
        public void CanCompareTimeEntries()
        {
            var instance = new TimeEntry
                               {
                                   UserId = 1,
                                   RequestId = 5,
                                   Hours = "30.5",
                                   Notes = "Description for Agency ABC"
                               };

            var instanceToCompareTo = new TimeEntry
                                          {
                                              UserId = 1,
                                              RequestId = 5,
                                              Hours = "30.5",
                                              Notes = "Description for Agency ABC"
                                          };

            instance.ShouldEqual(instanceToCompareTo);
        }
コード例 #4
0
        public void CanCreateValidTimeEntryFromForm()
        {
            // Establish Context
            var timeEntryFromForm = new TimeEntry();

            _timeEntryManagementService.Expect(r => r.SaveOrUpdate(timeEntryFromForm))
                .Return(ActionConfirmation.CreateSuccessConfirmation("saved"));

            _authenticationProvider.Expect(x => x.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(x => x.GetByUserName(Arg<string>.Is.Anything)).Return(
                PersonInstanceFactory.CreateValidTransientPerson());

            // Act
            RedirectToRouteResult redirectResult =
                _timeEntriesController.Create(timeEntryFromForm)
                    .AssertActionRedirect().ToAction("Index");

            // Assert
            _timeEntriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString()
                .ShouldEqual("saved");
        }
コード例 #5
0
 private void TransferFormValuesTo(TimeEntry timeEntryToUpdate, TimeEntry timeEntryFromForm)
 {
     timeEntryToUpdate.UserId = timeEntryFromForm.UserId;
     timeEntryToUpdate.RequestId = timeEntryFromForm.RequestId;
     timeEntryToUpdate.EmployeeNumber = timeEntryFromForm.EmployeeNumber;
     timeEntryToUpdate.RequestNumber = timeEntryFromForm.RequestNumber;
     timeEntryToUpdate.WeekEndingDate = timeEntryFromForm.WeekEndingDate;
     timeEntryToUpdate.Hours = timeEntryFromForm.Hours;
     timeEntryToUpdate.Notes = timeEntryFromForm.Notes;
     timeEntryToUpdate.LastUpdateTimeStamp = timeEntryFromForm.LastUpdateTimeStamp;
     timeEntryToUpdate.LastUpdateUser = timeEntryFromForm.LastUpdateUser;
 }
コード例 #6
0
        public ActionConfirmation UpdateWith(TimeEntry timeEntryFromForm, int idOfTimeEntryToUpdate)
        {
            TimeEntry timeEntryToUpdate =
                _timeEntryRepository.Get(idOfTimeEntryToUpdate);
            TransferFormValuesTo(timeEntryToUpdate, timeEntryFromForm);

            if (timeEntryToUpdate.IsValid())
            {
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The Time Entry was successfully updated.");
                updateConfirmation.Value = timeEntryToUpdate;

                return updateConfirmation;
            }
            else
            {
                _timeEntryRepository.DbContext.RollbackTransaction();

                return ActionConfirmation.CreateFailureConfirmation(
                    "The Time Entry could not be saved due to missing or invalid information.");
            }
        }
コード例 #7
0
        public ActionConfirmation SaveOrUpdate(TimeEntry timeEntry)
        {
            if (timeEntry.IsValid())
            {
                _timeEntryRepository.SaveOrUpdate(timeEntry);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation("");
                saveOrUpdateConfirmation.Value = timeEntry;

                return saveOrUpdateConfirmation;
            }
            else
            {
                _timeEntryRepository.DbContext.RollbackTransaction();

                return ActionConfirmation.CreateFailureConfirmation(
                    "The Time Entry could not be saved due to missing or invalid information.");
            }
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        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");
        }
コード例 #10
0
        public void CanUpdateWithValidTimeEntryFromForm()
        {
            // Establish Context
            TimeEntry validTimeEntryFromForm =
                TimeEntryInstanceFactory.CreateValidTransientTimeEntry();

            // Intentionally empty to ensure successful transfer of values
            var timeEntryFromDb = new TimeEntry();

            _timeEntryRepository.Expect(r => r.Get(1))
                .Return(timeEntryFromDb);

            // Act
            ActionConfirmation confirmation =
                _timeEntryManagementService.UpdateWith(validTimeEntryFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(timeEntryFromDb);
            confirmation.Value.ShouldEqual(validTimeEntryFromForm);
        }
コード例 #11
0
        public void CannotUpdateWithInvalidTimeEntryFromForm()
        {
            // Establish Context
            var invalidTimeEntryFromForm = new TimeEntry();

            // Intentionally empty to ensure successful transfer of values
            var timeEntryFromDb = new TimeEntry();

            _timeEntryRepository.Expect(r => r.Get(1))
                .Return(timeEntryFromDb);

            // Act
            ActionConfirmation confirmation =
                _timeEntryManagementService.UpdateWith(invalidTimeEntryFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
コード例 #12
0
        public void CannotSaveOrUpdateInvalidTimeEntry()
        {
            // Establish Context
            var invalidTimeEntry = new TimeEntry();

            // Act
            ActionConfirmation confirmation =
                _timeEntryManagementService.SaveOrUpdate(invalidTimeEntry);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }