public void GivenAProvider_WhenRemove_ThenRemoveFromContext() { var item = new Provider { Id = 1 }; Target.Remove(item); MockDbSet.AssertWasCalled(m => m.Remove(item)); }
public void GivenAProvider_WhenUpdate_ThenContextSetsModified() { var expected = new Provider { Id = 1 }; Target.Update(expected); MockContext.AssertWasCalled(m => m.SetModified(expected)); }
public void GivenAProvider_WhenAdd_ThenAddToContext() { var expected = new Provider { Id = 1 }; Target.Add(expected); MockDbSet.AssertWasCalled(m => m.Add(expected)); }
public void GivenAnUnassociatedStudentAndProvider_WhenAddLink_ThenTheyAreAssociated() { Student student = new Student(); Provider provider = new Provider(); Target.AddLink(student, provider); CollectionAssert.Contains(student.ApprovedProviders.ToList(), provider); CollectionAssert.Contains(provider.ApprovingStudents.ToList(), student); }
public void GivenAnUnassociatedUserRoleAndProvider_WhenAddLink_ThenTheyAreAssociated() { UserRole userRole = new UserRole(); Provider provider = new Provider(); Target.AddLink(userRole, provider); CollectionAssert.Contains(userRole.Providers.ToList(), provider); CollectionAssert.Contains(provider.UserRoles.ToList(), userRole); }
public void GivenAnAssociatedStudentAndProvider_WhenDeleteLink_ThenTheyAreNoLongerAssociated() { Student student = new Student(); Provider provider = new Provider { ApprovingStudents = new List<Student> { student } }; student.ApprovedProviders.Add(provider); Target.DeleteLink(student, provider); CollectionAssert.DoesNotContain(student.ApprovedProviders.ToList(), provider); CollectionAssert.DoesNotContain(provider.ApprovingStudents.ToList(), student); }
public void GivenAnAssociatedUserRoleAndProvider_WhenDeleteLink_ThenTheyAreNoLongerAssociated() { UserRole userRole = new UserRole(); Provider provider = new Provider { UserRoles = new List<UserRole> { userRole } }; userRole.Providers.Add(provider); Target.DeleteLink(userRole, provider); CollectionAssert.DoesNotContain(userRole.Providers.ToList(), provider); CollectionAssert.DoesNotContain(provider.UserRoles.ToList(), userRole); }
public void DeleteLink(Student student, Provider provider) { if (student == null) { throw new ArgumentNullException("student"); } if (provider == null) { throw new ArgumentNullException("provider"); } student.ApprovedProviders.Remove(provider); provider.ApprovingStudents.Remove(student); }
public void GivenNameCriteria_AndProviderNameMatches_WhenExecuteFilterPredicate_ThenReturnTrue() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider provider = new Provider { Name = "provider", IsActive = true }; MockRequest.Expect(m => m["PartnerName"]).Return("pro"); ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); Assert.IsTrue(target.FilterPredicate.Compile().Invoke(provider)); }
public void DeleteLink(UserRole userRole, Provider provider) { if (userRole == null) { throw new ArgumentNullException("userRole"); } if (provider == null) { throw new ArgumentNullException("provider"); } userRole.Providers.Remove(provider); provider.UserRoles.Remove(userRole); }
public void GivenServiceOffering_AndUserIsProvider_AndUserIsAssignedProvider_WhenInvokeDataSelector_ThenDataCanInteractTrue() { Provider matchingProvider = new Provider(); ServiceOffering offering = new ServiceOffering { Provider = matchingProvider, ServiceType = new ServiceType(), Program = new Program() }; CurrentUser.Identity.User.UserRoles.Add(new UserRole { Role = new Role { Name = SecurityRoles.Provider }, Providers = new[] { matchingProvider } }); ServiceOfferingClientDataTable target = new ServiceOfferingClientDataTable(MockRequest, CurrentUser); dynamic actual = target.DataSelector.Compile().Invoke(offering); Assert.AreEqual(true, actual.CanInteract); }
public void GivenNameCriteria_AndProviderAssociatedWithProgramWithMatchingName_WhenExecuteFilterPredicate_ThenReturnTrue() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider provider = new Provider { Name = "not the search criteria", IsActive = true, ServiceOfferings = new List<ServiceOffering> { new ServiceOffering { Program = new Program { Name = "contains bLah criteria" } } } }; MockRequest.Expect(m => m["PartnerName"]).Return("blah"); ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); Assert.IsTrue(target.FilterPredicate.Compile().Invoke(provider)); }
public void GivenProviderWithServiceOfferingsWithPrograms_WhenDelete_ThenAssociatedServiceOfferingsDeactivated() { Data.ServiceTypes.Clear(); Data.StudentAssignedOfferings.Clear(); Data.ServiceTypes.AddRange(new List<ServiceType> { new ServiceType { Name = "A" }, new ServiceType { Name = "B" } }); Data.Programs.Clear(); Data.Programs.AddRange(new List<Program> { new Program { Name = "A" }, new Program { Name = "B" } }); Provider toDelete = new Provider { Id = 1, IsActive = true, ServiceOfferings = new List<ServiceOffering> { new ServiceOffering { ServiceType = Data.ServiceTypes[0], ServiceTypeId = Data.ServiceTypes[0].Id, Program = Data.Programs[0], ProgramId = Data.Programs[0].Id, ProviderId = 1, IsActive = true }, new ServiceOffering { ServiceType = Data.ServiceTypes[1], ServiceTypeId = Data.ServiceTypes[1].Id, Program = Data.Programs[0], ProgramId = Data.Programs[0].Id, ProviderId = 1, IsActive = true }, new ServiceOffering { ServiceType = Data.ServiceTypes[0], ServiceTypeId = Data.ServiceTypes[0].Id, Program = Data.Programs[1], ProgramId = Data.Programs[1].Id, ProviderId = 1, IsActive = true }, new ServiceOffering { ServiceType = Data.ServiceTypes[1], ServiceTypeId = Data.ServiceTypes[1].Id, Program = Data.Programs[1], ProgramId = Data.Programs[1].Id, ProviderId = 1, IsActive = true } } }; Data.Providers.Clear(); Data.ServiceOfferings.Clear(); Data.Providers.Add(toDelete); Data.ServiceOfferings.AddRange(toDelete.ServiceOfferings); Target.Delete(toDelete.Id); Assert.IsTrue(Data.ServiceOfferings.All(s => !s.IsActive)); }
public void GivenProgramRemovedFromProvider_WhenEdit_ThenAssociatedServiceOfferingsDeactivated() { Data.ServiceTypes.Clear(); Data.ServiceTypes.AddRange(new List<ServiceType> { new ServiceType { Name = "A" }, new ServiceType { Name = "B" } }); Data.Programs.Clear(); Data.Programs.AddRange(new List<Program> { new Program { Name = "A", Id = 1 }, new Program { Name = "B", Id = 2 } }); Provider toEdit = new Provider { Id = 1, IsActive = true, ServiceOfferings = new List<ServiceOffering> { new ServiceOffering { ServiceType = Data.ServiceTypes[0], Program = Data.Programs[0], ProgramId = Data.Programs[0].Id, IsActive = true, ProviderId = 1 }, new ServiceOffering { ServiceType = Data.ServiceTypes[1], Program = Data.Programs[0], ProgramId = Data.Programs[0].Id, IsActive = true, ProviderId = 1 }, new ServiceOffering { ServiceType = Data.ServiceTypes[0], Program = Data.Programs[1], ProgramId = Data.Programs[1].Id, IsActive = true, ProviderId = 1 }, new ServiceOffering { ServiceType = Data.ServiceTypes[1], Program = Data.Programs[1], ProgramId = Data.Programs[1].Id, IsActive = true, ProviderId = 1 } } }; Data.Providers.Clear(); Data.ServiceOfferings.Clear(); Data.Providers.Add(toEdit); Data.ServiceOfferings.AddRange(toEdit.ServiceOfferings); var viewModel = new ProviderModel { SelectedPrograms = new[] { 1 }, Id = 1 }; PermissionFactory.Current.Expect(m => m.Create("EditProvider", viewModel.Id)).Return(MockRepository.GenerateMock<IPermission>()); Target.Edit(User, viewModel); Assert.IsTrue(Data.ServiceOfferings.Where(s => s.IsActive).All(s => s.ProgramId == 1)); }
public void GivenProvider_AndUserIsNotDataAdmin_AndUserIsAssociatedToProvider_WhenInvokeDataSelector_ThenDataAccessModeIsEdit() { Provider provider = new Provider { Id = 3548 }; EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever", UserRoles = new List<UserRole> { new UserRole { Role = new Role { Name = SecurityRoles.Provider }, Providers = new List<Provider> { provider } } } }); ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(provider); Assert.AreEqual("Edit", actual.AccessMode); }
public void GivenProvider_AndUserIsNotDataAdmin_AndUserNotAssociatedToProvider_WhenInvokeDataSelector_ThenDataAccessModeIsView() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider provider = new Provider(); ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(provider); Assert.AreEqual("View", actual.AccessMode); }
public void GivenNullUserRole_AndProvider_WhenDeleteLink_ThenThrowException() { Provider provider = new Provider(); Target.ExpectException<ArgumentNullException>(() => Target.DeleteLink(null, provider)); }
public void GivenProviderWithApprovingStudents_WhenDelete_ThenNoApprovedProviderMappingsToDeletedProvider() { int toDeleteId; using (EducationDataContext setupContext = new EducationDataContext()) { Provider temp = new Provider { Name = "blah blah blah", IsActive = true, ApprovingStudents = setupContext.Students.ToList() }; foreach (Student student in temp.ApprovingStudents) { student.ApprovedProviders.Add(temp); } setupContext.Providers.Add(temp); setupContext.SaveChanges(); toDeleteId = temp.Id; } Target.Delete(toDeleteId); Assert.IsFalse(EducationContext.Students.Any(s => s.ApprovedProviders.Select(p => p.Id).Contains(toDeleteId))); }
public void GivenProvider_WhenInvokeDataSelector_ThenDataHasNameAndIdAndWebsite() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider expectedState = new Provider { Name = "provider's name", Website = "www.this-is-made-up.com", Id = 482 }; ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(expectedState); Assert.AreEqual(expectedState.Name, actual.Name); Assert.AreEqual(expectedState.Website, actual.Website); Assert.AreEqual(expectedState.Id, actual.Id); }
public void GivenStudent_AndStudentHasApprovedProviders_AndSomeProvidersAreInactive_WhenExecuteDataSelctor_ThenDataContainsActiveApprovedProviderDetail() { Provider expectedState = new Provider { Id = 382, Name = "Blah1", IsActive = true }; Student student = new Student { School = new School(), ApprovedProviders = new List<Provider> { expectedState, new Provider { Id = 289, Name = "Grapejuice" } } }; StudentApprovalClientDataTable target = new StudentApprovalClientDataTable(MockRequest); dynamic actual = target.DataSelector.Compile().Invoke(student); dynamic actualApprovedProvider = ((IEnumerable<object>)actual.ApprovedProviders).Single(); Assert.AreEqual(expectedState.Id, actualApprovedProvider.Id); Assert.AreEqual(expectedState.Name, actualApprovedProvider.Name); }
public void GivenProvider_AndUserIsDataAdmin_WhenInvokeDataSelector_ThenDataAccessModeIsAll() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever", UserRoles = new List<UserRole> { new UserRole { Role = new Role { Name = SecurityRoles.DataAdmin } } } }); Provider provider = new Provider(); ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(provider); Assert.AreEqual("All", actual.AccessMode); }
public void Remove(Provider item) { Context.Providers.Remove(item); }
public void GivenProvider_WhenInvokeDataSelector_ThenDataHasAddress() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider expectedState = new Provider { Address = new Address { City = "Cbus", State = "OH", Street = "123 Main St.", Zip = "44444" } }; ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(expectedState); Assert.AreEqual(expectedState.Address.City, actual.Address.City); Assert.AreEqual(expectedState.Address.State, actual.Address.State); Assert.AreEqual(expectedState.Address.Street, actual.Address.Street); Assert.AreEqual(expectedState.Address.Zip, actual.Address.Zip); }
public void GivenProvider_WhenInvokeDataSelector_ThenDataHasContact() { EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider expectedState = new Provider { Contact = new Contact { Email = "*****@*****.**", Name = "Bob", Phone = "555-444-1234" } }; ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(expectedState); Assert.AreEqual(expectedState.Contact.Email, actual.Contact.Email); Assert.AreEqual(expectedState.Contact.Name, actual.Contact.Name); Assert.AreEqual(expectedState.Contact.Phone, actual.Contact.Phone); }
public void GivenNullStudent_WhenAddLink_ThenThrowException() { Provider provider = new Provider(); Target.ExpectException<ArgumentNullException>(() => Target.AddLink(null, provider)); }
private static bool AssertPropertieMatch(ProviderModel expectedState, Provider actualState) { Assert.IsNotNull(actualState); Assert.AreEqual(expectedState.Name, actualState.Name); Assert.AreEqual(expectedState.Website, actualState.Website); Assert.AreEqual(expectedState.Address, actualState.Address); Assert.AreEqual(expectedState.Contact, actualState.Contact); return true; }
public void Add(Provider item) { Context.Providers.Add(item); }
public void GivenProviderWithUserAssociations_WhenDelete_ThenNoUserAssociationsToDeletedProvider() { int toDeleteId; using (EducationDataContext setupContext = new EducationDataContext()) { Provider temp = new Provider { Name = "halb halb halb", IsActive = true, UserRoles = setupContext.UserRoles.Where(u => u.Role.Name == SecurityRoles.Provider).ToList() }; foreach (UserRole userRole in temp.UserRoles) { userRole.Providers.Add(temp); } setupContext.Providers.Add(temp); setupContext.SaveChanges(); toDeleteId = temp.Id; } Target.Delete(toDeleteId); Assert.IsFalse(EducationContext.UserRoles.Any(u => u.Providers.Select(p => p.Id).Contains(toDeleteId))); }
public void Update(Provider item) { Context.SetModified(item); }
public void GivenProvider_AndProviderHasAssociatedServiceOfferingsWithAProgram_WhenInvokeDataSelector_ThenDataHasAssociatedProgramNames() { string[] expected = new[] { "program 1", "blah", "apples!" }; EducationSecurityPrincipal user = new EducationSecurityPrincipal(new User { UserKey = "whatever" }); Provider expectedState = new Provider { ServiceOfferings = expected.Select(e => new ServiceOffering { IsActive = true, Program = new Program { Name = e, IsActive = true } }).ToList() }; ProviderClientDataTable target = new ProviderClientDataTable(MockRequest, user); dynamic actual = target.DataSelector.Compile().Invoke(expectedState); CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.Programs).ToList()); }