public void TestSubPropSerializingAndDeserializing() { var parentProp = new WzProperty(); var subProp = new WzProperty(); parentProp.Set("sub", subProp); var ms = new MemoryStream(); var aw = new ArchiveWriter(ms); parentProp.Write(aw); ms.Position = 0; var outProp = new WzProperty(); outProp.Read(new ArchiveReader(ms)); Assert.IsTrue(outProp.HasChild("sub")); Assert.IsInstanceOfType(outProp["sub"], typeof(WzProperty)); }
public void TestPrimitiveSerializingAndDeserializing() { var prop = new WzProperty(); prop.Set("byte", (byte)0xaf); prop.Set("sbyte", (sbyte)0x7a); prop.Set("ushort", (ushort)0xaaff); prop.Set("uint", (uint)0xaaffaaff); prop.Set("ulong", (ulong)0xaaffaaffaaffaaff); prop.Set("short", (short)0x7aff); prop.Set("int", (int)0x7affaaff); prop.Set("long", (long)0x7affaaffaaffaaff); prop.Set("l", (long)0x7affaaffaaffaaff); prop.Set("single", (Single)1234.6789f); prop.Set("double", (Double)1234.6789d); prop.Set("ascii", "test1234"); prop.Set("unicode", "hurr emoji 😋"); prop.Set("null", null); prop.Set("dt", DateTime.Now); var testEncryptions = EncryptionTest.TestEncryptions(); foreach (var testEncryption in testEncryptions) { using (var ms = new MemoryStream()) using (var aw = new ArchiveWriter(ms)) { aw.Encryption = testEncryption; prop.Write(aw); ms.Position = 0; var outProp = new WzProperty(); var ar = new ArchiveReader(ms); ar.SetEncryption(testEncryption); outProp.Read(ar); foreach (var kvp in outProp) { Console.WriteLine("Got key {0} of {1}", kvp.Key, testEncryption); } foreach (var kvp in prop) { Console.WriteLine("Checking key {0} of {1}", kvp.Key, testEncryption); var hasKey = outProp.HasChild(kvp.Key); Assert.IsTrue(hasKey, $"Missing key {kvp.Key}"); if (hasKey) { Assert.AreEqual(kvp.Value, outProp[kvp.Key], $"Unequal values! {kvp.Key} {kvp.Value}"); } } } } }