Пример #1
0
        public void ConvertToElection()
        {
            var t_Converter = new ElectionParticipationConverter();
            var t_DTO       = new ElectionParticipationResult
            {
                data = new Data[]
                {
                    new Data {
                        key = new string[] { "00", "1900" }, values = new string[] { "90.0" }
                    },
                    new Data {
                        key = new string[] { "01", "1900" }, values = new string[] { "50.0" }
                    }
                }
            };

            var t_Elections = t_Converter.Convert(t_DTO);

            Assert.IsTrue(t_Elections.Length == 1);
            Assert.IsTrue(t_Elections[0].Results.Count == 2);
            Assert.AreEqual(1900, t_Elections[0].Year.Value);

            Assert.AreEqual(0, t_Elections[0].Results[0].Region.Code);
            Assert.AreEqual(0.9m, t_Elections[0].Results[0].Participation.Value.Value);

            Assert.AreEqual(1, t_Elections[0].Results[1].Region.Code);
            Assert.AreEqual(0.5m, t_Elections[0].Results[1].Participation.Value.Value);
        }
Пример #2
0
        public Election[] CreateElections(ElectionParticipationResult Elections, RegionResult Regions)
        {
            var t_Regions = m_RegionConverter.Convert(Regions);

            return
                (m_ElectionConverter.Convert(Elections)
                 .Select(E =>
            {
                E.Results = E.Results.Select(R =>
                {
                    R.Region.Name = _LookupRegionByCode(R.Region.Code, t_Regions)?.Name;
                    return R;
                }).ToList();
                return E;
            })
                 .ToArray());
        }
Пример #3
0
        public void CreateElections()
        {
            var t_Factory   = new ElectionFactory(new RegionConverter(), new ElectionParticipationConverter());
            var t_RegionDTO = new RegionResult
            {
                title     = "",
                variables = new Variable[]
                {
                    new Variable
                    {
                        code       = "Region",
                        values     = new string[] { "00", "01" },
                        valueTexts = new string[] { "Foo", "Bar" }
                    }
                }
            };

            var t_ElectionDTO = new ElectionParticipationResult
            {
                data = new Data[]
                {
                    new Data {
                        key = new string[] { "00", "1900" }, values = new string[] { "50.0" }
                    },
                    new Data {
                        key = new string[] { "01", "1900" }, values = new string[] { "25.0" }
                    }
                }
            };

            var t_Elections = t_Factory.CreateElections(t_ElectionDTO, t_RegionDTO);

            Assert.IsTrue(t_Elections.Length == 1);

            Assert.IsTrue(t_Elections[0].Results.Count == 2);
            Assert.IsTrue(t_Elections[0].Year.Value == 1900);

            Assert.AreEqual(0, t_Elections[0].Results[0].Region.Code);
            Assert.AreEqual("Foo", t_Elections[0].Results[0].Region.Name);
            Assert.AreEqual(0.5m, t_Elections[0].Results[0].Participation.Value.Value);

            Assert.AreEqual(1, t_Elections[0].Results[1].Region.Code);
            Assert.AreEqual("Bar", t_Elections[0].Results[1].Region.Name);
            Assert.AreEqual(0.25m, t_Elections[0].Results[1].Participation.Value.Value);
        }