public void BuildUsingAdHockSchema() { var schema = new Schema("TEZT", new Schema.FieldDef("ID", typeof(int), new List<FieldAttribute>{ new FieldAttribute(required: true, key: true)}), new Schema.FieldDef("Description", typeof(string), new List<FieldAttribute>{ new FieldAttribute(required: true)}) ); var tbl = new Rowset(schema); for(var i=0; i<1000; i++) { var row = new DynamicRow(tbl.Schema); row["ID"] = i; row["Description"] = "Item-{0}".Args(i); tbl.Insert( row ); } Assert.AreEqual(1000, tbl.Count); var match = tbl.FindByKey(178); Assert.IsNotNull( match ); Assert.AreEqual("Item-178", match["Description"]); }
public void JSON_SerializeRowset_ComplexTypedRows_Array() { var rowset = new Rowset(Schema.GetForTypedRow(typeof(PersonWithNesting))); for(var i=0; i<10; i++) rowset.Insert( new PersonWithNesting{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem{ ID = "111", StartDate = DateTime.Now, Description="Chaplin" }, History1 = new List<HistoryItem> { new HistoryItem{ ID = "789211", StartDate = DateTime.Now, Description="Chaplin with us" }, new HistoryItem{ ID = "234234", StartDate = DateTime.Now, Description="Chaplin with you" } }, History2 = new HistoryItem[2] }); var json = rowset.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrint);// ); Console.WriteLine( json); var rowset2 = json.JSONToDynamic(); Assert.AreEqual("Popov-1", rowset2.Rows[1][2]); }
public void LogChanges_Delete() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); tbl.Insert( new Person{ ID = "POP1", FirstName = "Oleg", LastName = "Popov", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); tbl.LogChanges = true; tbl.Delete( tbl[0] ); Assert.AreEqual(1, tbl.ChangeCount); Assert.AreEqual(0, tbl.Count); Assert.AreEqual(RowChangeType.Delete, tbl.GetChangeAt(0).Value.ChangeType); }
public static void ASYNC_InsertManyUsingLogChanges_TypedRow(ICRUDDataStore store) { var rowset = new Rowset( Schema.GetForTypedRow(typeof(Patient))); rowset.LogChanges = true; for(var i=0; i<1000; i++) { rowset.Insert( new Patient { SSN = "999-88-9012", First_Name = "Jack", Last_Name = "Kozloff"+i, DOB = new DateTime(1980, 1, 12) }); } for(var i=0; i<327; i++) { rowset.Insert( new Patient { SSN = "999-88-9012", First_Name = "Jack", Last_Name = "Abramovich"+i, DOB = new DateTime(2001, 1, 12) }); } store.SaveAsync( rowset ).Wait(); var task = store.LoadAsync( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%loff%") } ); Assert.AreEqual(1000, task.Result[0].Count); task = store.LoadAsync( new Query("CRUD.Patient.List", typeof(Patient) ) { new Query.Param("LN", "%ovich%") } ); Assert.AreEqual(327, task.Result[0].Count); }
public void JSON_SerializeRowset_TypedRows() { var rowset = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<10; i++) rowset.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); var json = rowset.ToJSON( NFX.Serialization.JSON.JSONWritingOptions.PrettyPrint);// ); Console.WriteLine( json); var rowset2 = json.JSONToDynamic(); Assert.AreEqual("Popov-1", rowset2.Rows[1][2]); }
private Rowset makeTypedRows(int count) { var rset = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<count; i++) rset.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 1000-i, YearsWithCompany = i }); return rset; }
public void PopulateAndUpsertNonExisting() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) tbl.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); var update = new Person{ ID = "GOODMAN17", FirstName = "John", LastName = "Jeffer", DOB = new DateTime(1952, 12, 10), YearsInSpace = 14 }; var existed = tbl.Upsert(update);//<-------------!!!!!! Assert.IsFalse( existed ); Assert.AreEqual(1001, tbl.Count); var match = tbl.FindByKey("POP17") as Person; Assert.IsNotNull( match ); Assert.AreEqual("Oleg", match.FirstName); Assert.AreEqual("Popov-17", match.LastName); match = tbl.FindByKey("GOODMAN17") as Person; Assert.IsNotNull( match ); Assert.AreEqual("John", match.FirstName); Assert.AreEqual("Jeffer", match.LastName); }
public void PopulateAndUpdateNonExisting() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) tbl.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); var update = new Person{ ID = "NONE17", FirstName = "Yaroslav", LastName = "Suzkever", DOB = new DateTime(1952, 12, 10), YearsInSpace = 14 }; var idx = tbl.Update(update);//<-------------!!!!!! Assert.IsTrue( idx==-1 ); var match = tbl.FindByKey("NONE17") as Person; Assert.IsNull( match ); }
public void PopulateAndFindKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) tbl.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); Assert.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Assert.IsNotNull( match1 ); Assert.AreEqual("Popov-35", match1["LastName"]); //example of dynamic row access var match2 = tbl.FindByKey("POP36") as Person; Assert.IsNotNull( match2 ); Assert.AreEqual("Popov-36", match2.LastName);//example of typed row access var match3 = tbl.FindByKey("DoesNotExist"); Assert.IsNull( match3 ); }
public void PopulateAndFindKey_MixedRows() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) { var row = new DynamicRow(tbl.Schema); row["ID"] = "DYN{0}".Args(i); row["FirstName"] = "Oleg"; row["LastName"] = "DynamicPopov-{0}".Args(i); row["DOB"] = new DateTime(1953, 12, 10); row["YearsInSpace"] = 12; tbl.Insert( row ); tbl.Insert( new Person{ ID = "TYPED{0}".Args(i), FirstName = "Oleg", LastName = "TypedPopov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); } Assert.AreEqual(2000, tbl.Count); var match1 = tbl.FindByKey("DYN35"); Assert.IsNotNull( match1 ); Assert.IsTrue( match1 is DynamicRow ); Assert.AreEqual("DynamicPopov-35", match1["LastName"]); var match2 = tbl.FindByKey("TYPED36") as Person; Assert.IsNotNull( match2 ); Assert.AreEqual("TypedPopov-36", match2["LastName"]); var match3 = tbl.FindByKey("DoesNotExist"); Assert.IsNull( match3 ); }
public void PopulateAndFindKey_DynamicRows() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) { var row = new DynamicRow(tbl.Schema); row["ID"] = "POP{0}".Args(i); row["FirstName"] = "Oleg"; row["LastName"] = "Popov-{0}".Args(i); row["DOB"] = new DateTime(1953, 12, 10); row["YearsInSpace"] = 12; tbl.Insert( row ); } Assert.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Assert.IsNotNull( match1 ); Assert.AreEqual("Popov-35", match1["LastName"]); var match2 = tbl.FindByKey("POP36") as DynamicRow; Assert.IsNotNull( match2 ); Assert.AreEqual("Popov-36", match2["LastName"]); var match3 = tbl.FindByKey("DoesNotExist"); Assert.IsNull( match3 ); }
public void PopulateAndFindCompositeKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(WithCompositeKey))); for(var i=0; i<1000; i++) tbl.Insert( new WithCompositeKey{ ID = "ID{0}".Args(i), StartDate = new DateTime(1953, 12, 10), Description = "Descr{0}".Args(i) }); Assert.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("ID35", new DateTime(1953, 12, 10)); Assert.IsNotNull( match1 ); Assert.AreEqual("Descr35", match1["Description"]); var match2 = tbl.FindByKey("ID35", new DateTime(1953, 07, 10)); Assert.IsNull( match2 ); }
public void PopulateAndDeleteNonExisting() { var tbl = new Rowset(Schema.GetForTypedRow(typeof(Person))); for(var i=0; i<1000; i++) tbl.Insert( new Person{ ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); var delete = new Person{ ID = "NONE17" }; var idx = tbl.Delete( delete );//<-------------!!!!!! Assert.IsTrue( idx==-1 ); Assert.AreEqual(1000, tbl.Count); var match = tbl.FindByKey("POP17") as Person; Assert.IsNotNull( match ); }
public void Save() { var rowset = new Rowset(Schema.GetForTypedRow(typeof(MyPerzon))); rowset.LogChanges = true; for(var i=0; i<100; i++) { rowset.Insert( new MyPerzon { GDID = new GDID(1, 1, (ulong)i), Name = "Jeka Koshmar", Age = i }); } var qryBetween5060 = new Query("CRUD.LoadPerzonsInAgeSpan", typeof(MyPerzon)) { new Query.Param("fromAge", 50), new Query.Param("toAge", 60) }; var rs = store.LoadOneRowset(qryBetween5060); Assert.IsNotNull( rs ); Assert.AreEqual(0, rs.Count); store.Save(rowset); rowset.PurgeChanges(); rs = store.LoadOneRowset(qryBetween5060); Assert.IsNotNull( rs ); Assert.AreEqual(9, rs.Count); rowset[55]["Age"] = 900; //falls out of query rowset.Update(rowset[55]); rowset.Delete(rowset[59]); //physically deleted store.Save(rowset); rs = store.LoadOneRowset(qryBetween5060); Assert.IsNotNull( rs ); Assert.AreEqual(7, rs.Count); Assert.AreEqual(58, rs.First()["Age"]); Assert.AreEqual(51, rs.Last()["Age"]); }