private static void CompareTransactionsDataRpcObjects(RpcObject expectedRpcObject, RpcObject actualRpcObject) { var expectedKeys = expectedRpcObject.GetKeys().OrderBy(x => x).ToList(); var actualKeys = actualRpcObject.GetKeys().OrderBy(x => x); Assert.True(expectedKeys.SequenceEqual(actualKeys)); foreach (var key in expectedKeys) { var expected = expectedRpcObject.GetItem(key); var actual = actualRpcObject.GetItem(key); if (expected is RpcValue expectedRpcValue && actual is RpcValue actualRpcValue) { Assert.Equal(expectedRpcValue.ToString(), actualRpcValue.ToString()); continue; } if (expected is RpcObject expectedObj && actual is RpcObject actualObj) { CompareTransactionsDataRpcObjects(expectedObj, actualObj); continue; } throw new ArgumentException("Can't compare key values"); } }
private static void SerializeObjectItems(StringBuilder builder, RpcObject @object) { var firstItem = true; foreach (var key in @object.GetKeys().OrderBy(x => x)) { if (firstItem) { firstItem = false; } else { builder.Append("."); } Serialize(builder.Append(key).Append("."), @object.GetItem(key)); } }
private static object FromRpcObject <T>(RpcObject @object) { var type = typeof(T); if (type.IsAssignableFrom(typeof(RpcObject))) { return(@object); } var result = new Dictionary <string, object>(); var keys = @object.GetKeys(); foreach (var key in keys) { var v = FromRpcItem(@object.GetItem(key)); if (v != null) { result[key] = v; } } return(result); }