示例#1
0
        public void TestCompletenessReportMitGapToCsv()
        {
            CompletenessReport cr = new CompletenessReport()
            {
                LokationsId = "DE12345",
                Coverage    = 0.87M, // 87%
                wertermittlungsverfahren = BO4E.ENUM.Wertermittlungsverfahren.PROGNOSE,
                ReferenceTimeFrame       = new BO4E.COM.Zeitraum()
                {
                    Startdatum = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 3, 1, 0, 0, 0, DateTimeKind.Utc)
                },
            };

            cr.Values = new List <CompletenessReport.BasicVerbrauch>
            {
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 17,
                    Startdatum = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 2, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 21,
                    Startdatum = new DateTime(2019, 1, 7, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 8, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 35,
                    Startdatum = new DateTime(2019, 1, 12, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 13, 0, 0, 0, DateTimeKind.Utc)
                }
            };
            cr.Gaps = new List <CompletenessReport.BasicVerbrauch>
            {
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 0,
                    Startdatum = new DateTime(2017, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2017, 1, 2, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 0,
                    Startdatum = new DateTime(2017, 1, 7, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2017, 1, 8, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 0,
                    Startdatum = new DateTime(2017, 1, 12, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2017, 1, 13, 0, 0, 0, DateTimeKind.Utc)
                }
            };
            var multiplicityResult = cr.ToCsv(lineTerminator: Environment.NewLine);

            Assert.AreEqual(2 + cr.Values.Count + cr.Gaps.Count, new List <string>(multiplicityResult.Split(Environment.NewLine)).Count);
        }
示例#2
0
        public void TestCompletenessReportToCsvExceptions()
        {
            CompletenessReport cr = new CompletenessReport()
            {
                LokationsId = "DE12345",
                Coverage    = 0.87M, // 87%
                wertermittlungsverfahren = BO4E.ENUM.Wertermittlungsverfahren.PROGNOSE,
                ReferenceTimeFrame       = new BO4E.COM.Zeitraum()
                {
                    Startdatum = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 3, 1, 0, 0, 0, DateTimeKind.Utc)
                },
            };

            // reihenfolge
            List <Dictionary <string, string> > reihenfolge = new List <Dictionary <string, string> >
            {
                new Dictionary <string, string>()
                {
                    ["LokationsId"] = "messlokationsId"
                },
                new Dictionary <string, string>()
                {
                    ["Coverage"] = "Newcoverage"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.Startdatum"] = "time.startdatum"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.Enddatum"] = "time.enddatum"
                },
                new Dictionary <string, string>()
                {
                    ["Wert"] = null
                },
                new Dictionary <string, string>()
                {
                    ["Startdatum"] = "V.startdatum"
                },
                new Dictionary <string, string>()
                {
                    ["Enddatum"] = "V.enddatum"
                },
                null
            };
            string newResult = string.Empty;

            Assert.ThrowsException <ArgumentNullException>(() => cr.ToCsv(';', true, Environment.NewLine, reihenfolge));
            Assert.AreEqual(newResult, "");


            // reihenfolge
            List <Dictionary <string, string> > reihenfolge2 = new List <Dictionary <string, string> >
            {
                new Dictionary <string, string>()
                {
                    ["lokationsId"] = "messlokationsId"
                },
                new Dictionary <string, string>()
                {
                    ["coverage"] = "Newcoverage"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.startdatum"] = "time.startdatum"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.enddatum"] = "time.enddatum"
                },
                new Dictionary <string, string>()
                {
                    ["wert"] = "V.wert"
                },
                new Dictionary <string, string>()
                {
                    ["startdatum"] = "V.startdatum"
                },
                new Dictionary <string, string>()
                {
                    ["enddatum"] = "V.enddatum"
                },
                new Dictionary <string, string>()
                {
                    ["asdasd"] = "000"
                }
            };

            Assert.ThrowsException <ArgumentException>(() => cr.ToCsv(';', true, Environment.NewLine, reihenfolge2));
            Assert.AreEqual(newResult, "");
        }
