public void GivenAServiceType_WhenRemove_ThenRemoveFromContext()
        {
            var item = new ServiceType { Id = 1 };

            Target.Remove(item);

            MockDbSet.AssertWasCalled(m => m.Remove(item));
        }
        public void GivenAServiceType_WhenAdd_ThenAddToContext()
        {
            var expected = new ServiceType { Id = 1 };

            Target.Add(expected);

            MockDbSet.AssertWasCalled(m => m.Add(expected));
        }
        public void GivenAnUnassociatedServiceTypeAndCategory_WhenAddLink_ThenTheyAreAssociated()
        {
            ServiceType serviceType = new ServiceType();
            Category category = new Category();

            Target.AddLink(serviceType, category);

            CollectionAssert.Contains(serviceType.Categories.ToList(), category);
            CollectionAssert.Contains(category.ServiceTypes.ToList(), serviceType);
        }
        public void GivenAnAssociatedServiceTypeAndCategory_WhenDeleteLink_TheyAreNoLongerAssociated()
        {
            ServiceType serviceType = new ServiceType();
            Category category = new Category { ServiceTypes = new List<ServiceType> { serviceType } };
            serviceType.Categories.Add(category);

            Target.DeleteLink(serviceType, category);

            CollectionAssert.DoesNotContain(serviceType.Categories.ToList(), category);
            CollectionAssert.DoesNotContain(category.ServiceTypes.ToList(), serviceType);
        }
 public void DeleteLink(ServiceType serviceType, Category category)
 {
     if (serviceType == null)
     {
         throw new ArgumentNullException("serviceType");
     }
     if (category == null)
     {
         throw new ArgumentNullException("category");
     }
     serviceType.Categories.Remove(category);
     category.ServiceTypes.Remove(serviceType);
 }
        public void GivenServiceType_WhenInvokeDataSelector_ThenReturnObjectWithServiceTypeState()
        {
            string expectedName = "Basic Needs";
            bool expectedIsPrivate = true;
            string expectedDescription = "This is a test service type.";
            ServiceType type = new ServiceType
            {
                Name = expectedName,
                IsPrivate = expectedIsPrivate,
                Description = expectedDescription
            };
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

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

            Assert.AreEqual(expectedName, actual.Name);
            Assert.AreEqual(expectedIsPrivate, actual.IsPrivate);
            Assert.AreEqual(expectedDescription, actual.Description);
        }
        public void GivenServiceType_AndUserIsNotAdministrator_WhenInvokeDataSelector_ThenIsEditableFalse()
        {
            ServiceType type = new ServiceType();
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

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

            Assert.IsFalse(actual.IsEditable);
        }
        public void GivenServiceType_AndUserIsAdministrator_WhenInvokeDataSelector_ThenIsEditableTrue()
        {
            User.Identity.User.UserRoles.Add(new UserRole { Role = new Role { Name = SecurityRoles.DataAdmin } });
            ServiceType type = new ServiceType();
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

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

            Assert.IsTrue(actual.IsEditable);
        }
        public void GivenServiceType_AndSortOnSecondColumn_WhenInvokeSortSelector_ThenReturnName()
        {
            string expected = "Basic Needs";
            ServiceType type = new ServiceType { Name = expected };
            PrepareDataTableRequestParameters("1");
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.AreEqual(expected, Target.SortSelector.Compile().Invoke(type));
        }
        public void GivenServiceType_AndSortOnFourthColumn_WhenInvokeSortSelector_ThenReturnDescription()
        {
            string expected = "This is the string to be sorted on";
            ServiceType type = new ServiceType { Description = expected };
            PrepareDataTableRequestParameters("3");
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.AreEqual(expected, Target.SortSelector.Compile().Invoke(type));
        }
        public void GivenNullCategory_WhenDeleteLink_ThenThrowException()
        {
            ServiceType serviceType = new ServiceType();

            Target.ExpectException<ArgumentNullException>(() => Target.DeleteLink(serviceType, null));
        }
        public void GivenServiceTypeNameSearchCriteria_AndServiceTypeDoesNotContainSearchCriteria_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            string searchCriteria = "Basic";
            ServiceType type = new ServiceType { Name = "Student Needs" };
            MockRequestParameter("ServiceTypeName", searchCriteria);
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.IsFalse(Target.FilterPredicate.Compile().Invoke(type));
        }
 public void Create(ServiceTypeModel viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     ServiceType item = new ServiceType { IsActive = true };
     viewModel.CopyTo(item);
     if (ServiceTypeRepository.Items.Any(s => s.Name == item.Name && !s.IsActive))
     {
         item = ServiceTypeRepository.Items.Include("ServiceOfferings.Program.Schools").Single(s => s.Name == item.Name);
         item.IsActive = true;
     }
     else
     {
         ServiceTypeRepository.Add(item);
     }
     UpdateTypeCategories(viewModel.SelectedCategories, item);
     UpdateServiceTypePrograms(viewModel.SelectedPrograms, item);
     RepositoryContainer.Save();
 }
        public void GivenServiceTypeInactive_WhenInvokeFilterPredicate_ThenReturnFalse()
        {
            ServiceType type = new ServiceType();
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.IsFalse(Target.FilterPredicate.Compile().Invoke(type));
        }
        public void GivenServiceTypeNameSearchCriteria_AndServiceTypeContainsSearchCriteria_AndCaseMismatched_WhenInvokeFilterPredicate_ThenReturnTrue()
        {
            string searchCriteria = "BaSiC";
            ServiceType type = new ServiceType { Name = "Student " + searchCriteria.ToUpper() + " Needs", IsActive = true };
            MockRequestParameter("ServiceTypeName", searchCriteria);
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(type));
        }
        public void GivenNoServiceTypeNameSearchCriteria_WhenInvokeFilterPredicate_ThenReturnTrue()
        {
            ServiceType type = new ServiceType { IsActive = true };
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.IsTrue(Target.FilterPredicate.Compile().Invoke(type));
        }
 public void Update(ServiceType item)
 {
     Context.SetModified(item);
 }
 public void Remove(ServiceType item)
 {
     Context.ServiceTypes.Remove(item);
 }
 private static List<string> FindServicesOfferingNames(Student data, ServiceType serviceType)
 {
     return data.StudentAssignedOfferings.
         Where(s => s.ServiceOffering.ServiceType == serviceType && s.IsActive).
         Select(o => o.ServiceOffering.Name).ToList();
 }
 private void UpdateTypeCategories(IEnumerable<int> SelectedCategories, ServiceType serviceType)
 {
     List<Category> selectedCategories = (SelectedCategories == null || !SelectedCategories.Any()) ?
                                             new List<Category>() :
                                             CategoryRepository.Items.Where(s => SelectedCategories.Contains(s.Id)).ToList();
     IEnumerable<Category> categorySet = selectedCategories.Union(serviceType.Categories.ToArray());
     foreach (Category category in categorySet)
     {
         if (!selectedCategories.Contains(category))
         {
             ServiceTypeRepository.DeleteLink(serviceType, category);
         }
         else if (!serviceType.Categories.Contains(category))
         {
             ServiceTypeRepository.AddLink(serviceType, category);
         }
     }
 }
        public void GivenANewServiceType_WhenSaveChanges_ThenNewServiceTypeIsSaved()
        {
            ServiceType serviceType = new ServiceType
            {
                Name = "Bob",
                Description = "Bob's Description",
            };
            Target.ServiceTypes.Add(serviceType);

            Target.SaveChanges();

            var secondaryClient = new EducationDataContext();
            var actual = secondaryClient.ServiceTypes.Where(s => s.Name == "Bob").SingleOrDefault();
            Assert.IsNotNull(actual);
        }
 private void UpdateServiceTypePrograms(IEnumerable<int> selectedProgramIds, ServiceType serviceType)
 {
     List<Program> selectedPrograms = selectedProgramIds == null || !selectedProgramIds.Any() ? new List<Program>() : ProgramRepository.Items.Include(p => p.ServiceOfferings).Where(p => selectedProgramIds.Contains(p.Id)).ToList();
     IEnumerable<ServiceOffering> serviceOfferingSet = ServiceOfferingRepository.Items.Include(s => s.Program.ServiceOfferings).Where(s => s.ServiceTypeId == serviceType.Id);
     foreach (Program program in selectedPrograms)
     {
         CreateServiceOfferings(program, serviceType);
     }
     RemoveServiceOfferings(selectedPrograms, serviceOfferingSet);
     DeactivatePrograms(serviceType.ServiceOfferings.Select(s => s.Program).Distinct().ToList());
 }
        public void GivenServiceType_AndNoSortInformation_WhenInvokeSortSelector_ThenReturnName()
        {
            string expected = "Basic Needs";
            ServiceType type = new ServiceType { Name = expected };
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.AreEqual(expected, Target.SortSelector.Compile().Invoke(type));
        }
 public void Add(ServiceType item)
 {
     Context.ServiceTypes.Add(item);
 }
        public void GivenServiceType_AndServiceTypeHasServiceOfferingsWithPrograms_WhenInvokeDataSelector_ThenReturnObjectHasProgramNames()
        {
            string[] expected = new[] { "Apple Picking", "Youth Group", "After School Tutoring" };
            ServiceType type = new ServiceType
            {
                ServiceOfferings = expected.Select(name => new ServiceOffering { Program = new Program { Name = name, IsActive = true }, IsActive = true }).ToList()
            };
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

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

            CollectionAssert.AreEqual(expected, ((IEnumerable<string>)actual.Programs).ToList());
        }
        public void GivenServiceType_AndSortOnFirstColumn_WhenInvokeSortSelector_ThenReturnIsPrivate()
        {
            bool expected = true;
            ServiceType type = new ServiceType { IsPrivate = expected };
            PrepareDataTableRequestParameters("0");
            Target = new ServiceTypeClientDataTable(MockContext.Request, User);

            Assert.AreEqual(expected.ToString(), Target.SortSelector.Compile().Invoke(type));
        }
        public void GivenAServiceType_WhenUpdate_ThenContextSetsModified()
        {
            var expected = new ServiceType { Id = 1 };

            Target.Update(expected);

            MockContext.AssertWasCalled(m => m.SetModified(expected));
        }
 private void CreateServiceOfferings(Program program, ServiceType serviceType)
 {
     foreach (int providerId in program.ServiceOfferings.Select(s => s.ProviderId).Distinct().ToArray())
     {
         if (!serviceType.ServiceOfferings.Any(o => o.Program == program && o.ProviderId == providerId))
         {
             ServiceOffering newOffering = new ServiceOffering
             {
                 IsActive = true,
                 ServiceType = serviceType,
                 Program = program,
                 ProgramId = program.Id,
                 ProviderId = providerId
             };
             serviceType.ServiceOfferings.Add(newOffering);
             ServiceOfferingRepository.Add(newOffering);
         }
         else if (serviceType.ServiceOfferings.Any(o => o.Program == program && o.ProviderId == providerId && !o.IsActive))
         {
             serviceType.ServiceOfferings.Single(o => o.Program == program && o.ProviderId == providerId && !o.IsActive).IsActive = true;
         }
     }
 }