public void TestCreateFilter()
        {
            //setup
            var english = new Framework.Dal.Common.Language(false, 1, "English", true);
            var spanish = new Framework.Dal.Common.Language(false, 2, "Spanish", true);

            var source = new List<ProviderCacheView>();

            var provider = new ProviderCacheView { Id = 1 };
            provider.AddLanguage(english);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 2 };
            provider.AddLanguage(english);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 3 };
            provider.AddLanguage(spanish);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 4 };
            source.Add(provider);

            var builder = new LanguageFilterBuilder();

            //act
            var filter = builder.CreateFilters(source.AsQueryable()).FirstOrDefault();

            //assert
            Assert.IsNotNull(filter);
            Assert.AreEqual(QueryStringKeys.LanguageIdKey, filter.QueryStringParameterName);
            Assert.AreEqual("Language", filter.Name);
            Assert.IsNotNull(filter.FilterValues);
            Assert.AreEqual(2, filter.FilterValues.Count());

            var value = filter.FilterValues.ElementAt(0);
            Assert.AreEqual(english.Name, value.DisplayName);
            Assert.AreEqual(english.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(2, value.Count);

            value = filter.FilterValues.ElementAt(1);
            Assert.AreEqual(spanish.Name, value.DisplayName);
            Assert.AreEqual(spanish.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(1, value.Count);
        }
        public void TestCreateFilter()
        {
            //setup
            var cardio = new Specialty { Name = "Cardiology", Id = 1, SpecialtyType = SpecialtyType.Specialty };
            var oncology = new Specialty { Name = "Oncology", Id = 2, SpecialtyType = SpecialtyType.Specialty };

            var source = new List<ProviderCacheView>();

            var provider = new ProviderCacheView { Id = 1 };
            provider.AddSpecialty(cardio);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 2 };
            provider.AddSpecialty(cardio);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 3 };
            provider.AddSpecialty(oncology);
            source.Add(provider);

            provider = new ProviderCacheView { Id = 4 };
            source.Add(provider);

            var builder = new SpecialtyFilterBuilder();

            //act
            var filter = builder.CreateFilters(source.AsQueryable()).FirstOrDefault();

            //assert
            Assert.IsNotNull(filter);
            Assert.AreEqual(QueryStringKeys.SpecialtyIdKey, filter.QueryStringParameterName);
            Assert.AreEqual("Specialty", filter.Name);
            Assert.IsNotNull(filter.FilterValues);
            Assert.AreEqual(2, filter.FilterValues.Count());

            var value = filter.FilterValues.ElementAt(0);
            Assert.AreEqual(cardio.Name, value.DisplayName);
            Assert.AreEqual(cardio.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(2, value.Count);

            value = filter.FilterValues.ElementAt(1);
            Assert.AreEqual(oncology.Name, value.DisplayName);
            Assert.AreEqual(oncology.Id.ToString(CultureInfo.CurrentCulture), value.QueryStringParameterValue);
            Assert.AreEqual(1, value.Count);
        }
 private static ProviderCacheView CreateProvider(int id)
 {
     var provider = new ProviderCacheView { Id = id, IsEnabled = true };
     return provider;
 }
        public void TestCreateFilter()
        {
            //setup
            var orgUnitTypeLocations = new OrgUnitType
                                            {
                                                Id = 1,
                                                Name = "Locations",
                                                IsEnabled = true,
                                                IsOutsideOfOrganization = false
                                            };

            var orgUnitTypeDepartments = new OrgUnitType
                                              {
                                                  Id = 2,
                                                  Name = "Departments",
                                                  IsEnabled = true,
                                                  IsOutsideOfOrganization = false
                                              };

            // orgUnit
            var orgUnit1 = new OrgUnit
                               {
                                   Id = 1,
                                   Name = "Hospital A"
                               };
            var outa = new List<OrgUnitTypeAssociation>
                           {
                               new OrgUnitTypeAssociation
                                   {
                                       Id = 1,
                                       OrgUnit = orgUnit1,
                                       OrgUnitType = orgUnitTypeLocations
                                   }
                           };
            orgUnit1.OrgUnitTypeAssociations = outa;

            // orgUnit
            var orgUnit2 = new OrgUnit
                               {
                                   Id = 2,
                                   Name = "Department A"
                               };
            outa = new List<OrgUnitTypeAssociation>
                       {
                           new OrgUnitTypeAssociation
                               {
                                   Id = 2,
                                   OrgUnit = orgUnit2,
                                   OrgUnitType = orgUnitTypeDepartments
                               }
                       };
            orgUnit2.OrgUnitTypeAssociations = outa;

            // orgUnit
            var orgUnit3 = new OrgUnit
                               {
                                   Id = 3,
                                   Name = "Hospital B"
                               };
            outa = new List<OrgUnitTypeAssociation>
                       {
                           new OrgUnitTypeAssociation
                               {
                                   Id = 3,
                                   OrgUnit = orgUnit3,
                                   OrgUnitType = orgUnitTypeLocations
                               }
                       };
            orgUnit3.OrgUnitTypeAssociations = outa;

            // orgUnit
            var orgUnit4 = new OrgUnit
                               {
                                   Id = 4,
                                   Name = "Department B"
                               };
            outa = new List<OrgUnitTypeAssociation>
                       {
                           new OrgUnitTypeAssociation
                               {
                                   Id = 4,
                                   OrgUnit = orgUnit4,
                                   OrgUnitType = orgUnitTypeDepartments
                               }
                       };
            orgUnit4.OrgUnitTypeAssociations = outa;

            var source = new List<ProviderCacheView>();

            var provider = new ProviderCacheView { Id = 1 };
            source.AddRange(provider.AddOrgUnit(orgUnit1));
            source.AddRange(provider.AddOrgUnit(orgUnit3));

            provider = new ProviderCacheView { Id = 2 };
            source.AddRange(provider.AddOrgUnit(orgUnit1));
            source.AddRange(provider.AddOrgUnit(orgUnit2));

            provider = new ProviderCacheView { Id = 3 };
            source.AddRange(provider.AddOrgUnit(orgUnit3));
            source.AddRange(provider.AddOrgUnit(orgUnit4));

            provider = new ProviderCacheView { Id = 4 };
            source.AddRange(provider.AddOrgUnit(orgUnit1));
            source.AddRange(provider.AddOrgUnit(orgUnit2));
            source.AddRange(provider.AddOrgUnit(orgUnit3));
            source.AddRange(provider.AddOrgUnit(orgUnit4));

            source.Add(new ProviderCacheView { Id = 5 });

            var builder = new OrgUnitFilterBuilder();

            //act
            var filters = builder.CreateFilters(source.AsQueryable());

            //assert
            Assert.IsNotNull(filters);
            var filterTypes = filters as SearchFilterType[] ?? filters.ToArray();
            Assert.AreEqual(2, filterTypes.Count());

            //locations
            var locationsFilter = filterTypes.Single(f => f.Name == "Locations");
            Assert.AreEqual(2, locationsFilter.FilterValues.Count());
            Assert.AreEqual(3, locationsFilter.FilterValues.ElementAt(0).Count);
            Assert.AreEqual(3, locationsFilter.FilterValues.ElementAt(1).Count);
            Assert.IsNotNullOrEmpty(locationsFilter.FilterValues.ElementAt(0).DisplayName);
            Assert.IsNotNullOrEmpty(locationsFilter.FilterValues.ElementAt(1).DisplayName);

            //departments
            var departmentsFilter = filterTypes.Single(f => f.Name == "Departments");
            Assert.AreEqual(2, departmentsFilter.FilterValues.Count());
            Assert.AreEqual(2, departmentsFilter.FilterValues.ElementAt(0).Count);
            Assert.AreEqual(2, departmentsFilter.FilterValues.ElementAt(1).Count);
            Assert.IsNotNullOrEmpty(departmentsFilter.FilterValues.ElementAt(0).DisplayName);
            Assert.IsNotNullOrEmpty(departmentsFilter.FilterValues.ElementAt(1).DisplayName);
        }