示例#3
0
        public void TestCompletenessReportToCsv()
        {
            CompletenessReport cr = new CompletenessReport()
            {
                LokationsId = "DE12345",
                Coverage    = 0.87M, // 87%
                wertermittlungsverfahren = BO4E.ENUM.Wertermittlungsverfahren.PROGNOSE,
                ReferenceTimeFrame       = new BO4E.COM.Zeitraum()
                {
                    Startdatum = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 3, 1, 0, 0, 0, DateTimeKind.Utc)
                },
            };
            string result = cr.ToCsv(';', true, Environment.NewLine);
            var    lines  = new List <string>(result.Split(Environment.NewLine));

            Assert.AreEqual(2, lines.Count);

            // reihenfolge
            List <Dictionary <string, string> > reihenfolge = new List <Dictionary <string, string> >
            {
                new Dictionary <string, string>()
                {
                    ["LokationsId"] = "messlokationsId"
                },
                new Dictionary <string, string>()
                {
                    ["Coverage"] = "Newcoverage"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.Startdatum"] = "time.startdatum"
                },
                new Dictionary <string, string>()
                {
                    ["Zeitraum.Enddatum"] = "time.enddatum"
                }
            };

            //string JSONdata = "{'completenessZfa':[{'lokationsId':'lokationsId'},{'coverage':'coverage'},{'Zeitraum.einheit':'einheit'},{'Zeitraum.dauer':'dauer'},{'Zeitraum.startdatum':'startdatum'},{'Zeitraum.enddatum':'enddatum'},{'obiskennzahl':'obiskennzahl'},{'einheit':'einheit'},{'wertermittlungsverfahren':'wertermittlungsverfahren'},{'startdatum':'Verbrauch.startdatum'},{'enddatum':'Verbrauch.enddatum'},{'wert':'Verbrauch.wert'},{'headerLine':'1'}]}";
            //var alldata = JsonConvert.DeserializeObject<Dictionary<string, List<Dictionary<string, string>>>>(JSONdata);
            //List<Dictionary<string, string>> reihenfolge = alldata["completenessZfa"];

            var Newresult = cr.ToCsv(';', true, Environment.NewLine, reihenfolge);

            lines = new List <string>(Newresult.Split(Environment.NewLine));
            Assert.AreEqual(2, lines.Count);
            string decimalSeparator = Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator;

            Assert.AreEqual("DE12345;0" + decimalSeparator + "87;2019-01-01T00:00:00Z;2019-03-01T00:00:00Z;", lines[1]);
            var commaResult = cr.ToCsv(',', lineTerminator: Environment.NewLine, reihenfolge: reihenfolge);

            Assert.AreEqual("DE12345,0" + decimalSeparator + "87,2019-01-01T00:00:00Z,2019-03-01T00:00:00Z,", commaResult.Split(Environment.NewLine)[1]);
            var dpunktResult = cr.ToCsv(':', lineTerminator: Environment.NewLine, reihenfolge: reihenfolge);

            Assert.AreEqual("DE12345:0" + decimalSeparator + "87:\"2019-01-01T00:00:00Z\":\"2019-03-01T00:00:00Z\":", dpunktResult.Split(Environment.NewLine)[1]);

            cr.Values = new List <CompletenessReport.BasicVerbrauch>
            {
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 17,
                    Startdatum = new DateTime(2019, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 2, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 21,
                    Startdatum = new DateTime(2019, 1, 7, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 8, 0, 0, 0, DateTimeKind.Utc)
                },
                new CompletenessReport.BasicVerbrauch()
                {
                    Wert       = 35,
                    Startdatum = new DateTime(2019, 1, 12, 0, 0, 0, DateTimeKind.Utc),
                    Enddatum   = new DateTime(2019, 1, 13, 0, 0, 0, DateTimeKind.Utc)
                }
            };

            reihenfolge.Add(new Dictionary <string, string>()
            {
                ["Wert"] = "V.wert"
            });
            reihenfolge.Add(new Dictionary <string, string>()
            {
                ["Startdatum"] = "V.startdatum"
            });
            reihenfolge.Add(new Dictionary <string, string>()
            {
                ["Enddatum"] = "V.enddatum"
            });

            var multiplicityResult = cr.ToCsv(lineTerminator: Environment.NewLine, reihenfolge: reihenfolge);

            Assert.AreEqual(2 + cr.Values.Count, new List <string>(multiplicityResult.Split(Environment.NewLine)).Count);
        }