Skip to content

Commit

Permalink
#861 Refactor into Bixon tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhabis committed May 10, 2023
1 parent 17374a2 commit d6c8237
Showing 1 changed file with 0 additions and 78 deletions.
78 changes: 0 additions & 78 deletions src/testing/Azos.Tests.Nub/Logging/ArchiveConventionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,83 +91,5 @@ public void SD_Test02()
Aver.AreObjectsEqual(1, decoded["a"]);
Aver.AreObjectsEqual(3, decoded["b"]);
}

[Run]
public void SD_RoundtripAllTypes()
{
using var w = new BixWriterBufferScope(1024);

var map = new JsonDataMap
{
{"null-key", null},
{"str", "string 1"},
{"atom", Atom.Encode("abc")},
{"dt", new DateTime(1980, 2, 3, 14, 10, 05, DateTimeKind.Utc)},
{"tspan", TimeSpan.FromSeconds(15.5)},
{"bin", new byte[]{1,2,3,4,5,6,7,8,9,0,10,20,30,40,50,60,70,80,90,100}},
{"eid", new EntityId(Atom.Encode("sys"), Atom.Encode("type"), Atom.Encode("sch"), "address 1")},
{"gdid", new GDID(1, 190)},
{"rgdid", new RGDID(5, new GDID(7, 2190))},
{"guid", Guid.NewGuid()},

{"bool1", false},
{"bool2", true},

{"byte", (byte)100},
{"sbyte", (sbyte)-100},

{"short", (short)-32000},
{"ushort", (ushort)65534},

{"int", (int)-3200000},
{"uint", (uint)6553400},

{"long", (long)-3200000},
{"ulong", (ulong)6553400},

{"float", -45.1f},
{"double", -7890.0923d},
{"decimal", 185_000.00m},

{"sub-map", new JsonDataMap(){ {"a", 12345}, {"b", null} }},
{"sub-object-anonymous", new { z=1000_000, q=-2, m = Atom.Encode("subobj")} },

{"arr", new object[]{ 1, 2, true, false, "ok", 345, Atom.Encode("zxy")}},
};
ArchiveConventions.WriteArchivedDataMap(w.Writer, map);

w.Buffer.ToHexDump().See();

using var r = new BixReaderBufferScope(w.Buffer);
var got = ArchiveConventions.ReadArchivedDataMap(r.Reader);

got.See(new JsonWritingOptions(JsonWritingOptions.PrettyPrintRowsAsMap){ EnableTypeHints = true });
averMapsEqual(map, got);

Aver.AreEqual(-2, (int)(got["sub-object-anonymous"] as JsonDataMap)["q"]);
Aver.AreEqual(1000_000, (int)(got["sub-object-anonymous"] as JsonDataMap)["z"]);
Aver.AreEqual(Atom.Encode("subobj"), (Atom)(got["sub-object-anonymous"] as JsonDataMap)["m"]);
}


private static void averMapsEqual(JsonDataMap map1, JsonDataMap map2)
{
Aver.AreEqual(map1.Count, map2.Count);

foreach (var kvp in map1)
{
if (kvp.Key== "sub-object-anonymous") continue;

if (kvp.Value is JsonDataMap map)
averMapsEqual(map, (JsonDataMap)map2[kvp.Key]);
else if (kvp.Value is byte[] buf)
Aver.IsTrue(buf.MemBufferEquals((byte[])map2[kvp.Key]));
else if (kvp.Value is object[] oarr)
Aver.IsTrue(oarr.SequenceEqual((IEnumerable<object>)map2[kvp.Key]));
else
Aver.AreObjectsEqual(kvp.Value, map2[kvp.Key]);
}
}

}
}

0 comments on commit d6c8237

Please sign in to comment.