public void GivenServiceRequest_WhenAdd_ThenAddToContext() { var expected = new ServiceRequest { Id = 1 }; Target.Add(expected); MockDbSet.AssertWasCalled(m => m.Add(expected)); }
public void GivenAServiceRequests_WhenUpdate_ThenContextSetsModified() { var expected = new ServiceRequest { Id = 1 }; Target.Update(expected); MockContext.AssertWasCalled(m => m.SetModified(expected)); }
public void GivenAServiceRequest_WhenRemove_ThenRemoveFromContext() { var item = new ServiceRequest { Id = 1 }; Target.Remove(item); MockDbSet.AssertWasCalled(m => m.Remove(item)); }
public ManageServiceRequestPermission(ServiceRequest serviceRequest) { if (serviceRequest == null) { throw new ArgumentNullException("serviceRequest"); } ServiceRequest = serviceRequest; }
public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull() { ServiceRequest expectedState = new ServiceRequest { PriorityId = 1, SubjectId = 1, FulfillmentDetails = new List<ServiceRequestFulfillment> { new ServiceRequestFulfillment { FulfillmentStatusId = 1 } }, CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" } }; ServiceRequestModel target = new ServiceRequestModel(); target.CopyFrom(expectedState); Assert.IsNull(target.Audit.LastModifiedBy); Assert.IsFalse(target.Audit.LastModifyTime.HasValue); }
public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet() { ServiceRequest expectedState = new ServiceRequest { PriorityId = 1, SubjectId = 1, FulfillmentDetails = new List<ServiceRequestFulfillment> { new ServiceRequestFulfillment { FulfillmentStatusId = 1 } }, CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" }, LastModifyTime = new DateTime(2010, 5, 13), LastModifyingUser = new User { DisplayName = "jimGeorge" } }; ServiceRequestModel target = new ServiceRequestModel(); 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); }
private void AssertSuccessfulUpdate(ServiceRequest expected) { Repositories.MockServiceRequestRepository.AssertWasCalled(m => m.Update(expected)); Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save()); }
public void Update(ServiceRequest item) { Context.SetModified(item); }
public void Remove(ServiceRequest item) { Context.ServiceRequests.Remove(item); }
public void Add(ServiceRequest item) { Context.ServiceRequests.Add(item); }
private void CreateFulfillmentDetail(ServiceRequest model, EducationSecurityPrincipal user, ServiceRequestModel viewModel) { int selectedStatusId = viewModel.SelectedStatusId != 0 ? viewModel.SelectedStatusId : 1; var newDetail = new ServiceRequestFulfillment { FulfilledById = viewModel.SelectedAssignedOfferingId, CreatingUser = user.Identity.User, ServiceRequest = model, FulfillmentStatusId = selectedStatusId, Notes = viewModel.FulfillmentNotes }; if (model.FulfillmentDetails == null) { model.FulfillmentDetails = new List<ServiceRequestFulfillment> { newDetail }; } else { model.FulfillmentDetails.Add(newDetail); } }
private static ServiceRequest CreateServiceRequestInDatabase(int creatingUserId, int priorityId) { using (EducationDataContext context = new EducationDataContext()) { ServiceRequestFulfillment newServiceRequestFulfillment = new ServiceRequestFulfillment { FulfillmentStatusId = 1, Notes = "Test", CreatingUserId = 1 }; ServiceRequest newRequestToEdit = new ServiceRequest { CreatingUserId = creatingUserId, PriorityId = priorityId, ServiceTypeId = 1, StudentId = 6, SubjectId = 2, FulfillmentDetails = new List<ServiceRequestFulfillment> { newServiceRequestFulfillment } }; context.ServiceRequests.Add(newRequestToEdit); context.SaveChanges(); return newRequestToEdit; } }
public void WhenConstruct_ThenCreateTimeSet() { ServiceRequest actual = new ServiceRequest(); Assert.IsTrue(actual.CreateTime.WithinTimeSpanOf(TimeSpan.FromMilliseconds(20), DateTime.Now)); }
public void Create(EducationSecurityPrincipal user, ServiceRequestModel viewModel) { if (user == null) { throw new ArgumentNullException("user"); } if (viewModel == null) { throw new ArgumentNullException("viewModel"); } IPermission permission = PermissionFactory.Current.Create("CreateServiceRequest", StudentRepository.Items.Include(s => s.School.UserRoles).Where(s => viewModel.StudentIds.Contains(s.Id))); permission.GrantAccess(user); List<int> studentIds = viewModel.StudentIds.ToList(); foreach (int studentId in studentIds) { ServiceRequest request = new ServiceRequest(); viewModel.CopyTo(request); request.StudentId = studentId; request.CreatingUser = user.Identity.User; request.CreatingUserId = user.Identity.User.Id; CreateFulfillmentDetail(request, user, viewModel); ServiceRequestRepository.Add(request); } RepositoryContainer.Save(); }
private void UpdateCurrentFulfillmentDetail(ServiceRequest model, ServiceRequestModel viewModel) { var currentFulfillment = ServiceRequestFulfillmentRepository.Items.OrderByDescending(s => s.CreateTime).FirstOrDefault(s => s.ServiceRequestId == model.Id); if (currentFulfillment != null) { currentFulfillment.FulfilledById = viewModel.SelectedAssignedOfferingId; ServiceRequestFulfillmentRepository.Update(currentFulfillment); } }
public void GivenValidModel_WhenCopyTo_ThenFieldsAreIdentical() { ServiceRequest expected = TestData.ServiceRequests[0]; ServiceRequest actual = new ServiceRequest(); Target.CopyFrom(expected); Target.CopyTo(actual); Assert.AreEqual(expected.PriorityId, actual.PriorityId); Assert.AreEqual(expected.SubjectId, actual.SubjectId); Assert.AreEqual(expected.ServiceTypeId, actual.ServiceTypeId); Assert.AreEqual(expected.Notes, actual.Notes); }
public void GivenUserIsSiteCoordinator_AndDidntCreateRequest_AndServiceTypeIsntPrivate_AndUserAssociatedWithSchool_WhenGrantAccess_ThenSucceed() { var entity = new ServiceRequest { CreatingUserId = 2, ServiceType = new ServiceType { IsPrivate = false }, Student = new Student { School = new School { UserRoles = new List<UserRole> { new UserRole { UserId = 1 } } } } }; ManageServiceRequestPermission target = new ManageServiceRequestPermission(entity); EducationSecurityPrincipal user = CreateSiteCoordinatorUser(new[] { entity.Student.School }); target.GrantAccess(user); }