public void GivenAServiceAttendance_WhenAdd_ThenAddToContext()
        {
            var expected = new ServiceAttendance { Id = 1 };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
        public void GivenAServiceAttendance_ThenUpdate_ThenContextSetsModified()
        {
            var expected = new ServiceAttendance { Id = 1 };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
        public void GivenAServiceAttendance_WhenRemove_ThenRemoveFromContext()
        {
            var expected = new ServiceAttendance { Id = 1 };

            Target.Remove(expected);

            MockDbSet.AssertWasCalled(m => m.Remove(expected));
        }
        public void GivenIdRequestParameter_AndServiceAttendanceMatchesStudentAssignedOfferingId_WhenInvokeFilterPredicate_ThenReturnTrue()
        {
            ServiceAttendance attendance = new ServiceAttendance { StudentAssignedOfferingId = 1 };
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(attendance));
        }
 private void Create(StudentAssignedOffering studentAssignedOffering, DateTime dateAttended, Subject subject, decimal duration, string notes, EducationSecurityPrincipal user)
 {
     var newAttendance = new ServiceAttendance();
     newAttendance.StudentAssignedOffering = studentAssignedOffering;
     newAttendance.DateAttended = dateAttended;
     newAttendance.Subject = subject;
     newAttendance.Duration = duration;
     newAttendance.Notes = notes;
     newAttendance.CreatingUser = user.Identity.User;
     ServiceAttendanceRepository.Add(newAttendance);
 }
        public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull()
        {
            ServiceAttendance expectedState = new ServiceAttendance
            {
                CreateTime = new DateTime(2005, 4, 30),
                CreatingUser = new User { DisplayName = "fredBob" }
            };
            ServiceAttendanceModel target = new ServiceAttendanceModel();

            target.CopyFrom(expectedState);

            Assert.IsNull(target.Audit.LastModifiedBy);
            Assert.IsFalse(target.Audit.LastModifyTime.HasValue);
        }
        public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet()
        {
            ServiceAttendance expectedState = new ServiceAttendance
            {
                CreateTime = new DateTime(2005, 4, 30),
                CreatingUser = new User { DisplayName = "fredBob" },
                LastModifyTime = new DateTime(2010, 5, 13),
                LastModifyingUser = new User { DisplayName = "jimGeorge" }
            };
            ServiceAttendanceModel target = new ServiceAttendanceModel();

            target.CopyFrom(expectedState);

            AuditModel actualState = target.Audit;
            Assert.AreEqual(expectedState.CreateTime, actualState.CreateTime);
            Assert.AreEqual(expectedState.CreatingUser.DisplayName, actualState.CreatedBy);
            Assert.AreEqual(expectedState.LastModifyTime, actualState.LastModifyTime);
            Assert.AreEqual(expectedState.LastModifyingUser.DisplayName, actualState.LastModifiedBy);
        }
        public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();
            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();
            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);
            ServiceAttendance attendance = new ServiceAttendance
            {
                DateAttended = DateTime.Now.AddYears(100),
                StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(),
                Subject = EducationContext.Subjects.First(),
                CreatingUser = User.Identity.User
            };
            EducationContext.ServiceAttendances.Add(attendance);
            EducationContext.SaveChanges();

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
 public void Create(ServiceAttendanceModel viewModel, EducationSecurityPrincipal user)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     if (user == null)
     {
         throw new ArgumentNullException("user");
     }
     var studentAssignedOffering = StudentAssignedOfferingRepository.Items.Single(s => s.Id == viewModel.StudentAssignedOfferingId);
     IPermission permission = PermissionFactory.Current.Create("CreateServiceAttendance", studentAssignedOffering);
     permission.GrantAccess(user);
     ServiceAttendance serviceAttendance = new ServiceAttendance
     {
         CreatingUser = user.Identity.User
     };
     viewModel.CopyTo(serviceAttendance);
     ServiceAttendanceRepository.Add(serviceAttendance);
     RepositoryContainer.Save();
 }
 private static void AssertState(ServiceAttendance expectedState, ServiceAttendanceModel actual)
 {
     Assert.AreEqual(expectedState.Id, actual.Id);
     Assert.AreEqual(expectedState.Notes, actual.Notes);
     Assert.AreEqual(expectedState.StudentAssignedOfferingId, actual.StudentAssignedOfferingId);
     Assert.AreEqual(expectedState.SubjectId, actual.SelectedSubjectId);
 }
 private static bool AssertPropertiesMatch(ServiceAttendanceModel expectedState, ServiceAttendance actualState)
 {
     Assert.IsNotNull(actualState);
     Assert.AreEqual(expectedState.DateAttended, actualState.DateAttended);
     Assert.AreEqual(expectedState.SelectedSubjectId, actualState.SubjectId);
     Assert.AreEqual(expectedState.Duration, actualState.Duration);
     Assert.AreEqual(expectedState.Notes, actualState.Notes);
     return true;
 }
