public void GetMetadataTest()
        {
            var lastupdate = DateTime.Now.ToShortDateString();
            Metadata ineMetadata = new Metadata
            {
                Designation = "Indicator 1",
                Abbreviation = "I1",
                TimeDimension = new TimeDimension
                {
                    Code = "T1",
                    Designation = "Time dimension",
                    Abbreviation = "TD",
                    Periods = new List<Period>{
                        new Period { Code= "1", Designation = "2010" }
                    }
                },
                GeoDimension = new INEService.Dimension
                {
                    Code = "Geo1",
                    Designation = "Dimensao geografica",
                    Abbreviation = "DG",
                    ClassificationCode = "00320",
                    LowestClassificationLevel = 2
                },
                Url = "http://nowhere.com",
                IndicatorUrl = "http://nowhere.com",
                DataLastUpdate = lastupdate
            };
            Mock<IINERequesterWrapper> ineMock = new Mock<IINERequesterWrapper>();
            ineMock.Setup(m => m.GetMetadata(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>())).Returns(ineMetadata);

            INEStatisticsProvider target = new INEStatisticsProvider(ineMock.Object, null);
            string indicatorId = "1";
            IndicatorMetadata expected = new IndicatorMetadata
            {
                ID = indicatorId,
                IndicatorName = "Indicator 1",
                IndicatorNameAbbr = "I1",
                Dimensions = new List<ProviderDataContracts.Metadata.Dimension>
                {
                    new ProviderDataContracts.Metadata.Dimension {
                        ID = "1",
                        DimensionType = DimensionType.Temporal,
                        Name = "Time dimension",
                        NameAbbr = "TD",
                        Attributes = new List<DimensionAttribute> {
                            new DimensionAttribute { ID = "1", Name = "2010" }
                        }
                    },
                    new ProviderDataContracts.Metadata.Dimension {
                        ID = "2",
                        DimensionType = DimensionType.Geographic,
                        Name = "Dimensao geografica",
                        NameAbbr = "DG",
                        Attributes = new List<DimensionAttribute> {
                            new HierarchyAttribute {
                                ID = "PT",
                                Name = "Portugal",
                                LazyLoad = true
                            }
                        },
                        AggregationLevels = new List<AggregationLevel>{
                            new AggregationLevel { ID = "NUTS1", Level = 2, Name = "NUTS 1" }
                        }
                    }
                },
                LastUpdate = DateTime.Parse(lastupdate),
                SourceName = "Instituto Nacional de Estatísticas",
                SourceNameAbbr = "INE",
                SourceURL = "http://nowhere.com"
            };
            IndicatorMetadata actual = target.GetMetadata(indicatorId);
            Assert.AreEqual(expected, actual);
        }
        public static void MyClassInitialize(TestContext testContext)
        {
            List<Dimension> dimensions = new List<Dimension> {
                new Dimension {
                    ID = "1",
                    DimensionType = DimensionType.Temporal,
                    Name = "Ano",
                    NameAbbr = "Ano",
                    Attributes = new List<DimensionAttribute> {
                        new DimensionAttribute { ID = "2010", Name = "2010" },
                        new DimensionAttribute { ID = "2011", Name = "2011" }
                    }
                },
                new Dimension {
                    ID = "2",
                    DimensionType = DimensionType.Geographic,
                    Name = "Geografia",
                    NameAbbr = "Geografia",
                    Attributes = new List<DimensionAttribute> {
                        new HierarchyAttribute {
                            ID = "PT",
                            Name = "Portugal",
                            LazyLoad = true
                        }
                    },
                    AggregationLevels = new List<AggregationLevel> {
                        new AggregationLevel { ID = "Districts", Level = 1, Name = "Distritos" },
                        new AggregationLevel { ID = "Municipalities", Level = 2, Name = "Municipios" }
                    }
                },
                new Dimension {
                    ID = "3",
                    DimensionType = DimensionType.Other,
                    Name = "Género",
                    NameAbbr = "Género",
                    Attributes = new List<DimensionAttribute> {
                        new HierarchyAttribute {
                            ID = "all",
                            Name = "Todos",
                            ChildAttributes = new List<DimensionAttribute> {
                                new DimensionAttribute { ID = "M", Name = "Masculino" },
                                new DimensionAttribute { ID = "F", Name = "Feminino" }
                            }
                        }
                    }
                }
            };

            metadata = new IndicatorMetadata
            {
                ID = "1",
                IndicatorName = "Indicator 1",
                IndicatorNameAbbr = "I1",
                LastUpdate = DateTime.Now,
                SourceName = "Test provider",
                SourceNameAbbr = "TP",
                SourceURL = "http://nowhere.com",
                Dimensions = dimensions
            };

            values = new IndicatorValue[] {
                new IndicatorValue {
                    Value = 2,
                    Projected = new DimensionFilter [] {
                        new DimensionFilter { DimensionID = "3", AttributeIDs=new string[]{ "M" } }
                    },
                    Filters = new DimensionFilter[] {
                        new DimensionFilter{ DimensionID = "1", AttributeIDs = new List<string>{ "2010", "2011" } },
                        new DimensionFilter{ DimensionID = "2", AttributeIDs = new List<string>{ "PT" } }
                    }
                },
                new IndicatorValue {
                    Value = 4,
                    Projected = new DimensionFilter[] {
                        new DimensionFilter { DimensionID = "3", AttributeIDs = new string[] { "F" } }
                    },
                    Filters = new DimensionFilter[] {
                        new DimensionFilter{ DimensionID = "1", AttributeIDs = new List<string>{ "2010", "2011" } },
                        new DimensionFilter{ DimensionID = "2", AttributeIDs = new List<string>{ "PT" } }
                    }
                }
            };

            var mock = new Mock<IStatisticsProxyService>();
            mock.Setup(m => m.GetMetadata(It.IsAny<int>(), It.IsAny<int>())).Returns(metadata);
            mock.Setup(m => m.GetIndicatorValues(
                It.IsAny<int>(),
                It.IsAny<int>(),
                It.IsAny<IEnumerable<DimensionFilter>>(),
                It.IsAny<IEnumerable<DimensionFilter>>())
            ).Returns(new IndicatorValues { Values = values });

            serviceImplementation = mock.Object;
        }
        private static Mock<IStatisticsRequestStrategy> GetRequestStrategyMock()
        {
            List<Dimension> dimensions = new List<Dimension> {
                new Dimension {
                    ID = "1",
                    DimensionType = DimensionType.Temporal,
                    Name = "Ano",
                    NameAbbr = "Ano",
                    Attributes = new List<DimensionAttribute> {
                        new DimensionAttribute { ID = "2010", Name = "2010" },
                        new DimensionAttribute { ID = "2011", Name = "2011" }
                    }
                },
                new Dimension {
                    ID = "2",
                    DimensionType = DimensionType.Geographic,
                    Name = "Geografia",
                    NameAbbr = "Geografia",
                    Attributes = new List<DimensionAttribute> {
                        new HierarchyAttribute {
                            ID = "PT",
                            Name = "Portugal",
                            LazyLoad = true
                        }
                    },
                    AggregationLevels = new List<AggregationLevel> {
                        new AggregationLevel { ID = "Districts", Level = 1, Name = "Distritos" },
                        new AggregationLevel { ID = "Municipalities", Level = 2, Name = "Municipios" }
                    }
                },
                new Dimension {
                    ID = "3",
                    DimensionType = DimensionType.Other,
                    Name = "Género",
                    NameAbbr = "Género",
                    Attributes = new List<DimensionAttribute> {
                        new HierarchyAttribute {
                            ID = "all",
                            Name = "Todos",
                            ChildAttributes = new List<DimensionAttribute> {
                                new DimensionAttribute { ID = "M", Name = "Masculino" },
                                new DimensionAttribute { ID = "F", Name = "Feminino" }
                            }
                        }
                    }
                }
            };

            metadata = new IndicatorMetadata
            {
                ID = "1",
                IndicatorName = "Indicator 1",
                IndicatorNameAbbr = "I1",
                LastUpdate = DateTime.Now,
                SourceName = "Test provider",
                SourceNameAbbr = "TP",
                SourceURL = "http://nowhere.com",
                Dimensions = dimensions
            };

            values = new IndicatorValue[] {
                new IndicatorValue {
                    Value = 2,
                    Projected = new DimensionFilter[] {
                        new DimensionFilter { DimensionID = "3", AttributeIDs = new string[] { "M" } }
                    },
                    Filters = new DimensionFilter[] {
                        new DimensionFilter{ DimensionID = "1", AttributeIDs = new List<string>{ "2010", "2011" } },
                        new DimensionFilter{ DimensionID = "2", AttributeIDs = new List<string>{ "PT" } }
                    }
                },
                new IndicatorValue {
                    Value = 4,
                    Projected = new DimensionFilter[] {
                        new DimensionFilter { DimensionID = "3", AttributeIDs = new string[] { "F" } }
                    },
                    Filters = new DimensionFilter[] {
                        new DimensionFilter{ DimensionID = "1", AttributeIDs = new List<string>{ "2010", "2011" } },
                        new DimensionFilter{ DimensionID = "2", AttributeIDs = new List<string>{ "PT" } }
                    }
                }
            };

            var requesterMock = new Mock<IStatisticsRequestStrategy>();
            requesterMock.Setup(m => m.GetMetadata(It.IsAny<string>())).Returns(metadata);
            requesterMock.Setup(m => m.GetValues(It.IsAny<string>(), It.IsAny<IEnumerable<DimensionFilter>>(), It.IsAny<IEnumerable<DimensionFilter>>())).Returns(values);

            return requesterMock;
        }
        public void ToIndicatorMetadataTest()
        {
            var lastupdate = DateTime.Now.ToShortDateString();

            Metadata metadata = new Metadata
            {
                Designation = "Indicator 1",
                Abbreviation = "I1",
                TimeDimension = new TimeDimension {
                    Code = "T1",
                    Designation = "Time dimension",
                    Abbreviation = "TD",
                    Periods = new List<Period>{
                        new Period { Code= "1", Designation = "2010" }
                    }
                },
                GeoDimension = new INEService.Dimension {
                    Code = "Geo1",
                    Designation = "Dimensao geografica",
                    Abbreviation = "DG",
                    ClassificationCode = "00320",
                    LowestClassificationLevel = 2
                },
                Url = "http://nowhere.com",
                IndicatorUrl = "http://nowhere.com",
                DataLastUpdate = lastupdate
            };
            string indicatorId = "1";
            IndicatorMetadata expected = new IndicatorMetadata
            {
                ID = indicatorId,
                IndicatorName = "Indicator 1",
                IndicatorNameAbbr = "I1",
                Dimensions = new List<ProviderDataContracts.Metadata.Dimension>
                {
                    new ProviderDataContracts.Metadata.Dimension {
                        ID = "1",
                        DimensionType = DimensionType.Temporal,
                        Name = "Time dimension",
                        NameAbbr = "TD",
                        Attributes = new List<DimensionAttribute> {
                            new DimensionAttribute { ID = "1", Name = "2010" }
                        }
                    },
                    new ProviderDataContracts.Metadata.Dimension {
                        ID = "2",
                        DimensionType = DimensionType.Geographic,
                        Name = "Dimensao geografica",
                        NameAbbr = "DG",
                        Attributes = new List<DimensionAttribute> {
                            new HierarchyAttribute {
                                ID = "PT",
                                Name = "Portugal",
                                LazyLoad = true
                            }
                        },
                        AggregationLevels = new List<AggregationLevel>{
                            new AggregationLevel { ID = "NUTS1", Level = 2, Name = "NUTS 1" }
                        }
                    }
                },
                LastUpdate = DateTime.Parse(lastupdate),
                SourceName = "Instituto Nacional de Estatísticas",
                SourceNameAbbr = "INE",
                SourceURL = "http://nowhere.com"
            };
            IndicatorMetadata actual = MetadataExtensions.ToIndicatorMetadata(metadata, indicatorId);
            Assert.AreEqual(expected, actual);
        }