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 TestWithAll() { var c = new ClassToTestEnumerables { Case1 = new[] { 1, 2 }, Case2 = new[] { 3, 4 }, Case3 = new List <int> { 5, 6 }, Case4 = new[] { 7, 8 }, Case5 = new[] { 9, 10 }, Case6 = new List <int> { 11, 12 } }; c.DeeperF = c; c.DeeperP = c; var t = new InMemoryTableManager(); var export = new DataExtract <ClassToTestEnumerables>(_spec, t); export.Run(c); var tables = export.TableManager.GetWithAllData().ToDictionary(_ => _.Name, _ => _.Rows); tables.Remove("ClassToTestEnumerables"); Assert.IsTrue(tables.Values.All(_ => _.Count == 2)); }
public void SetUp() { var spec = entitySpec.Begin().Add("*"); var export = new DataExtract <DeepDeclaration>(spec); _entity = export.TopEntity; var dd = new DeepDeclaration { TheFirst = new Level2 { X1 = new Level3 { Ss1 = new SomeStruct { X = 78 } } }, TheSecond = new Level2 { X2 = new Level3 { Ss2 = new SomeStruct { Y = 79 } } }, }; export.Run(dd); var table = export.TableManager.GetWithAllData(); _topTable = table.Single(); }
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 TestAutonumberingWithAggregation() { var spec = entitySpec.Begin() .Add("Tot").Aggregates("Strings.x") .Add(entitySpec.Begin("Strings") .Add("x").Formula("#index*2") .Add("@|y")); var export = new DataExtract <TheTop>(spec); export.Run(new TheTop { Strings = new List <string> { "a", "b", "c", "d", "e" } }); var tables = export.TableManager.GetWithAllData(); var rows = tables.Single(_ => _.Name == "Strings").Rows; var firstColumn = rows.Select(_ => _.Columns.First()); var lastColumn = rows.Select(_ => _.Columns.Last()); CollectionAssert.AreEqual(new[] { 0, 2, 4, 6, 8 }, firstColumn); CollectionAssert.AreEqual(new[] { "a", "b", "c", "d", "e" }, lastColumn); Assert.AreEqual(2 + 4 + 6 + 8, tables.First().Rows.Single().Columns.Single()); }
public void Test() { var spec = entitySpec.Begin() .Add(entitySpec.Begin("SelfList").NotSaved() .Add("Double")) .Add("AggregatedDouble").Aggregates("SelfList.Double") .Add("FormulaOnAggregate").Formula("2*AggregatedDouble"); var theTop = new TheTop { SelfList = new List <TheTop> { new TheTop { Double = 42 }, new TheTop { Double = 43 } } }; var t = new InMemoryTableManager(); var export = new DataExtract <TheTop>(spec, t); _topEntity = export.TopEntity; export.Run(theTop); _tables = export.TableManager.GetWithAllData(); _topTable = _tables.Single(_ => _.Name == "TheTop"); }
public void Test() { var spec = entitySpec.Begin().Add("*"); var testObj = new WithDictionary { AnnoyingThing = new AnnoyingThing { Dic = new Dictionary <string, object> { { "nisse", "kalle" }, { "sture", null }, { "ulrik", 7 } } } }; SqlTestHelpers.WithNewDb("Gurka", conn => { var tm = new SqlTableManager(SqlTestHelpers.ConnectionString("Gurka")); var dataExtract = new DataExtract <WithDictionary>(spec, tm); dataExtract.Run(testObj); var result = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM WithDictionary"); Assert.AreEqual(1, result.NameAndTypes.Length); result = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM WithDictionary_AnnoyingThingDic"); Assert.AreEqual(2, result.NameAndTypes.Length); }); }
public void SetUp2() { Spec = entitySpec.Begin() .Add("Name") .Add(entitySpec.Begin("Classes") .Add("Name").PrimaryKey() .Add(entitySpec.Begin("Students") .Add("FirstName") .Add("LastName"))); var exportMem = new DataExtract <School>(Spec); exportMem.Run(School); var tables = exportMem.TableManager.GetWithAllData(); Assert.AreEqual(1, tables.Single(_ => _.Name == "School").Rows.Count); Assert.AreEqual(6, tables.Single(_ => _.Name == "Classes").Rows.Count); Assert.AreEqual(100, tables.Single(_ => _.Name == "Students").Rows.Count); if (Environment.MachineName != "DAN_FACTOR10") { return; } var tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("SchoolPkTest")); var exportDb = new DataExtract <School>(Spec, tableFactory); SqlTestHelpers.WithNewDb("SchoolPkTest", conn => { var sw = Stopwatch.StartNew(); exportDb.Run(Enumerable.Range(0, 1).Select(_ => School)); _classQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM school_classes"); }); }
public void SetUp() { if (SqlTestHelpers.ConnectionString(null) == null) { return; } SqlTestHelpers.WithNewDb("LogTest", conn => { var tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("LogTest"), "log"); var export = new DataExtract <School>(Spec, tableFactory); export.Run(new[] { School }); tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("LogTest"), "log"); tableFactory.WriteLog("Explicit logging from the outside A"); export = new DataExtract <School>(Spec, tableFactory); export.Run(new[] { School }); tableFactory.WriteLog("Explicit logging from the outside B"); tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("LogTest"), "log"); tableFactory.WriteLog("Explicit logging from the outside C"); _logRows = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM log").Rows.Select(_ => new logEntry(_)).ToList(); var lookup = _logRows.ToLookup(_ => _.SessionId, _ => _); _log1 = lookup.FirstOrDefault(_ => _.Count() == 3)?.ToList(); _log2 = lookup.FirstOrDefault(_ => _.Count() == 6)?.ToList(); _log3 = lookup.FirstOrDefault(_ => _.Count() == 1)?.ToList(); _log1?.Sort((x, y) => x.SeqId.CompareTo(y.SeqId)); _log2?.Sort((x, y) => x.SeqId.CompareTo(y.SeqId)); _log3?.Sort((x, y) => x.SeqId.CompareTo(y.SeqId)); }); }
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> { -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 TestThatCompletedMethodIsCalledOnObjectsImplementingIDataExtractCompleted() { var export = new DataExtract <X>(entitySpec.Begin().Add("*")); var x = new X(); Assert.IsFalse(x.CompletedCalled); export.Run(x); Assert.IsTrue(x.CompletedCalled); }
public void TestSimplePropertiesAndIEnumerableOverPrimitive() { var export = new DataExtract <TheTop>(entitySpec.Begin() .Add("Strings")); export.Run(_td); var table = export.TableManager.GetWithAllData().Last(); CollectionAssert.AreEquivalent(_td.Strings, table.Rows.SelectMany(_ => _.Columns)); }
public void TestSchoolExample() { var dataextract = new DataExtract <School>(_spec); dataextract.Run(School); var tables = dataextract.TableManager.GetWithAllData(); Assert.AreEqual(2, tables.Count); _classesTable = tables.Single(_ => _.Name == "Classes"); }
public void TestSimpleProperties() { var export = new DataExtract <TheTop>(entitySpec.Begin() .Add("FirstName") .Add("SomeStruct.X")); export.Run(_td); var tables = export.TableManager.GetWithAllData(); CollectionAssert.AreEqual(new object[] { "nisse", 3 }, tables.Single().Rows.Single().Columns); }
public void TestSchoolExample() { var export = new DataExtract(typeof(School), Spec); export.Run(School); var tables = export.TableManager.GetWithAllData(); Assert.AreEqual(1, tables.Single(_ => _.Name == "School").Rows.Count); Assert.AreEqual(6, tables.Single(_ => _.Name == "Classes").Rows.Count); Assert.AreEqual(100, tables.Single(_ => _.Name == "Students").Rows.Count); }
public void TestSimplePropertiesAndIEnumerableOverStruct() { var export = new DataExtract <TheTop>(entitySpec.Begin() .Add(entitySpec.Begin("Structs") .Add("X") .Add("Y"))); export.Run(_td); var table = export.TableManager.GetWithAllData().Last(); CollectionAssert.AreEquivalent(new[] { 5, 6, 7, 8 }, table.Rows.SelectMany(_ => _.Columns)); }
public void Test10000Schools() { var export = new DataExtract(typeof(School), Spec); var sw = Stopwatch.StartNew(); export.Run(Enumerable.Range(0, 10000).Select(_ => School)); Console.Write(sw.ElapsedMilliseconds.ToString()); var tables = export.TableManager.GetWithAllData(); Assert.AreEqual(10000, tables.Single(_ => _.Name == "School").Rows.Count); Assert.AreEqual(60000, tables.Single(_ => _.Name == "Classes").Rows.Count); Assert.AreEqual(1000000, tables.Single(_ => _.Name == "Students").Rows.Count); }
public void TestFiltering2() { var aStudent = new Student { FirstName = "Karl", LastName = "Anka" }; var school = new School { Name = "Xxx", Classes = new List <Class> { new Class { Name = "Klass 1", Students = new List <Student> { aStudent, aStudent } }, new Class { Name = "Klass 2", Students = new List <Student> { aStudent, aStudent } }, new Class { Name = "Klass 3", Students = new List <Student> { aStudent, aStudent } } } }; var spec = entitySpec.Begin() .Add(entitySpec.Begin("Classes").Where("Name!='Klass 1'") .Add("Name") .Add(entitySpec.Begin("Students") .Add("FirstName") .Add("LastName"))); var export = new DataExtract <School>(spec); export.Run(school); var tables = export.TableManager.GetWithAllData(); var classesTable = tables.Single(_ => _.Name == "Classes"); var studentsTable = tables.Single(_ => _.Name == "Students"); Assert.AreEqual(2, classesTable.Rows.Count); // this does not work yet... //Assert.AreEqual(4, studentsTable.Rows.Count); }
public void TestThatFilteringLazyLoadsProperties() { var list = Enumerable.Range(1, 3).Select(_ => new FilterMeLazily()).ToList(); var spec = entitySpec.Begin().Where($"Id=='{list[1].Id}'").Add("*"); var export = new DataExtract <FilterMeLazily>(spec); export.Run(list); var table = export.TableManager.GetWithAllData().Single(); Assert.AreEqual(1, table.Rows.Count); Assert.AreEqual(1, list.Count(_ => _.Value != 0)); }
public void TestSimpleFormula() { var spec = entitySpec.Begin() .Add("Double") .Add("kalle").Formula("3+Double") .Add("nisse").Formula("5*6") .Add("sture").Formula("kalle+nisse"); var export = new DataExtract <TheTop>(spec); export.Run(new TheTop { Double = 4 }); CollectionAssert.AreEqual(new[] { 4.0, 7.0, 30.0, 37.0 }, export.TableManager.GetWithAllData().Single().Rows.Single().Columns); }
static void Main(string[] args) { var school = new School { Name = "Old School", Classes = new[] { "Klass 1a", "Klass 1b", "Klass 2a", "Klass 2b", "Klass 3a", "Klass 3b" }.Select( _ => new Class { Name = _, Students = new List <Student>() }).ToList() }; var firstNames = new[] { "Ada", "Bertil", "Cecilia", "David", "Elina", "Fredrik", "Gun", "Hans", "Ida", "Jan", "Klara" }; var lastNames = new[] { "Johansson", "Eriksson", "Karlsson", "Andersson", "Nilsson", "Svensson", "Pettersson" }; for (var i = 0; i < 100; i++) { school.Classes[i % school.Classes.Count].Students.Add(new Student { FirstName = firstNames[i % firstNames.Length], LastName = lastNames[i % lastNames.Length] }); } var spec = entitySpec.Begin() .Add("Name") .Add(entitySpec.Begin("Classes") .Add("Name") .Add(entitySpec.Begin("Students") .Add("FirstName") .Add("LastName"))); const int numberOfSchools = 10000; var tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("SchoolTest")); var export = new DataExtract <School>(spec, tableFactory); SqlTestHelpers.WithNewDb("SchoolTest", conn => { var sw = Stopwatch.StartNew(); export.Run(Enumerable.Range(0, numberOfSchools).Select(_ => school)); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); sw.Restart(); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); //Assert.AreEqual(numberOfSchools, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM school")); //Assert.AreEqual(numberOfSchools * 6, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM classes")); //Assert.AreEqual(numberOfSchools * 100, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM students")); }); Console.ReadLine(); }
public void TestFiltering3() { var schools = Enumerable.Range(0, 10).Select(_ => new School { Name = $"Skola {_}" }); var spec = entitySpec.Begin().Where("#index%2==0").Add("*"); var export = new DataExtract <School>(spec); export.Run(schools); var tables = export.TableManager.GetWithAllData(); Assert.AreEqual(5, tables.Single(_ => _.Name == "School").Rows.Count); Assert.AreEqual(0, tables.Single(_ => _.Name == "Classes").Rows.Count); Assert.AreEqual(0, tables.Single(_ => _.Name == "Students").Rows.Count); }
public void SetUp() { _data = new AllPropertyTypes { TheString = "Ashem Vohu", TheDateTime = new DateTime(1967, 10, 1, 1, 2, 3), TheDouble = Math.PI, TheFloat = 1.835f, TheInt16 = 42, TheInt32 = 1000000, TheInt64 = (long)1E18, TheBool = true, }; var export = new DataExtract <AllPropertyTypes>(entitySpec.Begin() .Add("TheBool") .Add("TheString") .Add("TheDateTime") .Add("TheDouble") .Add("TheFloat") .Add("TheDecimal") .Add("TheInt16") .Add("TheInt32") .Add("TheInt64") .Add("TheId") .Add("TheEnum") .Add("TheNullableInt") .Add("TheStringProperty") .Add("TheInt32Property") .Add("TheNullableInt32Property") .Add("formulanumber1").Formula("3") .Add("formulanumber2").Formula("TheInt32") .Add("formulastring1").Formula("'nisse'") .Add("formulastring2").Formula("'TheStringProperty'") ); export.Run(_data); export.TableManager.GetWithAllData(); var dbTable = (SqlTable) new SqlTableManager("dummy").New(export.TopEntity, true, true, -1); _createSql = dbTable.GenerateCreateTable(dbTable.Name); }
public void Test() { var spec = entitySpec.Begin() .Add("Blob1") .Add("Blob2") .Add("Blob3"); var testObj = new WithBlobs { Blob1 = new byte[] { 1, 2, 3, 4, 5 }, Blob3 = new byte[] { 6, 7, 8, 9, 0 } }; SqlTestHelpers.WithNewDb("Gurka", conn => { var tm = new SqlTableManager(SqlTestHelpers.ConnectionString("Gurka")); var dataExtract = new DataExtract <WithBlobs>(spec, tm); dataExtract.Run(testObj); var result = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM WithBlobs"); Assert.AreEqual(3, result.NameAndTypes.Length); }); }
public void SetUp() { if (SqlTestHelpers.ConnectionString(null) == null) { return; } var tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("SchoolTest"), "log"); var export = new DataExtract <School>(Spec, tableFactory); SqlTestHelpers.WithNewDb("SchoolTest", conn => { var sw = Stopwatch.StartNew(); export.Run(Enumerable.Range(0, NumberOfSchools).Select(_ => School)); Console.WriteLine(sw.ElapsedMilliseconds.ToString()); _schoolQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM school"); _classQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM school_classes"); _studentQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT TOP 1 * FROM school_classes_students"); _studentCount = SqlTestHelpers.SimpleQuery <int>(conn, "SELECT count(*) FROM school_classes_students"); _logQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM log"); }); }
public void Test() { var spec = entitySpec.Begin() .Add("FirstName") .Add("AggregatedX").Aggregates("Structs.X") .Add(entitySpec.Begin("Structs").NotSaved() .Add("X")) .Add(entitySpec.Begin("Self.SelfList") .Add("Double")) .Add("AggregatedDouble").Aggregates("Self.SelfList.Double"); var theTop = new TheTop { FirstName = "Petronella", Structs = Enumerable.Range(1, 4).Select(_ => new SomeStruct { X = _ }).ToList(), SomeStruct = new SomeStruct { X = 7, Y = 8 }, Self = new TheTop { SelfList = new List <TheTop> { new TheTop { Double = 42 }, new TheTop { Double = 43 } } } }; var t = new InMemoryTableManager(); var export = new DataExtract <TheTop>(spec, t); _topEntity = export.TopEntity; export.Run(theTop); _tables = export.TableManager.GetWithAllData(); _topTable = _tables.Single(_ => _.Name == "TheTop"); }
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); }
public void Test() { var spec = entitySpec.Begin() .Add(entitySpec.Begin("DictionariesAreSneaky") .Add("KeyValue").Formula("Key+Value") .Add("Key").NotSaved() .Add("Value").NotSaved()); var x = new TestClassWithSneakyStuff { DictionariesAreSneaky = new Dictionary <int, int> { { 1, 99 }, { 5, 15 } } }; var export = new DataExtract <TestClassWithSneakyStuff>(spec); export.Run(x); var t = export.TableManager.GetWithAllData().Single(_ => _.Name == "DictionariesAreSneaky"); CollectionAssert.AreEquivalent(new[] { 100, 20 }, t.Rows.Select(_ => _.Columns.Single())); }