Exemplo n.º 1
0
        public void Simply_Class_Test()
        {
            SimplyModel model = new SimplyModel
            {
                IntValue       = 100,
                DoubleValue    = 222.222,
                StringValue    = "This is a simply object",
                BooleanValue   = true,
                ByteValue      = 200,
                FloatValue     = 1.2f,
                LongValue      = 34234,
                SByteValue     = -97,
                UInt32Value    = 203947109,
                UInt64Value    = 21389172947123912,
                ShortValue     = -16234,
                UShortValue    = 36312,
                DateTime       = new DateTime(2020, 7, 6, 6, 54, 10, DateTimeKind.Utc),
                DateTimeOffset = new DateTimeOffset(2020, 6, 5, 23, 11, 2, TimeSpan.FromHours(8)),
                TimeSpan       = TimeSpan.FromHours(2.3),
                BytesValue     = new byte[] { 1, 2, 3, 4, 5 },
                GuidValue      = Guid.NewGuid()
            };

            MemoryStream stream = new MemoryStream();

            Message.Serialize(stream, model);

            stream.Position = 0;
            var model2 = Message.Deserialize <SimplyModel>(stream);

            Assert.Equal(model.IntValue, model2.IntValue);
            Assert.Equal(model.DoubleValue, model2.DoubleValue);
            Assert.Equal(model.StringValue, model2.StringValue);
            Assert.Equal(model.BooleanValue, model2.BooleanValue);
            Assert.Equal(model.ByteValue, model2.ByteValue);
            Assert.Equal(model.FloatValue, model2.FloatValue);
            Assert.Equal(model.LongValue, model2.LongValue);
            Assert.Equal(model.SByteValue, model2.SByteValue);
            Assert.Equal(model.UInt32Value, model2.UInt32Value);
            Assert.Equal(model.UInt64Value, model2.UInt64Value);
            Assert.Equal(model.ShortValue, model2.ShortValue);
            Assert.Equal(model.UShortValue, model2.UShortValue);
            Assert.Equal(model.DateTime, model2.DateTime);
            Assert.Equal(model.DateTimeOffset, model2.DateTimeOffset);
            Assert.Equal(model.TimeSpan, model2.TimeSpan);
            Assert.Equal(model.BytesValue, model2.BytesValue);
            Assert.Equal(model.GuidValue, model2.GuidValue);
        }
Exemplo n.º 2
0
        public void Convert_Test()
        {
            SimplyModel model = new SimplyModel
            {
                IntValue    = 100,
                DoubleValue = 222.222,
                StringValue = "This is a simply model"
            };

            Message <SimplyModel> message = model;

            Assert.Equal(model, message.Source);

            SimplyModel model2 = message;

            Assert.Equal(model, model2);

            ((IMessage)message).CalculateSize();
        }