/// <summary>
        /// Create a deep copy of the token.
        /// </summary>
        /// <param name="original">The token to copy</param>
        /// <returns>A copy</returns>
        public static object DeepCopy(object original)
        {
            var source = original as EventHubSequenceTokenV2;
            if (source == null)
            {
                return null;
            }

            var copy = new EventHubSequenceTokenV2(source.EventHubOffset, source.SequenceNumber, source.EventIndex);
            SerializationContext.Current.RecordObject(original, copy);
            return copy;
        }
        public void EventHubSequenceTokenV2_DeepCopy_IfNotNull()
        {
            var token = new EventHubSequenceTokenV2("name", long.MaxValue, int.MaxValue);
            var copy = EventHubSequenceTokenV2.DeepCopy(token) as EventSequenceToken;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);

            var writer = new BinaryTokenStreamWriter();
            SerializationManager.Serialize(token, writer);
            var bytes = writer.ToByteArray();

            var reader = new BinaryTokenStreamReader(bytes);
            copy = SerializationManager.Deserialize(reader) as EventHubSequenceTokenV2;
            Assert.NotNull(copy);
            Assert.NotSame(token, copy);
            Assert.Equal(token.EventIndex, copy.EventIndex);
            Assert.Equal(token.SequenceNumber, copy.SequenceNumber);
        }
 public void EventHubSequenceTokenV2_Serialize_IfNotNull()
 {
     var writer = new BinaryTokenStreamWriter();
     var token = new EventHubSequenceTokenV2("name", long.MaxValue, int.MaxValue);
     EventHubSequenceTokenV2.Serialize(token, writer, null);
     var reader = new BinaryTokenStreamReader(writer.ToByteArray());
     var deserialized = EventHubSequenceTokenV2.Deserialize(typeof (EventHubSequenceTokenV2), reader) as EventHubSequenceTokenV2;
     Assert.NotNull(deserialized);
     Assert.NotSame(token, deserialized);
     Assert.Equal(token.EventIndex, deserialized.EventIndex);
     Assert.Equal(token.SequenceNumber, deserialized.SequenceNumber);
 }
 /// <summary>
 /// Deserializes an event sequence token
 /// </summary>
 /// <param name="expected">The expected type.</param>
 /// <param name="reader">The binary stream to read from.</param>
 /// <returns></returns>
 public static object Deserialize(Type expected, BinaryTokenStreamReader reader)
 {
     var deserialized = new EventHubSequenceTokenV2(reader.ReadString(), reader.ReadLong(), reader.ReadInt());
     DeserializationContext.Current.RecordObject(deserialized);
     return deserialized;
 }