public void Test_Trend_Result_Provided_For_Every_Area()
        {
            // Arrange
            var areaCode1 = AreaCodes.CountyUa_Leicestershire;
            var areaCode2 = AreaCodes.CountyUa_Bexley;

            var mockTrendReader = new Mock<ITrendDataReader>();
            mockTrendReader.Setup(x => x.GetTrendData(It.IsAny<Grouping>(), It.IsAny<string>()))
                .Returns(new List<CoreDataSet> { });

            var areas = new List<IArea>
            {
                new Area { Code = areaCode1},
                new Area { Code = areaCode2}
            };

            var indicatorMetadata = new IndicatorMetadata
            {
                Unit = new Unit { Value = 1 },
                ValueTypeId = ValueTypeId.CrudeRate,
            };

            // Act
            var trendMarkers = new TrendMarkersProvider(mockTrendReader.Object, new TrendMarkerCalculator())
                .GetTrendResults(areas, indicatorMetadata, new Grouping());

            // Assert
            Assert.AreEqual(2, trendMarkers.Count);
            Assert.AreEqual(trendMarkers[areaCode1].Marker, TrendMarker.CannotBeCalculated);
            Assert.AreEqual(trendMarkers[areaCode2].Marker, TrendMarker.CannotBeCalculated);
        }
 public TrendMarkerWriter(ProfileDataWriter profileDataWriter, TrendMarkersProvider trendMarkersProvider, 
     TrendMarkerLabelProvider trendMarkerLabelProvider)
 {
     _profileDataWriter = profileDataWriter;
     _trendMarkersProvider = trendMarkersProvider;
     _trendMarkerLabelProvider = trendMarkerLabelProvider;
 }
        public Dictionary<string, TrendMarkerResult> GetTrendMarkers(string parent_area_code, int group_id,
            int area_type_id, int indicator_id, int sex_id, int age_id)
        {
            try
            {
                // Create dependencies
                var groupDataReader = ReaderFactory.GetGroupDataReader();
                var trendMarkersProvider = new TrendMarkersProvider(ReaderFactory.GetTrendDataReader(), new TrendMarkerCalculator());
                var areaListProvider = new FilteredChildAreaListProvider(ReaderFactory.GetAreasReader());
                var groupIdProvider = new GroupIdProvider(ReaderFactory.GetProfileReader());
                var singleGroupingProvider = new SingleGroupingProvider(groupDataReader, groupIdProvider);
                var groupMetadataList = groupDataReader.GetGroupMetadataList(new List<int> { group_id });
                var profileId = groupMetadataList.First().ProfileId;

                return new TrendMarkersAction(areaListProvider, trendMarkersProvider, singleGroupingProvider)
                    .GetTrendMarkers(parent_area_code, profileId, group_id, area_type_id, indicator_id, sex_id, age_id);
            }
            catch (Exception ex)
            {
                Log(ex);
                throw;
            }
        }
        private void AssignRecentTrends()
        {
            if (GroupData.Areas != null)
            {
                var trendCalculator = new TrendMarkerCalculator();
                var trendReader = ReaderFactory.GetTrendDataReader();
                var trendMarkersProvider = new TrendMarkersProvider(trendReader, trendCalculator);

                var areas = GroupData.Areas.ToList();
                AddParentAreas(areas);

                var metadataCollection = new IndicatorMetadataCollection(GroupData.IndicatorMetadata);
                foreach (var groupRoot in GroupData.GroupRoots)
                {
                    var grouping = groupRoot.Grouping.FirstOrDefault();

                    var indicatorMetaData = metadataCollection.GetIndicatorMetadataById(groupRoot.IndicatorId);

                    var recentTrends = indicatorMetaData == null
                        ? new Dictionary<string, TrendMarkerResult>()
                        : trendMarkersProvider.GetTrendResults(areas, indicatorMetaData, grouping);

                    groupRoot.RecentTrends = recentTrends;
                }
            }
        }
        public static ITrendMarkerWriter New(ProfileDataWriter profileDataWriter, int polarityId, IList<TimePeriod> timePeriods, bool hasTrendMarkers)
        {
            if (hasTrendMarkers && timePeriods.Count >= TrendMarkerCalculator.MinimumNumberOfPoints)
            {
                // Use null for TrendReader as all data will be provided to the provider
                var trendMarkerLabelProvider = new TrendMarkerLabelProvider(polarityId);
                var trendMarkerProvider = new TrendMarkersProvider(null, new TrendMarkerCalculator());
                return new TrendMarkerWriter(profileDataWriter, trendMarkerProvider, trendMarkerLabelProvider);
            }

            return new NullTrendMarkerWriter();
        }