public void ArrayOfDateTimesSerializing()
        {
            var serializer = new SerializerConfig().Create();

            var inputDateTime = new DateTime(2018, 01, 02, 03, 04, 05, DateTimeKind.Unspecified);

            var input = new[] { inputDateTime, inputDateTime, inputDateTime, inputDateTime, inputDateTime };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <DateTime[]>(stream);

                Assert.Equal(5, result.Length);

                foreach (var date in result)
                {
                    Assert.Equal(2018, date.Year);
                    Assert.Equal(01, date.Month);
                    Assert.Equal(2, date.Day);
                    Assert.Equal(3, date.Hour);
                    Assert.Equal(4, date.Minute);
                    Assert.Equal(5, date.Second);
                    Assert.Equal(DateTimeKind.Unspecified, date.Kind);
                }
            }
        }
        public void NotRegisteredDerivedEntitySerializedAsBaseEntity()
        {
            var serializer = new SerializerConfig().Create();

            var input = new EntityHolder
            {
                Entity = new DerivedEntity
                {
                    Id            = 111,
                    Discriminator = "DerivedEntity"
                }
            };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <EntityHolder>(stream);

                Assert.NotNull(result);
                Assert.NotNull(result.Entity);
                Assert.IsType <Entity>(result.Entity);
                Assert.Equal(111, result.Entity.Id);
            }
        }
        public void FloatSerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, 12.2f);
                stream.Seek(0);
                var result = serializer.Deserialize <float>(stream);
                Assert.Equal(12.2f, result);
            }
        }
        public void DoubleMaxValueSerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, double.MaxValue);
                stream.Seek(0);
                var result = serializer.Deserialize <double>(stream);
                Assert.Equal(double.MaxValue, result);
            }
        }
        public void Int32Serializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, 100_000);
                stream.Seek(0);
                var result = serializer.Deserialize <int>(stream);

                Assert.Equal(100_000, result);
            }
        }
Example #6
0
        public void StringSerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                var input = "String data type message";
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <string>(stream);

                Assert.Equal(input, result);
            }
        }
        public void IntArraySerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                var input = new[] { 3, 2, 1, 2, 3 };
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <int[]>(stream);

                Assert.Equal(5, result.Length);
                Assert.Equal(input, result);
            }
        }
        public void StringArraySerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                var input = new[] { "ABC", "DEG", "HIJ" };
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <string[]>(stream);

                Assert.Equal(3, result.Length);
                Assert.Equal(input, result);
            }
        }
        public void ObjectSerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                var input = new object();

                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <object>(stream);

                Assert.NotNull(result);
            }
        }
        public void StringListSerializing()
        {
            var serializer = new SerializerConfig().Create();

            using (var stream = CreateStream())
            {
                IList <string> input = new List <string> {
                    "ABC", "DEG", "HIJ"
                };
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <IList <string> >(stream);

                Assert.Equal(3, result.Count);
                Assert.Equal(input, result);
            }
        }
Example #11
0
        public void StringNameInPersonIsSerializing()
        {
            var serializer = new SerializerConfig().Create();

            var input = new Person
            {
                Name = "WORKS"
            };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <Person>(stream);

                Assert.Equal("WORKS", result.Name);
            }
        }
        public void ListSerializing()
        {
            var serializer = new SerializerConfig().Create();

            List <int> input = new List <int> {
                1, 2, 3
            };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <List <int> >(stream);

                Assert.Equal(3, result.Count);
                Assert.Equal(input, result);
            }
        }
        public void StringEntitySerializing()
        {
            var serializer = new SerializerConfig().Create();

            var input = new StringEntity
            {
                Name = Encoding.UTF8.GetString(new byte[] { 1, 2, 3, 4, 5 })
            };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <StringEntity>(stream);

                Assert.NotNull(result);
                Assert.Equal(input.Name, result.Name);
            }
        }
        public void EntitySerializing()
        {
            var serializer = new SerializerConfig().Create();

            var input = new Entity
            {
                Id = 123
            };

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <Entity>(stream);

                Assert.NotNull(result);
                Assert.Equal(123, result.Id);
            }
        }
        public void DateTimeUnspecifiedSerializing()
        {
            var serializer = new SerializerConfig().Create();

            var input = new DateTime(2018, 01, 02, 03, 04, 05, DateTimeKind.Unspecified);

            using (var stream = CreateStream())
            {
                serializer.Serialize(stream, input);
                stream.Seek(0);
                var result = serializer.Deserialize <DateTime>(stream);

                Assert.Equal(2018, result.Year);
                Assert.Equal(01, result.Month);
                Assert.Equal(2, result.Day);
                Assert.Equal(3, result.Hour);
                Assert.Equal(4, result.Minute);
                Assert.Equal(5, result.Second);
                Assert.Equal(DateTimeKind.Unspecified, result.Kind);
            }
        }