public void TestWriteObject() { // Test writing with the value to write being ignored being null. // ToString cases are tested to a degree with non-constant structs. var testProperties = new TestFlagProperties(); var mockPacketProperty = new MockPacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty4")); var flagPacketProperty = new FlagPacketProperty(mockPacketProperty, null); var writtenProperties = new Dictionary <string, object>(); var bitWriter = new BitWriter(new MemoryStream()); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsFalse(mockPacketProperty.DataWritten); testProperties.TestProperty4 = new TestFlagProperties(); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsTrue(mockPacketProperty.DataWritten); }
public void TestReadDefaultValue() { // Write the test data. var memoryStream = new MemoryStream(); var bitWriter = new BitWriter(memoryStream); bitWriter.WriteBit(false); // Test reading the properties with flags. var testProperties = new TestFlagProperties(); var bitReader = new BitReader(memoryStream); var readProperties = new Dictionary <string, object>(); new FlagPacketProperty(new PacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty1")), -5) .Read(testProperties, bitReader, readProperties, null); Assert.AreEqual(testProperties.TestProperty1, -5); }
public void TestWriteEnum() { // Test writing with the value to write being ignored being null. var testProperties = new TestFlagProperties(); var mockPacketProperty = new MockPacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty3")); var flagPacketProperty = new FlagPacketProperty(mockPacketProperty, null); var writtenProperties = new Dictionary <string, object>(); var bitWriter = new BitWriter(new MemoryStream()); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsFalse(mockPacketProperty.DataWritten); testProperties.TestProperty3 = TestFlagEnum.TestValue3; flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsTrue(mockPacketProperty.DataWritten); mockPacketProperty.DataWritten = false; // Test writing with the value to write being ignored being defined. flagPacketProperty = new FlagPacketProperty(mockPacketProperty, TestFlagEnum.TestValue3); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsFalse(mockPacketProperty.DataWritten); testProperties.TestProperty3 = TestFlagEnum.TestValue2; flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsTrue(mockPacketProperty.DataWritten); }
public void TestWriteNonConstantProperty() { // Test writing with the value to write being ignored being null. var testProperties = new TestFlagProperties(); var mockPacketProperty = new MockPacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty2")); var flagPacketProperty = new FlagPacketProperty(mockPacketProperty, null); var writtenProperties = new Dictionary <string, object>(); var bitWriter = new BitWriter(new MemoryStream()); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsFalse(mockPacketProperty.DataWritten); testProperties.TestProperty2 = new Vector3(2, 2, 2); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsTrue(mockPacketProperty.DataWritten); mockPacketProperty.DataWritten = false; // Test writing with the value to write being ignored being defined. flagPacketProperty = new FlagPacketProperty(mockPacketProperty, "<2, 2, 2>"); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsFalse(mockPacketProperty.DataWritten); testProperties.TestProperty2 = new Vector3(3, 3, 3); flagPacketProperty.Write(testProperties, bitWriter, writtenProperties); Assert.IsTrue(mockPacketProperty.DataWritten); }
public void TestRead() { // Write the test data. var memoryStream = new MemoryStream(); var bitWriter = new BitWriter(memoryStream); bitWriter.WriteBit(true); bitWriter.Write <int>(-5); bitWriter.WriteBit(false); bitWriter.WriteBit(true); bitWriter.Write <int>(1); bitWriter.WriteBit(false); // Test reading the properties with flags. var testProperties = new TestFlagProperties(); var bitReader = new BitReader(memoryStream); var readProperties = new Dictionary <string, object>(); new FlagPacketProperty(new PacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty1")), null) .Read(testProperties, bitReader, readProperties, null); new FlagPacketProperty(new PacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty2")), null) .Read(testProperties, bitReader, readProperties, null); new FlagPacketProperty(new PacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty3")), null) .Read(testProperties, bitReader, readProperties, null); new FlagPacketProperty(new PacketProperty(typeof(TestFlagProperties).GetProperty("TestProperty4")), null) .Read(testProperties, bitReader, readProperties, null); Assert.AreEqual(testProperties.TestProperty1, -5); Assert.AreEqual(testProperties.TestProperty2, Vector3.Zero); Assert.AreEqual(testProperties.TestProperty3, TestFlagEnum.TestValue2); Assert.IsNull(testProperties.TestProperty4); Assert.AreEqual(readProperties, new Dictionary <string, object>() { { "TestProperty1", -5 }, { "TestProperty3", TestFlagEnum.TestValue2 }, }); }