Exemplo n.º 12
0
        public void WhenConstruct_ThenCreateTimeSet()
        {
            ServiceAttendance actual = new ServiceAttendance();

            Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now));
        }
        public void WhenConstruct_ThenCreateTimeSet()
        {
            ServiceAttendance actual = new ServiceAttendance();

            Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now));
        }
        public void GivenValidModel_WhenCopyTo_ThenAllFieldsAreCopied()
        {
            var actual = new ServiceAttendance();
            Target.CopyFrom(TestData.ServiceAttendances[0]);

            Target.CopyTo(actual);

            Assert.AreEqual(actual.StudentAssignedOfferingId, Target.StudentAssignedOfferingId);
            Assert.AreEqual(actual.DateAttended, Target.DateAttended);
            Assert.AreEqual(actual.SubjectId, Target.SelectedSubjectId);
            Assert.AreEqual(actual.Duration, Target.Duration);
            Assert.AreEqual(actual.Notes, Target.Notes);
        }
        public void GivenServiceAttendance_WhenInvokeDataSelector_ThenPropertiesMatch()
        {
            ServiceAttendance expectedState = new ServiceAttendance
            {
                DateAttended = new DateTime(2003, 4, 5),
                Duration = 45,
                Id = 35,
                Notes = "blkah",
                Subject = new Subject { Name = "disojfw" }
            };
            MockRequest.Expect(m => m["id"]).Return("1");
            Target = new ServiceAttendanceClientDataTable(MockRequest);

            dynamic actual = Target.DataSelector.Compile().Invoke(expectedState);

            Assert.AreEqual(expectedState.DateAttended, actual.DateAttended);
            Assert.AreEqual(expectedState.Duration, actual.Duration);
            Assert.AreEqual(expectedState.Id, actual.Id);
            Assert.AreEqual(expectedState.Notes, actual.Notes);
            Assert.AreEqual(expectedState.Subject.Name, actual.Subject);
        }
 private static bool MatchProperties(ServiceAttendance actualState, StudentAssignedOffering expectedStudentAssignedOffering, DateTime expectedDateAttended, Subject expectedSubject, decimal expectedDuration, string expectedNotes)
 {
     Assert.AreEqual(expectedStudentAssignedOffering, actualState.StudentAssignedOffering);
     Assert.AreEqual(expectedDateAttended, actualState.DateAttended);
     Assert.AreEqual(expectedSubject.Id, actualState.Subject.Id);
     Assert.AreEqual(expectedDuration, actualState.Duration);
     Assert.AreEqual(expectedNotes, actualState.Notes);
     return true;
 }
 public void Update(ServiceAttendance item)
 {
     Context.SetModified(item);
 }
 public void Remove(ServiceAttendance item)
 {
     Context.ServiceAttendances.Remove(item);
 }
 public void Add(ServiceAttendance item)
 {
     Context.ServiceAttendances.Add(item);
 }