public Dictionary<int, Dictionary<string, IList<SimpleAreaData>>> GetAreaData()
        {
            var areaListBuilder = new AreaListProvider(ReaderFactory.GetAreasReader());
            areaListBuilder.CreateAreaListFromAreaCodes(_parameters.AreaCodes);
            var areas = areaListBuilder.Areas;

            Dictionary<int, Dictionary<string, IList<SimpleAreaData>>> groupIdToData =
                new Dictionary<int, Dictionary<string, IList<SimpleAreaData>>>();

            foreach (var groupId in _parameters.GroupIds)
            {
                Dictionary<string, IList<SimpleAreaData>> data = new AreaDataBuilder
                {
                    GroupId = groupId,
                    Areas = areas,
                    AreaTypeId = _parameters.AreaTypeId,
                    ComparatorAreaCodes = _parameters.ComparatorAreaCodes,
                    IncludeTimePeriods = _parameters.IncludeTimePeriods,
                    LatestDataOnly = _parameters.LatestDataOnly
                }.Build();
                groupIdToData.Add(groupId, data);
            }

            return groupIdToData;
        }
 public ChildAreaListForCategoryAreaBuilder(IAreasReader reader, CategoryArea parentArea, int childAreaType)
 {
     var areaCodes = reader
         .GetCategorisedAreasForOneCategory(AreaTypeIds.Country, childAreaType, parentArea.CategoryTypeId, parentArea.CategoryId)
         .Select(x => x.AreaCode);
     var areaListBuilder = new AreaListProvider(reader);
     areaListBuilder.CreateAreaListFromAreaCodes(areaCodes);
     ChildAreas = areaListBuilder.Areas.OrderBy(x=> x.Name).ToList();
 }
 private IList<IArea> GetParentAreas()
 {
     var listBuilder = new AreaListProvider(areasReader);
     if (Area.IsNearestNeighbour(_parameters.NearestNeighbourCode))
     {
         listBuilder.CreateAreaListFromNearestNeighbourAreaCode(_parameters.ProfileId, _parameters.NearestNeighbourCode);
     }
     else
     {
         listBuilder.CreateAreaListFromAreaTypeId(_parameters.ProfileId, _parameters.ParentAreaTypeId);
     }
     return listBuilder.Areas;
 }
        public void CreateAreaListFromAreaTypeIdReturnsParentAreas()
        {
            IList<string> codes = new List<string> { "a", "b" };
            var areas = AreaList();

            var mockAreasReader = new Mock<AreasReader>();
            ParentAreaCodesAreFound(codes, mockAreasReader);
            AreasGotFromCodes(codes, areas, mockAreasReader);

            var builder = new AreaListProvider(mockAreasReader.Object);
            builder.CreateAreaListFromAreaTypeId(profileId, areaTypeId);
            var areaList = builder.Areas;
            Assert.AreEqual(3, areaList.Count);
        }
        public void CreateAreaListFromAreaTypeIdWhereCategoryAreaType()
        {
            var categoryAreaType = CategoryAreaType.New(new CategoryType
            {
                Id = CategoryTypeIds.DeprivationDecileCountyAndUA2010
            });
            var builder = new AreaListProvider(ReaderFactory.GetAreasReader());
            builder.CreateAreaListFromAreaTypeId(profileId, categoryAreaType.Id);
            var areaList = builder.Areas;
            Assert.IsTrue(areaList.Any());

            // Check names are defined
            Assert.IsFalse(string.IsNullOrEmpty(areaList.First().Name));
            Assert.IsFalse(string.IsNullOrEmpty(areaList.First().ShortName));
        }
        public IList<IArea> GetResponse(int areaTypeId, int profileId,
            int templateProfileId, bool retrieveIgnoredAreas)
        {
            _areaListProvider = new AreaListProvider(areasReader);
            _areaListProvider.CreateAreaListFromAreaTypeId(profileId, areaTypeId);

            // Remove ignored areas
            if (retrieveIgnoredAreas == false)
            {
                var nonSearchProfileId = ActionHelper.GetNonSearchProfileId(profileId, templateProfileId);
                var ignoredAreasFilter = IgnoredAreasFilterFactory.New(nonSearchProfileId);
                _areaListProvider.RemoveAreasIgnoredEverywhere(ignoredAreasFilter);
            }

            _areaListProvider.SortByOrderOrName();
            return _areaListProvider.Areas;
        }
        public void TestCreateAreaListFromNearestNeighbourAreaCode()
        {
            const string code = AreaCodes.NearestNeighbours_Derby;
            var nn = new NearestNeighbourArea(code);
            IAreasReader areasReader = ReaderFactory.GetAreasReader();

            var builder = new AreaListProvider(areasReader);
            builder.CreateAreaListFromNearestNeighbourAreaCode(
                ProfileIds.ChildrenAndYoungPeoplesBenchmarkingTool, code);

            // Check areas
            var areas = builder.Areas;
            Assert.IsNotNull(areas);

            // Check order of Nearest Neighbours
            var sortedNearestNeighboursByRank = areasReader.GetNearestNeighbours(nn.Code, 1);
            for (var i = 0; i < sortedNearestNeighboursByRank.Count; i++)
            {
                Assert.AreEqual(sortedNearestNeighboursByRank[i].NeighbourAreaCode, areas[i].Code);
            }
        }
 public IList<IArea> GetAreasOfAreaType(string area_codes)
 {
     try
     {
         var codes = new StringListParser(area_codes).StringList;
         var areaListBuilder = new AreaListProvider(ReaderFactory.GetAreasReader());
         areaListBuilder.CreateAreaListFromAreaCodes(codes);
         return areaListBuilder.Areas;
     }
     catch (Exception ex)
     {
         Log(ex);
         throw;
     }
 }
 public ParentChildAreaRelationshipBuilder(IgnoredAreasFilter ignoredAreasFilter,
     AreaListProvider _areaListProvider)
 {
     this.ignoredAreasFilter = ignoredAreasFilter;
     this._areaListProvider = _areaListProvider;
 }
        public void TestGetAreaListFromAreaCodes()
        {
            const string code = "a";

            var codes = new[] { code };

            var mock = new Mock<AreasReader>();
            mock.Setup(x => x
                .GetAreaFromCode(code))
                .Returns(new Area { Code = code });
            var builder = new AreaListProvider(mock.Object);

            builder.CreateAreaListFromAreaCodes(codes);
            var areas = builder.Areas;
            Assert.AreEqual(1, areas.Count);
            Assert.AreEqual(code, areas.First().Code);
        }
        private AreaListProvider CreateAreaListFromAreaTypeId(List<Area> areas)
        {
            var mockAreasReader = new Mock<AreasReader>();
            GetAreasByAreaTypeIdReturnsAreas(areas, mockAreasReader);
            NoParentAreaCodes(mockAreasReader);

            var builder = new AreaListProvider(mockAreasReader.Object);
            builder.CreateAreaListFromAreaTypeId(profileId, areaTypeId);
            return builder;
        }
        public void TestGetAreaListFromAreaCodesReturnEmptyListForIfAreaCodes()
        {
            var codes = new string[] { };

            var mock = new Mock<AreasReader>();
            mock.Setup(x => x
                .GetAreasFromCodes(codes))
                .Returns(new List<Area>());

            var builder = new AreaListProvider(mock.Object);

            builder.CreateAreaListFromAreaCodes(codes);
            Assert.AreEqual(0, builder.Areas.Count);
        }