public void DeserializationMultipleMessageEntrepriseApplication()
        {
            Message message = new Message(0, 1, "Serialization - Message dans le bon format", "21/03/2015");
            User    user    = new User("Vincent", "Couvignou", "*****@*****.**", "19/03/2015", "masculin", true, null, null, null);
            DataContractJsonSerializer jsMessage = new DataContractJsonSerializer(typeof(Message));
            DataContractJsonSerializer jsUser    = new DataContractJsonSerializer(typeof(User));
            MemoryStream m = new MemoryStream();

            jsUser.WriteObject(m, user);
            jsMessage.WriteObject(m, message);

            m.Position = 0;
            StreamReader  s        = new StreamReader(m, Encoding.UTF8);
            List <string> listJson = ParseStream.ParseStreamToString(s);

            Assert.IsTrue(listJson.Count == 2);

            Message me = null;
            User    u  = null;

            foreach (var jsonItem in listJson)
            {
                StreamReader itemStream = new StreamReader(ParseStream.GenerateStreamFromString(jsonItem), Encoding.UTF8);
                var          userObject = JsonValue.Load(itemStream) as JsonObject;
                Assert.IsNotNull(userObject);
                MemoryStream mItem = new MemoryStream(Encoding.ASCII.GetBytes(jsonItem));
                if ((int)userObject["message_type"] == (int)MessageType.USER_INFORMATION)
                {
                    u = jsUser.ReadObject(mItem) as User;
                    Assert.IsTrue(true);
                }
                else if ((int)userObject["message_type"] == (int)MessageType.MESSAGE)
                {
                    me = jsMessage.ReadObject(mItem) as Message;
                    Assert.IsTrue(true);
                }
                else
                {
                    Assert.IsTrue(false);
                }
            }

            Assert.IsNotNull(u);
            Assert.IsNotNull(me);
            Assert.IsTrue(me.Equals(message));
            Assert.IsTrue(u.Equals(user) && me.Equals(message));
        }
        public void MessageSerialization()
        {
            Message message = new Message(0, 1, "Serialization - Message dans le bon format", "21/03/2015");
            DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Message));
            MemoryStream m = new MemoryStream();

            js.WriteObject(m, message);

            m.Position = 0;
            StreamReader s_object = new StreamReader(m);
            StreamReader s_file   = new StreamReader("MessageSerializationCorrectFormat.json", Encoding.UTF8);
            DataContractJsonSerializer jsonUser = new DataContractJsonSerializer(typeof(Message));
            MemoryStream mMessageFile           = new MemoryStream(Encoding.ASCII.GetBytes(s_file.ReadToEnd()));
            MemoryStream mMessageObject         = new MemoryStream(Encoding.ASCII.GetBytes(s_object.ReadToEnd()));
            Message      messageFile            = jsonUser.ReadObject(mMessageFile) as Message;
            Message      serializationMessage   = jsonUser.ReadObject(mMessageObject) as Message;

            Assert.IsNotNull(messageFile);
            Assert.IsTrue(messageFile.Equals(serializationMessage));
        }
        public void MessageDeserializationCorrectFormat_2()
        {
            StreamReader s = new StreamReader("MessageDeserializationCorrectFormat_2.json", Encoding.UTF8);

            var message = JsonValue.Load(s) as JsonObject;

            Assert.IsNotNull(message);
            Assert.IsTrue((int)message["message_type"] == (int)MessageType.MESSAGE);

            s.Close();
            s = new StreamReader("MessageDeserializationCorrectFormat_2.json", Encoding.UTF8);
            DataContractJsonSerializer jsonUser = new DataContractJsonSerializer(typeof(Message));
            MemoryStream m            = new MemoryStream(Encoding.ASCII.GetBytes(s.ReadToEnd()));
            Message      messageClass = jsonUser.ReadObject(m) as Message;

            Message mObject = new Message(1, 2, "Message dans le bon format", null);

            Assert.IsTrue(mObject.Equals(messageClass));
            s.Close();
        }