public void TestTrace() { TraceErrorData ed = new TraceErrorData { Foo = 12, Bar = "abcdefghijklmnopqrstuvwxyz" }; MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, ed); byte[] buffer = ms.GetBuffer(); Assert.AreEqual(30, ms.Length); MemoryStream ms2 = new MemoryStream(); ms2.Write(buffer, 0, (int)ms.Length - 5); ms2.Position = 0; try { Serializer.Deserialize <TraceErrorData>(ms2); Assert.Fail("Should have errored"); } catch (EndOfStreamException ex) { Assert.IsTrue(ex.Data.Contains("protoSource")); Assert.AreEqual("tag=2; wire-type=String; offset=25; depth=1; type=Examples.TraceErrorData", ex.Data["protoSource"]); } catch (Exception ex) { Assert.Fail("Unexpected exception: " + ex); } }
public void TestTrace() { TraceErrorData ed = new TraceErrorData { Foo = 12, Bar = "abcdefghijklmnopqrstuvwxyz" }; var tm0 = TypeModel.Create(); tm0.DeepClone(ed); MemoryStream ms = new MemoryStream(); var tm = TypeModel.Create(false, ProtoCompatibilitySettingsValue.FullCompatibility); tm.Serialize(ms, ed); byte[] buffer = ms.GetBuffer(); Assert.AreEqual(30, ms.Length); MemoryStream ms2 = new MemoryStream(); ms2.Write(buffer, 0, (int)ms.Length - 5); ms2.Position = 0; try { tm.Deserialize <TraceErrorData>(ms2); Assert.Fail("Should have errored"); } catch (EndOfStreamException ex) { Assert.IsTrue(ex.Data.Contains("protoSource"), "Missing protoSource"); Assert.AreEqual("tag=2; wire-type=String; offset=4; depth=0", ex.Data["protoSource"]); } catch (Exception ex) { Assert.Fail("Unexpected exception: " + ex); } }
public void TestTrace() { TraceErrorData ed = new TraceErrorData { Foo = 12, Bar = "abcdefghijklmnopqrstuvwxyz" }; MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, ed); byte[] buffer = ms.GetBuffer(); Assert.Equal(30, ms.Length); using MemoryStream ms2 = new MemoryStream(); ms2.Write(buffer, 0, (int)ms.Length - 5); ms2.Position = 0; var ex = Assert.Throws <EndOfStreamException>(() => { Serializer.Deserialize <TraceErrorData>(ms2); }); Assert.True(ex.Data.Contains("protoSource"), "Missing protoSource"); Assert.Matches(@"tag=2; wire-type=String; offset=\d+; depth=0", (string)ex.Data["protoSource"]); }
public void TestTrace() { TraceErrorData ed = new TraceErrorData {Foo = 12, Bar = "abcdefghijklmnopqrstuvwxyz"}; MemoryStream ms = new MemoryStream(); Serializer.Serialize(ms, ed); byte[] buffer = ms.GetBuffer(); Assert.AreEqual(30, ms.Length); MemoryStream ms2 = new MemoryStream(); ms2.Write(buffer, 0, (int)ms.Length - 5); ms2.Position = 0; try { Serializer.Deserialize<TraceErrorData>(ms2); Assert.Fail("Should have errored"); } catch(EndOfStreamException ex) { Assert.IsTrue(ex.Data.Contains("protoSource")); Assert.AreEqual("tag=2; wire-type=String; offset=25; depth=1; type=Examples.TraceErrorData", ex.Data["protoSource"]); } catch(Exception ex) { Assert.Fail("Unexpected exception: " + ex); } }