public void CopyFields_ExtendedDynamicRow_To_DynamicRow() { var schema = Schema.GetForTypedDoc(typeof(Person)); var fieldDefs = schema.FieldDefs.ToList(); fieldDefs.Add(new Schema.FieldDef("Info", typeof(string), new QuerySource.ColumnDef("Info"))); fieldDefs.Add(new Schema.FieldDef("Count", typeof(long), new QuerySource.ColumnDef("Info"))); var extendedSchema = new Schema("sname", fieldDefs.ToArray()); var from = new DynamicDoc(extendedSchema); from["FirstName"] = "Ivan"; from["Amount"] = 10; from["DOB"] = new DateTime(1990, 2, 16); from["GoodPerson"] = true; from["Info"] = "extended info"; from["Count"] = long.MaxValue; var to = new DynamicDoc(schema); from.CopyFields(to); Aver.AreObjectsEqual(to["FirstName"], from["FirstName"]); Aver.AreObjectsEqual(to["Amount"], from["Amount"]); Aver.AreObjectsEqual(to["DOB"], from["DOB"]); Aver.AreObjectsEqual(to["GoodPerson"], from["GoodPerson"]); }
public void Validate_Error_ValueList() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1981, 2, 12); person["YearsInSpace"] = 45; person["Amount"] = 100; person["Description"] = "0123"; person["Classification"] = "INVALID"; var error = person.Validate(); error?.Message.See(); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("Classification", ((FieldValidationException)error).FieldName); Aver.IsTrue(error.Message.Contains("list of allowed")); person["Classification"] = "good"; Aver.IsNull(person.Validate()); person["Classification"] = "bad"; Aver.IsNull(person.Validate()); person["Classification"] = "ugly"; Aver.IsNull(person.Validate()); }
public void Equality() { var person1 = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person1["ID"] = "POP1"; person1["FirstName"] = "Oleg"; person1["LastName"] = "Popov"; person1["DOB"] = new DateTime(1981, 2, 12); person1["YearsInSpace"] = 45; person1["Amount"] = 100; person1["Description"] = "Wanted to go to the moon"; var person2 = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person2["ID"] = "POP1"; person2["FirstName"] = "Egor"; person2["LastName"] = "Pedorov"; person2["DOB"] = new DateTime(1982, 5, 2); person2["YearsInSpace"] = 4; person2["Amount"] = 1000000; Aver.IsTrue(person1.Equals(person2)); person2["ID"] = "POP2"; Aver.IsFalse(person1.Equals(person2)); }
public void CopyFields_DynamicRow_To_Amorphous_IncludeAmorphous() { var schema = Schema.GetForTypedDoc(typeof(Person)); var from = new DynamicDoc(schema); from["FirstName"] = "Ivan"; from["Amount"] = 10; from["DOB"] = new DateTime(1990, 2, 16); from["GoodPerson"] = true; var to = new AmorphousDynamicDoc(Schema.GetForTypedDoc(typeof(Empty))); to.AmorphousData["field1"] = 123; to.AmorphousData["FirstName"] = "John"; from.CopyFields(to, includeAmorphousData: true); Aver.AreEqual(0, to.Schema.FieldCount); Aver.AreEqual(12, to.AmorphousData.Count); Aver.AreObjectsEqual(123, to.AmorphousData["field1"]); Aver.AreObjectsEqual(from["FirstName"], to.AmorphousData["FirstName"]); Aver.AreObjectsEqual(from["Amount"], to.AmorphousData["Amount"]); Aver.AreObjectsEqual(from["DOB"], to.AmorphousData["DOB"]); Aver.AreObjectsEqual(from["GoodPerson"], to.AmorphousData["GoodPerson"]); }
public void FindIndexByKey_DynamicRows() { var tbl = new Table(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 10; i++) { var row = new DynamicDoc(tbl.Schema); row["ID"] = "POP{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); } Aver.AreEqual(10, tbl.Count); var idx1 = tbl.FindIndexByKey("POP5"); Aver.AreEqual(5, idx1); var idx2 = tbl.FindIndexByKey("POP6"); Aver.AreEqual(6, idx2); var idx3 = tbl.FindIndexByKey("DoesNotExist"); Aver.AreEqual(-1, idx3); }
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 Table(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 CopyFields_DynamicRow() { var from = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); from["FirstName"] = "Ivan"; from["LastName"] = "Petrov"; from["Amount"] = 10; from["Classification"] = "class1"; from["Description"] = null; from["DOB"] = new DateTime(1990, 2, 16); from["GoodPerson"] = true; from["ID"] = "abc"; from["LuckRatio"] = 12345.6789D; from["YearsInSpace"] = 20; from["YearsWithCompany"] = null; var to = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); to["Description"] = "descr"; to["YearsWithCompany"] = 30; from.CopyFields(to); Aver.AreObjectsEqual(to["FirstName"], from["FirstName"]); Aver.AreObjectsEqual(to["LastName"], from["LastName"]); Aver.AreObjectsEqual(to["Amount"], from["Amount"]); Aver.AreObjectsEqual(to["Classification"], from["Classification"]); Aver.AreObjectsEqual(to["Description"], from["Description"]); Aver.AreObjectsEqual(to["DOB"], from["DOB"]); Aver.AreObjectsEqual(to["GoodPerson"], from["GoodPerson"]); Aver.AreObjectsEqual(to["ID"], from["ID"]); Aver.AreObjectsEqual(to["LuckRatio"], from["LuckRatio"]); Aver.AreObjectsEqual(to["YearsInSpace"], from["YearsInSpace"]); Aver.AreObjectsEqual(to["YearsWithCompany"], from["YearsWithCompany"]); }
public void Slim_SerializeTable_DynamicRows() { var tbl = new Table(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); } var ser = new SlimSerializer(); using (var ms = new MemoryStream()) { ser.Serialize(ms, tbl); Console.WriteLine("{0} rows took {1} bytes".Args(tbl.Count, ms.Position)); ms.Position = 0; var tbl2 = ser.Deserialize(ms) as Table; Aver.IsNotNull(tbl2); Aver.IsFalse(object.ReferenceEquals(tbl, tbl2)); Aver.AreEqual(1000, tbl2.Count); Aver.IsTrue(tbl.SequenceEqual(tbl2)); } }
public void DynamicRows() { var tbl = new Table(Schema.GetForTypedDoc(typeof(Person))); var row = new DynamicDoc(tbl.Schema); row["ID"] = "POP1"; row["FirstName"] = "Oleg"; row["LastName"] = "Popov-1"; row["DOB"] = new DateTime(1953, 12, 10); row["YearsInSpace"] = 12; tbl.Insert(row); var ser = new SlimSerializer(); using (var ms = new MemoryStream()) { ser.Serialize(ms, tbl); ms.Position = 0; var tbl2 = ser.Deserialize(ms) as Table; Aver.IsNotNull(tbl2); Aver.IsFalse(object.ReferenceEquals(tbl, tbl2)); Aver.IsFalse(object.ReferenceEquals(tbl.Schema, tbl2.Schema)); Aver.IsTrue(tbl.Schema.IsEquivalentTo(tbl2.Schema)); } }
public static void GetSchemaAndTestFullGDID(ICRUDDataStore store) { var schema = store.GetSchema(new Query("CRUD.Queries.FullGDID.Load")); var row = new DynamicDoc(schema); var key = new GDID(179, 1, 1234567890); Console.WriteLine(key.Bytes.ToDumpString(DumpFormat.Hex)); row["GDID"] = new GDID(179, 1, 1234567890); Console.WriteLine(((byte[])row["GDID"]).ToDumpString(DumpFormat.Hex)); row["VARGDID"] = new GDID(12, 9, 9876543210); row["STRING_NAME"] = "DA DA DA!"; store.Insert(row); var row2 = store.LoadOneDoc(new Query("CRUD.Queries.FullGDID.Load", key, typeof(FullGDID))) as FullGDID; Aver.IsNotNull(row2); Aver.AreEqual(key, row2.GDID); Aver.AreEqual(new GDID(12, 9, 9876543210), row2.VARGDID); Aver.AreObjectsEqual("DA DA DA!", row2["String_Name"]); }
public static void ASYNC_GetSchemaAndTestVariousTypes(ICRUDDataStore store) { var schema = store.GetSchemaAsync(new Query("CRUD.Queries.Types.Load")).Result; var row = new DynamicDoc(schema); row["GDID"] = new GDID(0, 145); row["SCREEN_NAME"] = "User1"; row["STRING_NAME"] = "Some user 1"; row["CHAR_NAME"] = "Some user 2"; row["BOOL_CHAR"] = 'T'; row["BOOL_BOOL"] = true; row["AMOUNT"] = 145670.23m; row["DOB"] = new DateTime(1980, 12, 1); store.Insert(row); var row2 = store.LoadOneDoc(new Query("CRUD.Queries.Types.Load", new GDID(0, 145))); Aver.IsNotNull(row2); Aver.AreObjectsEqual(145, row2["GDID"].AsInt()); Aver.AreObjectsEqual("User1", row2["Screen_Name"]); Aver.AreObjectsEqual("Some user 1", row2["String_Name"]); Aver.AreObjectsEqual("Some user 2", row2["Char_Name"]); Aver.AreEqual(true, row2["BOOL_Char"].AsBool()); Aver.AreEqual(true, row2["BOOL_BOOL"].AsBool()); Aver.AreObjectsEqual(145670.23m, row2["Amount"]); Aver.AreEqual(1980, row2["DOB"].AsDateTime().Year); }
public static void ASYNC_QueryInsertQuery(ICRUDDataStore store) { var query = new Query("CRUD.Queries.Patient.List") { new Query.Param("LN", "%loff") }; var task = store.LoadAsync(query); Aver.AreEqual(1, task.Result.Count); var rowset = task.Result[0]; Aver.AreEqual(0, rowset.Count); var row = new DynamicDoc(rowset.Schema); row["ssn"] = "999-88-9012"; row["First_Name"] = "Jack"; row["Last_Name"] = "Kozloff"; row["DOB"] = new DateTime(1980, 1, 12); Aver.IsNull(row.Validate()); store.InsertAsync(row).Wait(); task = store.LoadAsync(query); Aver.AreEqual(1, task.Result.Count); rowset = task.Result[0]; Aver.AreEqual(1, rowset.Count); Aver.AreObjectsEqual("Jack", rowset[0]["First_Name"]); }
public void PopulateAndFindKey_DynamicRows() { var tbl = new Table(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 void InferSchema() { var doc = new BSONDocument(); doc.Set(new BSONStringElement("FullName", "Alex Bobby")); doc.Set(new BSONInt32Element("Age", 123)); doc.Set(new BSONBooleanElement("IsGood", true)); var c = new DataDocConverter(); var schema = c.InferSchemaFromBSONDocument(doc); Aver.AreEqual(3, schema.FieldCount); Aver.AreEqual(0, schema["FullName"].Order); Aver.AreEqual(1, schema["Age"].Order); Aver.AreEqual(2, schema["IsGood"].Order); Aver.AreObjectsEqual(typeof(object), schema["FullName"].NonNullableType); Aver.AreObjectsEqual(typeof(object), schema["Age"].NonNullableType); Aver.AreObjectsEqual(typeof(object), schema["IsGood"].NonNullableType); var row = new DynamicDoc(schema); c.BSONDocumentToDataDoc(doc, row, null); Aver.AreObjectsEqual("Alex Bobby", row[0]); Aver.AreObjectsEqual(123, row[1]); Aver.AreObjectsEqual(true, row[2]); Aver.AreObjectsEqual("Alex Bobby", row["FullName"]); Aver.AreObjectsEqual(123, row["Age"]); Aver.AreObjectsEqual(true, row["IsGood"]); }
public void ToDynamicRow_FromString() { var str = @"{name: ""Orlov"", dob: ""02/12/2007 6:45 PM"", certified: true, serviceyears: 12, salary: 145000}"; var row = new DynamicDoc(Schema.GetForTypedDoc(typeof(MySimpleData))); JsonReader.ToDoc(row, str.JsonToDataObject() as JsonDataMap); Aver.AreObjectsEqual("Orlov", row["Name"]); Aver.AreObjectsEqual(new DateTime(2007, 2, 12, 18, 45, 0), row["DOB"]); Aver.AreObjectsEqual(true, row["Certified"]); Aver.AreObjectsEqual(12, row["ServiceYears"]); Aver.AreObjectsEqual(145000m, row["Salary"]); }
public void GetSchema_ROW_JSON_ROW() { var data = new byte[] { 0x00, 0x79, 0x14 }; var row = new MyPerzon { GDID = new GDID(1, 1, 980), Name = "Lenin Grib", Age = 100, Data = data }; m_Store.Insert(row); var qry = new Query("CRUD.LoadPerzon", typeof(MyPerzon)) { new Query.Param("id", new GDID(1, 1, 980)) }; var schema = m_Store.GetSchema(qry); Aver.IsNotNull(schema); Aver.AreEqual(4, schema.FieldCount); Aver.AreEqual(0, schema["_id"].Order); Aver.AreEqual(1, schema["Name"].Order); Aver.AreEqual(2, schema["Age"].Order); Aver.AreEqual(3, schema["Data"].Order); var row2 = new DynamicDoc(schema);//Notice: We are creating dynamic row with schema taken from Mongo row2["_id"] = new GDID(10, 10, 10); row2["Name"] = "Kozloff"; row2["Age"] = "199"; row2["Data"] = data; var json = row2.ToJSON(JSONWritingOptions.PrettyPrintRowsAsMap); Console.WriteLine(json); var dyn = json.JSONToDynamic(); Aver.AreEqual(4, dyn.Data.Count); Aver.AreEqual("10:10:10", dyn._id); Aver.AreEqual("Kozloff", dyn.Name); Aver.AreEqual("199", dyn.Age); //todo: how to check dynamic row with 'Data' name? dyn.Data is the collection of all kvp ((JSONDataMap)dyn.Data)["Data"] is JSONDataArray //Aver.AreEqual(data, dyn.Data); }
public void Validate_Error_DateTimeMinMax_DifferentTarget() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1899, 12, 10); person["YearsInSpace"] = 45; person["Amount"] = 100; var error = person.Validate("sparta_system"); Aver.IsNull(error); }
public void Validate_Error_StringRequired() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = null; person["DOB"] = new DateTime(1953, 12, 10); person["YearsInSpace"] = 12; var error = person.Validate(); Console.WriteLine(error); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("LastName", ((FieldValidationException)error).FieldName); }
public void BuildUsingTypedSchema() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1953, 12, 10); person["YearsInSpace"] = 12; Aver.AreObjectsEqual("POP1", person["ID"]); Aver.AreObjectsEqual("Oleg", person["FirstName"]); Aver.AreObjectsEqual("Popov", person["LastName"]); Aver.AreObjectsEqual(new DateTime(1953, 12, 10), person["DOB"]); Aver.AreObjectsEqual(12, person["YearsInSpace"]); }
public void Validate_Error_NullableIntRequired() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1953, 12, 10); // person["YearsInSpace"] = 12; NOT SET!!! var error = person.Validate(); error?.Message.See(); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("YearsInSpace", ((FieldValidationException)error).FieldName); }
public void Validate_Error_DateTimeMinMax_1() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1899, 12, 10); person["YearsInSpace"] = 45; person["Amount"] = 100; var error = person.Validate(); error?.Message.See(); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("DOB", ((FieldValidationException)error).FieldName); Aver.IsTrue(error.Message.Contains("is below")); }
public void Validate_Error_DecimalMinMax_2() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1953, 12, 10); person["YearsInSpace"] = 45; person["Amount"] = 2000000; var error = person.Validate(); Console.WriteLine(error); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("Amount", ((FieldValidationException)error).FieldName); Aver.IsTrue(error.Message.Contains("is above")); }
public void Validate_Error_MaxLength() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1981, 2, 12); person["YearsInSpace"] = 45; person["Amount"] = 100; person["Description"] = "0123456789012345678901234567890"; var error = person.Validate(); error?.Message.See(); Aver.IsTrue(error is FieldValidationException); Aver.AreEqual("Description", ((FieldValidationException)error).FieldName); Aver.IsTrue(error.Message.Contains("exceeds max length")); }
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 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 person = new DynamicDoc(schema); person["ID"] = 123; person["Description"] = "Tank"; Aver.AreObjectsEqual(123, person["ID"]); Aver.AreObjectsEqual("Tank", person["Description"]); }
public void SetGetAndValidate_NoError() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1953, 12, 10); person["YearsInSpace"] = 12; var error = person.Validate(); Aver.IsNull(error); Aver.AreObjectsEqual("POP1", person["ID"]); Aver.AreObjectsEqual("Oleg", person["FirstName"]); Aver.AreObjectsEqual("Popov", person["LastName"]); Aver.AreObjectsEqual(new DateTime(1953, 12, 10), person["DOB"]); Aver.AreObjectsEqual(12, person["YearsInSpace"]); }
public void CopyFields_AmorphousDynamicRow_To_DynamicRow() { var from = new AmorphousDynamicDoc(Schema.GetForTypedDoc(typeof(Person))); from["FirstName"] = "Ivan"; from["LuckRatio"] = 12345.6789D; from.AmorphousData["field1"] = "some data"; var to = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); to["Description"] = "descr"; to["YearsWithCompany"] = 30; from.CopyFields(to); Aver.AreObjectsEqual(to["FirstName"], from["FirstName"]); Aver.AreObjectsEqual(to["LuckRatio"], from["LuckRatio"]); Aver.AreObjectsEqual(to["Description"], from["Description"]); Aver.AreObjectsEqual(to["YearsWithCompany"], from["YearsWithCompany"]); Aver.AreObjectsEqual(null, to.Schema["field1"]); }
public void SetValuesAsDifferentTypes() { var person = new DynamicDoc(Schema.GetForTypedDoc(typeof(Person))); person["ID"] = "POP1"; person["FirstName"] = "Oleg"; person["LastName"] = "Popov"; person["DOB"] = new DateTime(1953, 12, 10); person["YearsInSpace"] = 12; Aver.AreObjectsEqual("POP1", person["ID"]); Aver.AreObjectsEqual("Oleg", person["FirstName"]); Aver.AreObjectsEqual("Popov", person["LastName"]); Aver.AreObjectsEqual(new DateTime(1953, 12, 10), person["DOB"]); Aver.AreObjectsEqual(12, person["YearsInSpace"]); person["DOB"] = "05/15/2009 18:00"; Aver.AreObjectsEqual(new DateTime(2009, 5, 15, 18, 0, 0), person["DOB"]); person["DOB"] = null; Aver.IsNull(person["DOB"]); person["YearsInSpace"] = "-190"; Aver.AreObjectsEqual(-190, person["YearsInSpace"]); person["Description"] = 2 + 2; Aver.AreObjectsEqual("4", person["Description"]); person["Amount"] = "180.12"; Aver.AreObjectsEqual(180.12m, person["Amount"]); person["GoodPerson"] = "true"; Aver.AreObjectsEqual(true, person["GoodPerson"]); person["LuckRatio"] = 123; Aver.AreObjectsEqual(123d, person["LuckRatio"]); }
public void T_09_DynamicRow() { var BYTES = new byte[] { 0x00, 0x79, 0x14 }; var schema = new Schema("Dynamic Schema", 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) }), new Schema.FieldDef("Bytes", typeof(byte[]), new List <FieldAttribute> { new FieldAttribute(required: true) }) ); var row = new DynamicDoc(schema); row["ID"] = 123; row["Description"] = "T-90 Tank"; row["Bytes"] = BYTES; var rc = new DataDocConverter(); var doc = rc.DataDocToBSONDocument(row, "A"); Console.WriteLine(doc.ToString()); var row2 = new DynamicDoc(schema); rc.BSONDocumentToDataDoc(doc, row2, "A"); Aver.AreObjectsEqual(123, row2["ID"]); Aver.AreObjectsEqual("T-90 Tank", row2["Description"]); Aver.IsTrue(BYTES.SequenceEqual((byte[])row2["Bytes"])); }