Пример #1
0
        public void TestThatAggregatedValuesCanBeUsedInFormulas()
        {
            var spec = entitySpec.Begin(null, "ontop")
                       //.Add("SumList3").Aggregates("List3.").NotSaved()
                       .Add(entitySpec.Begin("List3")
                            .Add(entitySpec.Begin("@", "innerlist")
                                 .Add("@|zvalue")));
            var x = new Nisse
            {
                List3 = new List <List <double> > {
                    new List <double> {
                        15
                    }, new List <double> {
                        15, 16, 17
                    }, new List <double> {
                        18
                    }
                }
            };

            var             sb     = new StringBuilder();
            Action <string> log    = _ => sb.AppendLine(_);
            var             export = new DataExtract <Nisse>(spec, null, log);

            export.Run(x);

            _tables = export.TableManager.GetWithAllData().ToDictionary(_ => _.Name, _ => _);
        }
        public void BasicTestOfAllAggregationTypes()
        {
            var x = new Nisse
            {
                List1 = new List <int> {
                    -1
                },
                List2 = null
            };

            var export = new DataExtract <Nisse>(_spec);

            export.Run(x);

            var t      = export.TableManager.GetWithAllData().First();
            var column = t.Rows.Single().Columns;

            CollectionAssert.AreEqual(new object[]
            {
                -1 * 2,
                0,
                -1,
                0,
                -1,
                45,
                -1,
                47,
                -1,
                49,
                2,
                0
            }, column);
        }
        public void TestThatAggregationWorksWithEmptyLists()
        {
            var x = new Nisse
            {
                List1 = new List <int>(),
                List2 = new List <int> {
                    7
                }
            };

            var export = new DataExtract <Nisse>(_spec);

            export.Run(x);

            var t = export.TableManager.GetWithAllData().First();

            CollectionAssert.AreEqual(new object[]
            {
                0,
                0,
                0,
                0,
                DBNull.Value,
                DBNull.Value,
                DBNull.Value,
                DBNull.Value,
                DBNull.Value,
                DBNull.Value,
                0,
                0
            }, t.Rows.Single().Columns);
        }
        public void BasicTestOfAllAggregationTypes()
        {
            var x = new Nisse
            {
                List1 = new List <int> {
                    5, 6, 7
                },
                List2 = new List <int> {
                    7, 15, 18, 20
                },
            };

            var export = new DataExtract <Nisse>(_spec);

            export.Run(x);

            var t = export.TableManager.GetWithAllData().First();

            CollectionAssert.AreEqual(new object[]
            {
                5 + 6,
                15 + 18 + 20,
                5 + 6,
                15 + 18 + 20,
                6,
                20,
                5,
                15,
                LinkedFieldInfo.CoherseType(typeof(int), (5 + 6) / 2.0),
                LinkedFieldInfo.CoherseType(typeof(int), (15 + 18 + 20) / 3.0),
                2,
                3
            }, t.Rows.Single().Columns);
        }
        public void TestThatAggregatedValuesCanBeUsedInFormulas()
        {
            var spec = entitySpec.Begin(null, "Tjo")
                       .Add("squash").Aggregates("List1.@")
                       .Add(entitySpec.Begin("List1", "Hopp")
                            .Add("@|gurka"));
            var x = new Nisse
            {
                List1 = new List <int> {
                    5, 6, 7
                },
            };

            var export = new DataExtract <Nisse>(spec);

            export.Run(x);

            var tables = export.TableManager.GetWithAllData();

            _topTable = tables.First();
            _subTable = tables.Last();
        }
        public void TestThatAggregatedValuesCanBeUsedInFormulas()
        {
            var spec = entitySpec.Begin()
                       .Add("SumList1").Aggregates("List1.@").NotSaved()
                       .Add("SumList2").Aggregates("List2.@").NotSaved()
                       .Add("Average").Formula("(SumList1+SumList2)/2")
                       .Add("List1")
                       .Add("List2")
                       .Add(entitySpec.Begin("List3")
                            .Add(entitySpec.Begin("@", "q")
                                 .Add("@|z")));
            var x = new Nisse
            {
                List1 = new List <int> {
                    5, 6, 7
                },
                List2 = new List <int> {
                    20
                },
                List3 = new List <List <double> > {
                    new List <double> {
                        15.0
                    }, new List <double> {
                        15.0, 16, 17
                    }, new List <double> {
                        18.0
                    }
                }
            };

            var export = new DataExtract <Nisse>(spec);

            export.Run(x);

            var t = export.TableManager.GetWithAllData().First();

            CollectionAssert.AreEqual(new[] { 19 }, t.Rows.Single().Columns);
        }