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 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 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> { 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 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 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 SetUp() { var spec = entitySpec.Begin().Add("*"); var export = new DataExtract <School>(spec); _entity = export.TopEntity; }
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 TestDeepDeclaration() { var export = new DataExtract <DeepDeclaration>(entitySpec.Begin().Add("*")); var spec = new entitySpec(export.TopEntity); CollectionAssert.AreEqual(new[] { "TheFirst.X1.Ss1.X", "TheFirst.X1.Ss1.Y", "TheFirst.X1.Ss2.X", "TheFirst.X1.Ss2.Y", "TheFirst.X2.Ss1.X", "TheFirst.X2.Ss1.Y", "TheFirst.X2.Ss2.X", "TheFirst.X2.Ss2.Y", "TheSecond.X1.Ss1.X", "TheSecond.X1.Ss1.Y", "TheSecond.X1.Ss2.X", "TheSecond.X1.Ss2.Y", "TheSecond.X2.Ss1.X", "TheSecond.X2.Ss1.Y", "TheSecond.X2.Ss2.X", "TheSecond.X2.Ss2.Y", }, spec.fields.Select(_ => _.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 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 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 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 TestLiftedDictionary() { var entity = new DataExtract <WithDictionary>(_starSpec).TopEntity; Assert.AreEqual(0, entity.Fields.Count); var list = entity.Lists.Single(); Assert.AreEqual("AnnoyingThingDic", list.ExternalName); CollectionAssert.AreEqual(new[] { typeof(string), typeof(int) }, list.Fields.Select(_ => _.FieldType)); }
public void Test2() { var x = new DataExtract <AllPropertyTypes>( entitySpec.Begin() .Add("TheString") .Add("TheInt32") .Add("formula1").Formula("val(TheString)") .Add("formula2").Formula("str(TheInt32)") .Add("formula3").Formula("7")); var inverse = new entitySpec(x.TopEntity); }
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 Test() { var y = entitySpec.Begin().Add("*"); var z = JsonConvert.SerializeObject(y, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, }); var x = new DataExtract <AllPropertyTypes>(entitySpec.Begin().Add("*")); var inverse = new entitySpec(x.TopEntity); }
private DataExtract Setup() { envData = new EnvironmentData(null, null, null, null, DateTime.Now); eHandlerMoq = new Mock <IEnvironmentHandler>(); eHandlerMoq.Setup(m => m.GetEnvironmentData()).Returns(envData); iisHandlerMoq = new Mock <IIisHandler>(); servHandlerMoq = new Mock <IServiceHandler>(); var sut = new DataExtract(eHandlerMoq.Object, iisHandlerMoq.Object, servHandlerMoq.Object); return(sut); }
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 TestTableProgression() { SqlTestHelpers.WithNewDb("SqlTableProgression", conn => { using (var cmd = new SqlCommand("CREATE TABLE School_bck (x int)", conn)) cmd.ExecuteNonQuery(); using (var cmd = new SqlCommand("CREATE TABLE School_Classes (x int)", conn)) cmd.ExecuteNonQuery(); using (var cmd = new SqlCommand("CREATE TABLE School_Classes_Students_tmp (x int)", conn)) cmd.ExecuteNonQuery(); var tableManager = new SqlTableManager(SqlTestHelpers.ConnectionString("SqlTableProgression")); var dataExtract = new DataExtract <School>(Spec, tableManager); var entityWithTable = new EntityWithTable(dataExtract.TopEntity, tableManager); // just to make some use of entityWithTable Assert.IsNotNull(entityWithTable); // pre-assert var tables = tableManager.GetExistingTableNames(conn, false); CollectionAssert.AreEquivalent(new[] { "School_bck", "School_Classes", "School_Classes_Students_tmp" }, tables); // after first begin, we should have a full set of _tmp, nothing else touched tableManager.Begin(); tables = tableManager.GetExistingTableNames(conn, false); CollectionAssert.AreEquivalent(new[] { "School_bck", "School_Classes", "School_Classes_Students_tmp", "School_tmp", "School_Classes_tmp" }, tables); // after first end, we should have a _bck of the faked School_Classes and the three real tables and no _tmp tableManager.End(); tables = tableManager.GetExistingTableNames(conn, false); CollectionAssert.AreEquivalent(new[] { "School_Classes_bck", "School", "School_Classes", "School_Classes_Students" }, tables); // after second begin, we should have a full set of _tmp, nothing else touched since last check tableManager.Begin(); tables = tableManager.GetExistingTableNames(conn, false); CollectionAssert.AreEquivalent(new[] { "School_Classes_bck", "School", "School_Classes", "School_Classes_Students", "School_Classes_Students_tmp", "School_tmp", "School_Classes_tmp" }, tables); // efter second, we should have a full set of _bck and and real files and no _tmp tableManager.End(); tables = tableManager.GetExistingTableNames(conn, false); CollectionAssert.AreEquivalent(new[] { "School_bck", "School_Classes_bck", "School_Classes_Students_bck", "School", "School_Classes", "School_Classes_Students" }, tables); }); }