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 PopulateAndFindCompositeKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedDoc(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) }); } Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("ID35", new DateTime(1953, 12, 10)); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Descr35", match1["Description"]); var match2 = tbl.FindByKey("ID35", new DateTime(1953, 07, 10)); Aver.IsNull(match2); }
public void PopulateAndUpsertExisting() { var tbl = new Rowset(Schema.GetForTypedDoc(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 = "POP17", FirstName = "Yaroslav", LastName = "Suzkever", DOB = new DateTime(1952, 12, 10), YearsInSpace = 14 }; var res = tbl.Upsert(update);//<-------------!!!!!! Aver.IsTrue(res.Updated); var match = tbl.FindByKey("POP17") as Person; Aver.IsNotNull(match); Aver.AreEqual("Yaroslav", match.FirstName); Aver.AreEqual("Suzkever", match.LastName); }
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 DynamicDoc(tbl.Schema); row["ID"] = i; row["Description"] = "Item-{0}".Args(i); tbl.Insert(row); } Aver.AreEqual(1000, tbl.Count); var match = tbl.FindByKey(178); Aver.IsNotNull(match); Aver.AreObjectsEqual("Item-178", match["Description"]); }
public void PopulateAndDeleteNonExisting() { var tbl = new Rowset(Schema.GetForTypedDoc(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); //<-------------!!!!!! Aver.IsTrue(idx == -1); Aver.AreEqual(1000, tbl.Count); var match = tbl.FindByKey("POP17") as Person; Aver.IsNotNull(match); }
public void PopulateAndFindKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedDoc(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 }); } Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Popov-35", match1["LastName"]); //example of dynamic row access var match2 = tbl.FindByKey("POP36") as Person; Aver.IsNotNull(match2); Aver.AreEqual("Popov-36", match2.LastName);//example of typed row access var match3 = tbl.FindByKey("DoesNotExist"); Aver.IsNull(match3); }
public void PopulateAndFindKey_DynamicRows() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { var row = new DynamicDoc(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); } Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Popov-35", match1["LastName"]); var match2 = tbl.FindByKey("POP36") as DynamicDoc; Aver.IsNotNull(match2); Aver.AreObjectsEqual("Popov-36", match2["LastName"]); var match3 = tbl.FindByKey("DoesNotExist"); Aver.IsNull(match3); }
public async override Task <RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { await Task.Delay(100); var result = new Rowset(Schema.GetForTypedDoc <Patient>()); var p = query.FindParamByName("Msg")?.Value.AsString(); result.Insert(new Patient { First_Name = "Jack", Last_Name = "Nice", Address1 = p }); result.Insert(new Patient { First_Name = "Mary", Last_Name = "Dice", Address1 = p }); return(result); }
public static void ASYNC_InsertManyUsingLogChanges_TypedRow(ICRUDDataStore store) { var rowset = new Rowset(Schema.GetForTypedDoc(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.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%loff%") }); Aver.AreEqual(1000, task.Result[0].Count); task = store.LoadAsync(new Query("CRUD.Queries.Patient.List", typeof(Patient)) { new Query.Param("LN", "%ovich%") }); Aver.AreEqual(327, task.Result[0].Count); }
public static void 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.Save(rowset); var result = store.Load(new Query("CRUD.Patient.List", typeof(Patient)) { new Query.Param("LN", "%loff%") })[0]; Assert.AreEqual(1000, result.Count); result = store.Load(new Query("CRUD.Patient.List", typeof(Patient)) { new Query.Param("LN", "%ovich%") })[0]; Assert.AreEqual(327, result.Count); }
public void PopulateAndFindKey_MixedRows() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { var row = new DynamicDoc(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 }); } Aver.AreEqual(2000, tbl.Count); var match1 = tbl.FindByKey("DYN35"); Aver.IsNotNull(match1); Aver.IsTrue(match1 is DynamicDoc); Aver.AreObjectsEqual("DynamicPopov-35", match1["LastName"]); var match2 = tbl.FindByKey("TYPED36") as Person; Aver.IsNotNull(match2); Aver.AreObjectsEqual("TypedPopov-36", match2["LastName"]); var match3 = tbl.FindByKey("DoesNotExist"); Aver.IsNull(match3); }
public void JSON_SerializeRowset_TypedRows() { var rowset = new Rowset(Schema.GetForTypedDoc(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 }); } // Serialization without schema var json = rowset.ToJson(Azos.Serialization.JSON.JsonWritingOptions.PrettyPrint); json.See(); var rowset2 = json.JsonToDynamic(); Aver.AreEqual("Popov-1", rowset2.Rows[1][2]); RowsetBase rowset3 = new Rowset(Schema.GetForTypedDoc(typeof(Person))); var res = Rowset.FromJSON <Person>(json, ref rowset3); Aver.AreEqual(10, res); Aver.AreEqual(10, rowset3.Count); Aver.AreObjectsEqual("Popov-1", rowset3[1][2]); var options = new Azos.Serialization.JSON.JsonWritingOptions { RowsetMetadata = true, IndentWidth = 2, ObjectLineBreak = true, MemberLineBreak = true, SpaceSymbols = true, ASCIITarget = false }; rowset3.Clear(); var json2 = rowset.ToJson(options); var res2 = Rowset.FromJSON <Person>(json2, ref rowset3); Aver.AreEqual(10, res); Aver.AreEqual(10, rowset3.Count); Aver.AreObjectsEqual("Popov-1", rowset3[1][2]); }
public void Save() { var rowset = new Rowset(Schema.GetForTypedDoc(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 = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(0, rs.Count); m_Store.Save(rowset); rowset.PurgeChanges(); rs = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(9, rs.Count); rowset[55]["Age"] = 900; //falls out of query rowset.Update(rowset[55]); rowset.Delete(rowset[59]); //physically deleted m_Store.Save(rowset); rs = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(7, rs.Count); Aver.AreObjectsEqual(58, rs.First()["Age"]); Aver.AreObjectsEqual(51, rs.Last()["Age"]); }
private Rowset makeTypedRows(int count) { var rset = new Rowset(Schema.GetForTypedDoc(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 LogChanges_Insert() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); tbl.LogChanges = true; tbl.Insert(new Person { ID = "POP1", FirstName = "Oleg", LastName = "Popov", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); Aver.AreEqual(1, tbl.ChangeCount); Aver.IsTrue(DocChangeType.Insert == tbl.GetChangeAt(0).Value.ChangeType); }
public void LogChanges_Update() { 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.Update(tbl[0]); Assert.AreEqual(1, tbl.ChangeCount); Assert.AreEqual(RowChangeType.Update, tbl.GetChangeAt(0).Value.ChangeType); }
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 JSON_SerializeRowset_ComplexTypedRows_Map() { var rowset = new Rowset(Schema.GetForTypedDoc(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(Azos.Serialization.JSON.JsonWritingOptions.PrettyPrintRowsAsMap);// ); json.See(); var rowset2 = json.JsonToDynamic(); Aver.AreEqual("Popov-1", rowset2.Rows[1].LastName); Aver.AreEqual("789211", rowset2.Rows[1].History1[0].ID); }
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]); }
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 PopulateAndDeleteExisting_UsingValues() { 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 idx = tbl.Delete("POP17"); //<-------------!!!!!! Assert.IsTrue(idx >= 0); Assert.AreEqual(999, tbl.Count); var match = tbl.FindByKey("POP17") as Person; Assert.IsNull(match); }