public void TestBooleanDeserialization() { string raw = "singleT:true,singleF:false,embedded:(singleT:true,singleF:false),array:[true,false]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["singleT"].GetType() == typeof(bool)); Assert.IsTrue((bool)record.Fields["singleT"] == true); Assert.IsTrue(record.Fields["singleF"].GetType() == typeof(bool)); Assert.IsTrue((bool)record.Fields["singleF"] == false); Dictionary<string, object> embedded = (Dictionary<string, object>)record.Fields["embedded"]; Assert.IsTrue(embedded["singleT"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["singleT"] == true); Assert.IsTrue(embedded["singleF"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["singleF"] == false); List<object> array = (List<object>)record.Fields["array"]; Assert.IsTrue(array.First().GetType() == typeof(bool)); Assert.IsTrue((bool)array.First() == true); Assert.IsTrue(array.Last().GetType() == typeof(bool)); Assert.IsTrue((bool)array.Last() == false); }
public static ORecord DeserializeRecord(DtoRecord record) { ORecord deserializedRecord = new ORecord(record); if (record.Type != ORecordType.Document) { return deserializedRecord; } string recordString = BinaryParser.ToString(record.Content).Trim(); int atIndex = recordString.IndexOf('@'); int colonIndex = recordString.IndexOf(':'); int index = 0; // parse class name if ((atIndex != -1) && (atIndex < colonIndex)) { deserializedRecord.Class = recordString.Substring(0, atIndex); index = atIndex + 1; } else { deserializedRecord.Class = ""; } // start document parsing with first field name do { index = ParseFieldName(index, recordString, deserializedRecord.Fields); } while (index < recordString.Length); return deserializedRecord; }
public void ShouldSerializeNumbers() { string recordString = "TestClass@ByteNumber:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c,embedded:(ByteNumber:123b,ShortNumber:1234s,IntNumber:123456,LongNumber:12345678901l,FloatNumber:3.14f,DoubleNumber:3.14d,DecimalNumber:1234567.8901c)"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField("ByteNumber", byte.Parse("123")); record.SetField("ShortNumber", short.Parse("1234")); record.SetField("IntNumber", 123456); record.SetField("LongNumber", 12345678901); record.SetField("FloatNumber", 3.14f); record.SetField("DoubleNumber", 3.14); record.SetField("DecimalNumber", new Decimal(1234567.8901)); record.SetField("embedded.ByteNumber", byte.Parse("123")); record.SetField("embedded.ShortNumber", short.Parse("1234")); record.SetField("embedded.IntNumber", 123456); record.SetField("embedded.LongNumber", 12345678901); record.SetField("embedded.FloatNumber", 3.14f); record.SetField("embedded.DoubleNumber", 3.14); record.SetField("embedded.DecimalNumber", new Decimal(1234567.8901)); string serializedRecord = record.Serialize(); Assert.AreEqual(serializedRecord, recordString); }
internal static ORecord ToRecord(ORID orid, int version, ORecordType type, short classId, byte[] rawRecord) { ORecord record = new ORecord(orid, version, type, classId); string recordString = BinarySerializer.ToString(rawRecord).Trim(); int atIndex = recordString.IndexOf('@'); int colonIndex = recordString.IndexOf(':'); int index = 0; // parse class name if ((atIndex != -1) && (atIndex < colonIndex)) { record.ClassName = recordString.Substring(0, atIndex); index = atIndex + 1; } // start document parsing with first field name do { index = ParseFieldName(index, recordString, record.Document); } while (index < recordString.Length); return record; }
public void ShouldSerializeNull() { string recordString = "TestClass@null:,embedded:(null:)"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField<object>("null", null); record.SetField<object>("embedded.null", null); string serializedRecord = record.Serialize(); Assert.AreEqual(serializedRecord, recordString); }
public void TestBinaryDeserialization() { string raw = "single:_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_,embedded:(binary:_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_),array:[_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_,_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["single"].GetType() == typeof(byte[])); Assert.IsTrue(((Dictionary<string, object>)record.Fields["embedded"])["binary"].GetType() == typeof(byte[])); foreach (object item in (List<object>)record.Fields["array"]) { Assert.IsTrue(item.GetType() == typeof(byte[])); } }
public void ShouldDeserializeDocComplexExample() { string recordString = "name:\"ORole\"," + "id:0," + "defaultClusterId:3," + "clusterIds:[3]," + "properties:[" + "(name:\"mode\",type:17,offset:0,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:,index:)," + "(name:\"rules\",type:12,offset:1,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:17,index:)" + "]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("name"), true); Assert.AreEqual(record.HasField("id"), true); Assert.AreEqual(record.HasField("defaultClusterId"), true); Assert.AreEqual(record.HasField("clusterIds"), true); Assert.AreEqual(record.HasField("properties"), true); // check for fields values Assert.AreEqual(record.GetField<string>("name"), "ORole"); Assert.AreEqual(record.GetField<int>("id"), 0); Assert.AreEqual(record.GetField<int>("defaultClusterId"), 3); Assert.AreEqual(record.GetField<List<int>>("clusterIds").Count, 1); Assert.AreEqual(record.GetField<List<int>>("clusterIds")[0], 3); List<DocComplexExampleEmbedded> loadedProperties = record.GetField<List<DocComplexExampleEmbedded>>("properties"); List<DocComplexExampleEmbedded> properties = new List<DocComplexExampleEmbedded>(); properties.Add(new DocComplexExampleEmbedded() { name = "mode", type = 17, offset = 0, mandatory = false, notNull = false, min = null, max = null, linkedClass = null, linkedType = null, index = null }); properties.Add(new DocComplexExampleEmbedded() { name = "rules", type = 12, offset = 1, mandatory = false, notNull = false, min = null, max = null, linkedClass = null, linkedType = 17, index = null }); Assert.AreEqual(loadedProperties.Count, properties.Count); for (int i = 0; i < loadedProperties.Count; i++) { Assert.AreEqual(loadedProperties[i].name, properties[i].name); Assert.AreEqual(loadedProperties[i].type, properties[i].type); Assert.AreEqual(loadedProperties[i].offset, properties[i].offset); Assert.AreEqual(loadedProperties[i].mandatory, properties[i].mandatory); Assert.AreEqual(loadedProperties[i].notNull, properties[i].notNull); Assert.AreEqual(loadedProperties[i].min, properties[i].min); Assert.AreEqual(loadedProperties[i].max, properties[i].max); Assert.AreEqual(loadedProperties[i].linkedClass, properties[i].linkedClass); Assert.AreEqual(loadedProperties[i].linkedType, properties[i].linkedType); Assert.AreEqual(loadedProperties[i].index, properties[i].index); } }
public void ShouldSerializeBoolean() { string recordString = "TestClass@isTrue:true,isFalse:false,embedded:(isTrue:true,isFalse:false),array:[true,false]"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField("isTrue", true); record.SetField("isFalse", false); record.SetField("embedded.isTrue", true); record.SetField("embedded.isFalse", false); record.SetField<List<bool>>("array", new List<bool> { true, false }); string serializedRecord = record.Serialize(); Assert.AreEqual(serializedRecord, recordString); }
/// <summary> /// Gets the result message data. /// </summary> /// <param name="resultData">The result data.</param> /// <returns></returns> private static string GetResultMessageData(string resultData) { List <string> resultsDataList = new List <string>(); List <string> errorCodes = new List <string>(); for (int index = 0; index < resultData.Length; index = index + 200) { resultsDataList.Add(resultData.Substring(index, 200)); } foreach (string result in resultsDataList) { switch (result.Substring(0, 1).ToUpper(CultureInfo.InvariantCulture)) { case "M": MRecord mRecord = new MRecord().Convert(result); errorCodes = errorCodes.Union(mRecord.ClaimRejectionReasons.Union(mRecord.ClaimDenialReasons) .Union(mRecord.ClaimBackToProviderReasons)).ToList(); break; case "N": NRecord nRecord = new NRecord().Convert(result); errorCodes = errorCodes.Union(nRecord.ClaimSuspensionReasons.Union(nRecord.LineRejectionReasons) .Union(nRecord.LineDenialReasons)).ToList(); break; case "O": ORecord oRecord = new ORecord().Convert(result); errorCodes = errorCodes.Union(oRecord.Diagnosis1.Union(oRecord.Diagnosis2) .Union(oRecord.Diagnosis3).Union(oRecord.Diagnosis4).Union(oRecord.Diagnosis5)).ToList(); break; case "R": RRecord rRecord = new RRecord().Convert(result); errorCodes = errorCodes.Union(rRecord.ProcedureEdits).ToList(); break; case "S": SRecord sRecord = new SRecord().Convert(result); errorCodes = errorCodes.Union(sRecord.Modifier1.Union(sRecord.Modifier2) .Union(sRecord.Modifier3).Union(sRecord.Modifier4).Union(sRecord.Modifier5).Union(sRecord.DateEdit).Union(sRecord.RevenueEdit)).ToList(); break; } } return(FilteredCodes(errorCodes)); }
public void ShouldSerializeDateTime() { DateTime dateTime = DateTime.Now; // get Unix time version DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); string timeString = ((long)((DateTime)dateTime - unixEpoch).TotalMilliseconds).ToString(); string recordString = "TestClass@DateTime:" + timeString + "t,embedded:(DateTime:" + timeString + "t)"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField("DateTime", dateTime); record.SetField("embedded.DateTime", dateTime); string serializedRecord = record.Serialize(); Assert.AreEqual(serializedRecord, recordString); }
public void ShouldDeserializeDocSimpleExample() { string recordString = "Profile@nick:\"ThePresident\",follows:[],followers:[#10:5,#10:6],name:\"Barack\",surname:\"Obama\",location:#3:2,invitedBy:,salary_cloned:,salary:120.3f"; ORecord record = new ORecord(recordString); Assert.AreEqual(record.ClassName, "Profile"); // check for fields existence Assert.AreEqual(record.HasField("nick"), true); Assert.AreEqual(record.HasField("follows"), true); Assert.AreEqual(record.HasField("followers"), true); Assert.AreEqual(record.HasField("name"), true); Assert.AreEqual(record.HasField("surname"), true); Assert.AreEqual(record.HasField("location"), true); Assert.AreEqual(record.HasField("invitedBy"), true); Assert.AreEqual(record.HasField("salary_cloned"), true); Assert.AreEqual(record.HasField("salary"), true); // check for fields values Assert.AreEqual(record.GetField<string>("nick"), "ThePresident"); Assert.AreEqual(record.GetField<List<object>>("follows").Count, new List<object>().Count); List<ORID> recordFollowers = record.GetField<List<ORID>>("followers"); List<ORID> followers = new List<ORID> { new ORID("#10:5"), new ORID("#10:6") }; Assert.AreEqual(recordFollowers.Count, followers.Count); Assert.AreEqual(recordFollowers[0], followers[0]); Assert.AreEqual(recordFollowers[1], followers[1]); Assert.AreEqual(record.GetField<string>("name"), "Barack"); Assert.AreEqual(record.GetField<string>("surname"), "Obama"); Assert.AreEqual(record.GetField<ORID>("location"), new ORID("#3:2")); Assert.AreEqual(record.GetField<string>("invitedBy"), null); Assert.AreEqual(record.GetField<string>("salary_cloned"), null); Assert.AreEqual(record.GetField<float>("salary"), 120.3f); }
internal static ORecord ToRecord(string recordString) { ORecord record = new ORecord(); int atIndex = recordString.IndexOf('@'); int colonIndex = recordString.IndexOf(':'); int index = 0; // parse class name if ((atIndex != -1) && (atIndex < colonIndex)) { record.ClassName = recordString.Substring(0, atIndex); index = atIndex + 1; } // start document parsing with first field name do { index = ParseFieldName(index, recordString, record.Document); } while (index < recordString.Length); return record; }
public void ShouldDeserializeNumbers() { string recordString = "byte:123b,short:23456s,int:1543345,long:13243432455l,float:1234.432f,double:123123.4324d,bigdecimal:300.5c,embedded:(byte:123b,short:23456s,int:1543345,long:13243432455l,float:1234.432f,double:123123.4324d,bigdecimal:300.5c),array:[123b,23456s,1543345,13243432455l,1234.432f,123123.4324d,300.5c]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("byte"), true); Assert.AreEqual(record.HasField("short"), true); Assert.AreEqual(record.HasField("int"), true); Assert.AreEqual(record.HasField("long"), true); Assert.AreEqual(record.HasField("float"), true); Assert.AreEqual(record.HasField("double"), true); Assert.AreEqual(record.HasField("bigdecimal"), true); Assert.AreEqual(record.HasField("embedded.byte"), true); Assert.AreEqual(record.HasField("embedded.short"), true); Assert.AreEqual(record.HasField("embedded.int"), true); Assert.AreEqual(record.HasField("embedded.long"), true); Assert.AreEqual(record.HasField("embedded.float"), true); Assert.AreEqual(record.HasField("embedded.double"), true); Assert.AreEqual(record.HasField("embedded.bigdecimal"), true); Assert.AreEqual(record.HasField("array"), true); // check for fields values Assert.AreEqual(record.GetField<byte>("byte"), (byte)123); Assert.AreEqual(record.GetField<short>("short"), (short)23456); Assert.AreEqual(record.GetField<int>("int"), 1543345); Assert.AreEqual(record.GetField<long>("long"), 13243432455); Assert.AreEqual(record.GetField<float>("float"), 1234.432f); Assert.AreEqual(record.GetField<double>("double"), 123123.4324); Assert.AreEqual(record.GetField<decimal>("bigdecimal"), 300.5m); Assert.AreEqual(record.GetField<byte>("embedded.byte"), (byte)123); Assert.AreEqual(record.GetField<short>("embedded.short"), (short)23456); Assert.AreEqual(record.GetField<int>("embedded.int"), 1543345); Assert.AreEqual(record.GetField<long>("embedded.long"), 13243432455); Assert.AreEqual(record.GetField<float>("embedded.float"), 1234.432f); Assert.AreEqual(record.GetField<double>("embedded.double"), 123123.4324); Assert.AreEqual(record.GetField<decimal>("embedded.bigdecimal"), 300.5m); List<object> array = record.GetField<List<object>>("array"); Assert.AreEqual(array.Count, 7); Assert.AreEqual(array[0], (byte)123); Assert.AreEqual(array[1], (short)23456); Assert.AreEqual(array[2], 1543345); Assert.AreEqual(array[3], 13243432455); Assert.AreEqual(array[4], 1234.432f); Assert.AreEqual(array[5], 123123.4324); Assert.AreEqual(array[6], 300.5m); }
public void ShouldDeserializeNull() { string recordString = "nick:,embedded:(nick:,joe:),joe:"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("nick"), true); Assert.AreEqual(record.HasField("embedded.nick"), true); Assert.AreEqual(record.HasField("embedded.joe"), true); Assert.AreEqual(record.HasField("joe"), true); // check for fields values Assert.AreEqual(record.GetField<string>("nick"), null); Assert.AreEqual(record.GetField<string>("embedded.nick"), null); Assert.AreEqual(record.GetField<string>("embedded.joe"), null); Assert.AreEqual(record.GetField<string>("joe"), null); }
public void ShouldDeserializeBoolean() { string recordString = "singleT:true,singleF:false,embedded:(singleT:true,singleF:false),array:[true,false]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("singleT"), true); Assert.AreEqual(record.HasField("singleF"), true); Assert.AreEqual(record.HasField("embedded.singleT"), true); Assert.AreEqual(record.HasField("embedded.singleF"), true); Assert.AreEqual(record.HasField("array"), true); // check for fields values Assert.AreEqual(record.GetField<bool>("singleT"), true); Assert.AreEqual(record.GetField<bool>("singleF"), false); Assert.AreEqual(record.GetField<bool>("embedded.singleT"), true); Assert.AreEqual(record.GetField<bool>("embedded.singleF"), false); List<bool> array = record.GetField<List<bool>>("array"); Assert.AreEqual(array.Count, 2); Assert.AreEqual(array[0], true); Assert.AreEqual(array[1], false); }
public void ShouldDeserializeDateTime() { string recordString = "datetime:1296279468000t,date:1306281600000a,embedded:(datetime:1296279468000t,date:1306281600000a),array:[1296279468000t,1306281600000a]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("datetime"), true); Assert.AreEqual(record.HasField("date"), true); Assert.AreEqual(record.HasField("embedded.datetime"), true); Assert.AreEqual(record.HasField("embedded.date"), true); Assert.AreEqual(record.HasField("array"), true); // check for fields values Assert.AreEqual(record.GetField<DateTime>("datetime"), new DateTime(2011, 1, 29, 5, 37, 48)); Assert.AreEqual(record.GetField<DateTime>("date"), new DateTime(2011, 5, 25, 0, 0, 0)); Assert.AreEqual(record.GetField<DateTime>("embedded.datetime"), new DateTime(2011, 1, 29, 5, 37, 48)); Assert.AreEqual(record.GetField<DateTime>("embedded.date"), new DateTime(2011, 5, 25, 0, 0, 0)); List<DateTime> array = record.GetField<List<DateTime>>("array"); Assert.AreEqual(array.Count, 2); Assert.AreEqual(array[0], new DateTime(2011, 1, 29, 5, 37, 48)); Assert.AreEqual(array[1], new DateTime(2011, 5, 25, 0, 0, 0)); }
public void TestWikiExample3Deserialization() { string raw = "ORole@name:\"reader\",inheritedRole:,mode:0,rules:{\"database\":2,\"database.cluster.internal\":2,\"database.cluster.orole\":2,\"database.cluster.ouser\":2,\"database.class.*\":2,\"database.cluster.*\":2,\"database.query\":2,\"database.command\":2,\"database.hook.record\":2}"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Class == "ORole"); Assert.IsTrue(record.Fields["name"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["name"] == "reader"); Assert.IsTrue(record.Fields["inheritedRole"] == null); Assert.IsTrue(record.Fields["mode"].GetType() == typeof(int)); Assert.IsTrue((int)record.Fields["mode"] == 0); Assert.IsTrue(record.Fields["rules"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["rules"] == "{\"database\":2,\"database.cluster.internal\":2,\"database.cluster.orole\":2,\"database.cluster.ouser\":2,\"database.class.*\":2,\"database.cluster.*\":2,\"database.query\":2,\"database.command\":2,\"database.hook.record\":2}"); }
public void TestWikiExample2Deserialization() { string raw = "name:\"ORole\",id:0,defaultClusterId:3,clusterIds:[3],properties:[(name:\"mode\",type:17,offset:0,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:,index:),(name:\"rules\",type:12,offset:1,mandatory:false,notNull:false,min:,max:,linkedClass:,linkedType:17,index:)]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["name"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["name"] == "ORole"); Assert.IsTrue(record.Fields["id"].GetType() == typeof(int)); Assert.IsTrue((int)record.Fields["id"] == 0); Assert.IsTrue(record.Fields["defaultClusterId"].GetType() == typeof(int)); Assert.IsTrue((int)record.Fields["defaultClusterId"] == 3); Assert.IsTrue(record.Fields["properties"].GetType() == typeof(List<object>)); List<object> properties = (List<object>)record.Fields["properties"]; Dictionary<string, object> embedded = (Dictionary<string, object>)properties[0]; Assert.IsTrue(embedded["name"].GetType() == typeof(string)); Assert.IsTrue((string)embedded["name"] == "mode"); Assert.IsTrue(embedded["type"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["type"] == 17); Assert.IsTrue(embedded["offset"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["offset"] == 0); Assert.IsTrue(embedded["mandatory"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["mandatory"] == false); Assert.IsTrue(embedded["notNull"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["notNull"] == false); Assert.IsTrue(embedded["min"] == null); Assert.IsTrue(embedded["max"] == null); Assert.IsTrue(embedded["linkedClass"] == null); Assert.IsTrue(embedded["linkedType"] == null); Assert.IsTrue(embedded["index"] == null); embedded = (Dictionary<string, object>)properties[1]; Assert.IsTrue(embedded["name"].GetType() == typeof(string)); Assert.IsTrue((string)embedded["name"] == "rules"); Assert.IsTrue(embedded["type"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["type"] == 12); Assert.IsTrue(embedded["offset"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["offset"] == 1); Assert.IsTrue(embedded["mandatory"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["mandatory"] == false); Assert.IsTrue(embedded["notNull"].GetType() == typeof(bool)); Assert.IsTrue((bool)embedded["notNull"] == false); Assert.IsTrue(embedded["min"] == null); Assert.IsTrue(embedded["max"] == null); Assert.IsTrue(embedded["linkedClass"] == null); Assert.IsTrue(embedded["linkedType"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["linkedType"] == 17); Assert.IsTrue(embedded["index"] == null); }
public void ShouldDeserializeComplexEmbeddedrecordsArray() { string recordString = "array:[(zak1:(nick:[(joe1:\"js1\"),(joe2:\"js2\"),(joe3:\"js3\")])),(zak2:(nick:[(joe4:\"js4\"),(joe5:\"js5\"),(joe6:\"js6\")]))]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("array"), true); // check for fields values List<ODocument> arrayOfZaks = record.GetField<List<ODocument>>("array"); Assert.AreEqual(arrayOfZaks.Count, 2); List<ODocument> arrayOfJoes1 = arrayOfZaks[0].GetField<List<ODocument>>("zak1.nick"); Assert.AreEqual(arrayOfJoes1.Count, 3); Assert.AreEqual(arrayOfJoes1[0].GetField<string>("joe1"), "js1"); Assert.AreEqual(arrayOfJoes1[1].GetField<string>("joe2"), "js2"); Assert.AreEqual(arrayOfJoes1[2].GetField<string>("joe3"), "js3"); List<ODocument> arrayOfJoes2 = arrayOfZaks[1].GetField<List<ODocument>>("zak2.nick"); Assert.AreEqual(arrayOfJoes2.Count, 3); Assert.AreEqual(arrayOfJoes2[0].GetField<string>("joe4"), "js4"); Assert.AreEqual(arrayOfJoes2[1].GetField<string>("joe5"), "js5"); Assert.AreEqual(arrayOfJoes2[2].GetField<string>("joe6"), "js6"); }
public void TestSingleAndCollectionOridDeserialization() { string raw = "single:#10:12345,collection:[#11:123,#22:1234,#33:1234567]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["single"].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)record.Fields["single"]).RID == "#10:12345"); Assert.IsTrue(record.Fields["collection"].GetType() == typeof(List<object>)); List<object> collection = (List<object>)record.Fields["collection"]; Assert.IsTrue(collection[0].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)collection[0]).RID == "#11:123"); Assert.IsTrue(collection[1].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)collection[1]).RID == "#22:1234"); Assert.IsTrue(collection[2].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)collection[2]).RID == "#33:1234567"); }
public void TestStringDeserialization() { string raw = "simple:\"whoa this is awesome\",singleQuoted:\"a" + "\\" + "\"\",doubleQuotes:\"" + "\\" + "\"adsf" + "\\" + "\"\",twoBackslashes:\"" + "\\a" + "\\a" + "\""; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["simple"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["simple"] == "whoa this is awesome"); Assert.IsTrue(record.Fields["singleQuoted"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["singleQuoted"] == "a\""); Assert.IsTrue(record.Fields["doubleQuotes"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["doubleQuotes"] == "\"adsf\""); Assert.IsTrue(record.Fields["twoBackslashes"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["twoBackslashes"] == "\\a\\a"); }
public void TestWikiExample1Deserialization() { string raw = "Profile@nick:\"ThePresident\",follows:[],followers:[#10:5,#10:6],name:\"Barack\",surname:\"Obama\",location:#3:2,invitedBy:,salary_cloned:,salary:120.3f"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Class == "Profile"); Assert.IsTrue(record.Fields["nick"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["nick"] == "ThePresident"); Assert.IsTrue(record.Fields["follows"].GetType() == typeof(List<object>)); Assert.IsTrue(record.Fields["followers"].GetType() == typeof(List<object>)); List<object> followers = (List<object>)record.Fields["followers"]; Assert.IsTrue(followers[0].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)followers[0]).RID == "#10:5"); Assert.IsTrue(followers[1].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)followers[1]).RID == "#10:6"); Assert.IsTrue(record.Fields["name"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["name"] == "Barack"); Assert.IsTrue(record.Fields["surname"].GetType() == typeof(string)); Assert.IsTrue((string)record.Fields["surname"] == "Obama"); Assert.IsTrue(record.Fields["location"].GetType() == typeof(ORID)); Assert.IsTrue(((ORID)record.Fields["location"]).RID == "#3:2"); Assert.IsTrue(record.Fields["invitedBy"] == null); Assert.IsTrue(record.Fields["salary_cloned"] == null); Assert.IsTrue(record.Fields["salary"].GetType() == typeof(float)); Assert.IsTrue((float)record.Fields["salary"] == 120.3f); }
public void ShouldSerializeORIDs() { string recordString = "TestClass@Single:#8:0,Array:[#8:1,#8:2],embedded:(Single:#9:0,Array:[#9:1,#9:2])"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField("Single", new ORID(8, 0)); record.SetField("Array", new List<ORID> { new ORID(8, 1), new ORID(8, 2) }); record.SetField("embedded.Single", new ORID(9, 0)); record.SetField("embedded.Array", new List<ORID> { new ORID(9, 1), new ORID(9, 2) }); string serializedString = record.Serialize(); Assert.AreEqual(serializedString, recordString); }
private ORecord ParseRecord(ref int offset, byte[] data) { ORecord record = null; short classId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray()); offset += 2; if (classId == -2) // NULL { } else if (classId == -3) // record id { ORID orid = new ORID(); orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray()); offset += 2; orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray()); offset += 8; record = new ORecord(); record.ORID = orid; } else { ORecordType type = (ORecordType)BinarySerializer.ToByte(data.Skip(offset).Take(1).ToArray()); offset += 1; ORID orid = new ORID(); orid.ClusterId = BinarySerializer.ToShort(data.Skip(offset).Take(2).ToArray()); offset += 2; orid.ClusterPosition = BinarySerializer.ToLong(data.Skip(offset).Take(8).ToArray()); offset += 8; int version = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray()); offset += 4; int recordLength = BinarySerializer.ToInt(data.Skip(offset).Take(4).ToArray()); offset += 4; byte[] rawRecord = data.Skip(offset).Take(recordLength).ToArray(); offset += recordLength; record = RecordSerializer.ToRecord(orid, version, type, classId, rawRecord); } return record; }
public void ShouldDeserializeString() { string recordString = "simple:\"whoa this is awesome\",singleQuoted:\"a" + "\\" + "\"\",doubleQuoted:\"" + "\\" + "\"adsf" + "\\" + "\"\",twoBackslashes:\"" + "\\a" + "\\a" + "\""; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("simple"), true); Assert.AreEqual(record.HasField("singleQuoted"), true); Assert.AreEqual(record.HasField("doubleQuoted"), true); Assert.AreEqual(record.HasField("twoBackslashes"), true); // check for fields values Assert.AreEqual(record.GetField<string>("simple"), "whoa this is awesome"); Assert.AreEqual(record.GetField<string>("singleQuoted"), "a\""); Assert.AreEqual(record.GetField<string>("doubleQuoted"), "\"adsf\""); Assert.AreEqual(record.GetField<string>("twoBackslashes"), "\\a\\a"); }
public void ShouldDeserializeSimpleEmbeddedrecordsArray() { string recordString = "array:[(joe1:\"js1\"),(joe2:\"js2\"),(joe3:\"js3\")]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("array"), true); // check for fields values List<ODocument> array = record.GetField<List<ODocument>>("array"); Assert.AreEqual(array.Count, 3); Assert.AreEqual(array[0].GetField<string>("joe1"), "js1"); Assert.AreEqual(array[1].GetField<string>("joe2"), "js2"); Assert.AreEqual(array[2].GetField<string>("joe3"), "js3"); }
public void TestNumbersDeserialization() { string raw = "byte:123b,short:23456s,int:1543345,long:132432455l,float:1234.432f,double:123123.4324d,bigdecimal:12312.24324c,embedded:(byte:123b,short:23456s,int:1543345,long:132432455l,float:1234.432f,double:123123.4324d,bigdecimal:12312.24324c),array:[123b,23456s,1543345,132432455l,1234.432f,123123.4324d,12312.24324c]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); Assert.IsTrue(record.Fields["byte"].GetType() == typeof(byte)); Assert.IsTrue((byte)record.Fields["byte"] == 123); Assert.IsTrue(record.Fields["short"].GetType() == typeof(short)); Assert.IsTrue((short)record.Fields["short"] == 23456); Assert.IsTrue(record.Fields["int"].GetType() == typeof(int)); Assert.IsTrue((int)record.Fields["int"] == 1543345); Assert.IsTrue(record.Fields["long"].GetType() == typeof(long)); Assert.IsTrue((long)record.Fields["long"] == 132432455); Assert.IsTrue(record.Fields["float"].GetType() == typeof(float)); Assert.IsTrue((float)record.Fields["float"] == 1234.432f); Assert.IsTrue(record.Fields["double"].GetType() == typeof(double)); Assert.IsTrue((double)record.Fields["double"] == 123123.4324); Assert.IsTrue(record.Fields["bigdecimal"].GetType() == typeof(decimal)); Assert.IsTrue((decimal)record.Fields["bigdecimal"] == new Decimal(12312.24324)); Dictionary<string, object> embedded = (Dictionary<string, object>)record.Fields["embedded"]; Assert.IsTrue(embedded["byte"].GetType() == typeof(byte)); Assert.IsTrue((byte)embedded["byte"] == 123); Assert.IsTrue(embedded["short"].GetType() == typeof(short)); Assert.IsTrue((short)embedded["short"] == 23456); Assert.IsTrue(embedded["int"].GetType() == typeof(int)); Assert.IsTrue((int)embedded["int"] == 1543345); Assert.IsTrue(embedded["long"].GetType() == typeof(long)); Assert.IsTrue((long)embedded["long"] == 132432455); Assert.IsTrue(embedded["float"].GetType() == typeof(float)); Assert.IsTrue((float)embedded["float"] == 1234.432f); Assert.IsTrue(embedded["double"].GetType() == typeof(double)); Assert.IsTrue((double)embedded["double"] == 123123.4324); Assert.IsTrue(embedded["bigdecimal"].GetType() == typeof(decimal)); Assert.IsTrue((decimal)embedded["bigdecimal"] == new Decimal(12312.24324)); List<object> array = (List<object>)record.Fields["array"]; Assert.IsTrue(array[0].GetType() == typeof(byte)); Assert.IsTrue((byte)array[0] == 123); Assert.IsTrue(array[1].GetType() == typeof(short)); Assert.IsTrue((short)array[1] == 23456); Assert.IsTrue(array[2].GetType() == typeof(int)); Assert.IsTrue((int)array[2] == 1543345); Assert.IsTrue(array[3].GetType() == typeof(long)); Assert.IsTrue((long)array[3] == 132432455); Assert.IsTrue(array[4].GetType() == typeof(float)); Assert.IsTrue((float)array[4] == 1234.432f); Assert.IsTrue(array[5].GetType() == typeof(double)); Assert.IsTrue((double)array[5] == 123123.4324); Assert.IsTrue(array[6].GetType() == typeof(decimal)); Assert.IsTrue((decimal)array[6] == new Decimal(12312.24324)); }
public void ShouldDeserializeSingleAndCollectionOfOrids() { string recordString = "single:#10:12345,collection:[#11:123,#22:1234,#33:1234567]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("single"), true); Assert.AreEqual(record.HasField("collection"), true); // check for fields values Assert.AreEqual(record.GetField<ORID>("single"), new ORID(10, 12345)); List<ORID> collection = record.GetField<List<ORID>>("collection"); Assert.AreEqual(collection.Count, 3); Assert.AreEqual(collection[0], new ORID(11, 123)); Assert.AreEqual(collection[1], new ORID(22, 1234)); Assert.AreEqual(collection[2], new ORID(33, 1234567)); }
public void ShouldSerializeStrings() { string recordString = "TestClass@String:\"Bra\\" + "\"vo \\\\ asdf\",Array:[\"foo\",\"bar\"],embedded:(String:\"Bra\\" + "\"vo \\\\ asdf\",Array:[\"foo\",\"bar\"])"; ORecord record = new ORecord(); record.ClassName = "TestClass"; record.SetField("String", "Bra\"vo \\ asdf"); record.SetField("Array", new List<string> { "foo", "bar" }); record.SetField("embedded.String", "Bra\"vo \\ asdf"); record.SetField("embedded.Array", new List<string> { "foo", "bar" }); string serializedString = record.Serialize(); Assert.AreEqual(serializedString, recordString); }
public void ShouldDeserializeDocBinary() { string recordString = "single:_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_,embedded:(binary:_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_),array:[_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_,_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGx_]"; ORecord record = new ORecord(recordString); // check for fields existence Assert.AreEqual(record.HasField("single"), true); Assert.AreEqual(record.HasField("embedded"), true); Assert.AreEqual(record.HasField("embedded.binary"), true); Assert.AreEqual(record.HasField("array"), true); // check for fields values Assert.AreEqual(record.GetField<byte[]>("single").GetType(), typeof(byte[])); Assert.AreEqual(record.GetField<byte[]>("embedded.binary").GetType(), typeof(byte[])); List<byte[]> array = record.GetField<List<byte[]>>("array"); Assert.AreEqual(array.Count, 2); Assert.AreEqual(array[0].GetType(), typeof(byte[])); Assert.AreEqual(array[0].GetType(), typeof(byte[])); }
public void TestComplexEmbeddedrecordsArrayDeserialization() { string raw = "mary:[(zak1:(nick:[(joe1:\"js1\"),(joe2:\"js2\"),(joe3:\"s3\")])),(zak2:(nick:[(joe4:\"js4\"),(joe5:\"js5\"),(joe6:\"s6\")]))]"; ORecord record = new ORecord(ORecordType.Document, 0, UTF8Encoding.UTF8.GetBytes(raw)); // mary List<object> array1 = (List<object>)record.Fields["mary"]; // zak1 Dictionary<string, object> embedded1 = (Dictionary<string, object>)array1[0]; // nick Dictionary<string, object> embedded2 = (Dictionary<string, object>)embedded1["zak1"]; List<object> array2 = (List<object>)embedded2["nick"]; Dictionary<string, object> embedded3 = (Dictionary<string, object>)array2[0]; Assert.IsTrue(embedded3["joe1"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe1"] == "js1"); embedded3 = (Dictionary<string, object>)array2[1]; Assert.IsTrue(embedded3["joe2"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe2"] == "js2"); embedded3 = (Dictionary<string, object>)array2[2]; Assert.IsTrue(embedded3["joe3"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe3"] == "s3"); // zak2 embedded1 = (Dictionary<string, object>)array1[1]; // nick embedded2 = (Dictionary<string, object>)embedded1["zak2"]; // joe1 array2 = (List<object>)embedded2["nick"]; embedded3 = (Dictionary<string, object>)array2[0]; Assert.IsTrue(embedded3["joe4"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe4"] == "js4"); embedded3 = (Dictionary<string, object>)array2[1]; Assert.IsTrue(embedded3["joe5"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe5"] == "js5"); embedded3 = (Dictionary<string, object>)array2[2]; Assert.IsTrue(embedded3["joe6"].GetType() == typeof(string)); Assert.IsTrue((string)embedded3["joe6"] == "s6"); }