public void TestSegmentIsSerializable() { string segmentName = "test"; string parentId = Entity.GenerateId(); Segment segment = new Segment(segmentName, TraceId, parentId); Exception ex = new ArgumentException("test can't be null"); segment.AddException(ex); segment.SetStartTimeToNow(); segment.SetEndTimeToNow(); string serviceKey = "key1"; string serviceValue = "value1"; segment.Service[serviceKey] = serviceValue; Segment segmentAfterSerialize = (Segment)SerializeAndDeserialize(segment); Assert.AreEqual(segmentName, segmentAfterSerialize.Name); Assert.AreEqual(TraceId, segmentAfterSerialize.TraceId); Assert.AreEqual(parentId, segmentAfterSerialize.ParentId); Assert.AreEqual(ex.Message, segmentAfterSerialize.Cause.ExceptionDescriptors[0].Message); Assert.AreEqual(segmentAfterSerialize.StartTime, segment.StartTime); Assert.AreEqual(segmentAfterSerialize.EndTime, segment.EndTime); Assert.AreEqual(segmentAfterSerialize.Service[serviceKey], segment.Service[serviceKey]); }
public void TestAddException() { var segment = new Segment("test", TraceId); var e = new EntityNotAvailableException("Test someting wrong happens"); segment.AddException(e); Assert.IsTrue(segment.HasFault); Assert.IsFalse(segment.HasError); Assert.IsNotNull(segment.Cause); var descriptor = segment.Cause.ExceptionDescriptors[0]; Assert.AreEqual("Test someting wrong happens", descriptor.Message); Assert.AreEqual("EntityNotAvailableException", descriptor.Type); Assert.ReferenceEquals(e, descriptor.Exception); }