コード例 #1
0
        public void Serialize_DateTime()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = RandomHelper.NextDate(g_random, 100);

            // Act
            var result = formatter.Serialize <DateTime>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.DateTime, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value.Ticks), result.Array);
        }
コード例 #2
0
        public void Serialize_Boolean()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = RandomHelper.NextBoolean(g_random);

            // Act
            var result = formatter.Serialize <bool>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Boolean, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #3
0
        public void Serialize_String()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = RandomHelper.NextString(g_random, 100, StringHelper.AlphabetLowerCase);

            // Act
            var result = formatter.Serialize <string>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.String, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(Encoding.UTF8.GetBytes(value), result.Array);
        }
コード例 #4
0
        public void Serialize_Int32()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = RandomHelper.NextInt(g_random, Int32.MinValue, Int32.MaxValue);

            // Act
            var result = formatter.Serialize <int>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Int32, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #5
0
        public void Serialize_Single()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = (float)(RandomHelper.NextInt(g_random, 100, 100000) * 2.3435);

            // Act
            var result = formatter.Serialize <float>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Single, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #6
0
        public void Serialize_UInt64()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = (ulong)RandomHelper.NextInt(g_random, 100, 23423);

            // Act
            var result = formatter.Serialize <ulong>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.UInt64, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #7
0
        public void Serialize_Int16()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = (short)23454;

            // Act
            var result = formatter.Serialize <short>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Int16, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #8
0
        public void Serialize_Double()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = g_random.NextDouble() * 1234567890.987654321;

            // Act
            var result = formatter.Serialize <double>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Double, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(BitConverter.GetBytes(value), result.Array);
        }
コード例 #9
0
        public void Serialize_DBNull()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = DBNull.Value;

            // Act
            var result = formatter.Serialize <DBNull>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.DBNull, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(0, result.Count);
        }
コード例 #10
0
        public void Serialize_Byte()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = (byte)100;

            // Act
            var result = formatter.Serialize <byte>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Byte, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(new byte[] { value }, result.Array);
        }
コード例 #11
0
        public void Serialize_Decimal()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = 100M;

            // Act
            var result = formatter.Serialize <decimal>(value, out flags);

            // Assert
            Assert.Equal((int)TypeCode.Decimal, flags);
            Assert.NotNull(result.Array);
            Assert.Equal(DecimalHelper.GetBytes(value), result.Array);
        }
コード例 #12
0
        public void Serialize_DoesNot_Handle()
        {
            // Arrange
            var formatter = new SimpleObjectFormatter(Encoding.UTF8, m_mockInner.Object);
            var flags     = -1;
            var value     = new object();

            m_mockInner.Setup(inner => inner.Serialize <object>(value, out flags)).Returns(new ArraySegment <byte>());

            // Act
            var result = formatter.Serialize <object>(value, out flags);

            // Assert
            Assert.Equal(-1, flags);
            Assert.Equal(0, result.Count);
        }