Ejemplo n.º 1
0
 public void ShouldSerializeMessageWithObjectToMemoryStream()
 {
     using (var ms = new MemoryStream()) {
         object message = new Message() { ID = 10, CreateDate = DateTime.Now, Data = "This is a test", test = new Test() { Int = 100, Str = "Testing", UUID = Guid.NewGuid() } };
         MessageSharkSerializer.Serialize(message, ms);
         var buffer = ms.ToArray();
     }
 }
Ejemplo n.º 2
0
        public void ShouldDeserializeTOMessageFromMemoryStream()
        {
            byte[] buffer = null;
            using (var ms = new MemoryStream()) {
                var message = new Message() { ID = 10, CreateDate = DateTime.Now, Data = "This is a test", test = new Test() { Int = 100, Str = "Testing", UUID = Guid.NewGuid() } };
                MessageSharkSerializer.Serialize(message, ms);
                buffer = ms.ToArray();
            }

            using (var ms2 = new MemoryStream(buffer)) {
                ms2.Seek(0, SeekOrigin.Begin);
                var msg = MessageSharkSerializer.Deserialize(typeof(Message), ms2);
            }
        }
Ejemplo n.º 3
0
 public void TestMultipleSerialization()
 {
     //MessageSharkSerializer.Build();
     var count = 10000;
     var tasks = new Task[count];
     //var threads = new ConcurrentBag<int>();
     for (var i = 0; i < count; i++) {
         tasks[i] = Task.Factory.StartNew(() =>
         {
             var data = new Message() { ID = 10, CreateDate = DateTime.Now, Data = "This is a test" };
             var buffer = MessageSharkSerializer.Serialize(data);
             //threads.Add(Thread.CurrentThread.ManagedThreadId);
         }).ContinueWith(t => Handle(t),   TaskContinuationOptions.OnlyOnFaulted)
         .ContinueWith(_ => {});
     }
     Task.WaitAll(tasks);
 }
Ejemplo n.º 4
0
 public void TestSerialize()
 {
     var message = new Message() { ID = 10, CreateDate = DateTime.Now, Data = "This is a test", test = new Test() { Int = 100, Str = "Testing", UUID = Guid.NewGuid() } };
     message.Tests = new List<Test> {
         new Test() { Int = 100, Str = "Testing", UUID = Guid.NewGuid() },
         new Test() { Int = 100, Str = "Testing2", UUID = Guid.NewGuid() },
         new Test() { Int = 100, Str = "Testing3", UUID = Guid.NewGuid() }
     };
     var buffer = MessageSharkSerializer.Serialize(message);
     var message2 = MessageSharkSerializer.Deserialize<Message>(buffer);
     Assert.IsTrue(message.CreateDate == message2.CreateDate);
     Assert.IsTrue(message.Data == message2.Data);
     Assert.IsTrue(message.ID == message2.ID);
 }