Beispiel #1
0
        public void ObjectFromBytesTest()
        {
            Assert.Null(SerDeExtensions.FromBytes <ITestInterface>(null));

            var testBytes = new byte[] { 1, 2, 123 };

            Assert.Equal(testBytes, SerDeExtensions.FromBytes <byte[]>(testBytes));
        }
Beispiel #2
0
        public void ObjectToBytesTest()
        {
            Assert.Null(SerDeExtensions.ToBytes((object)null));

            var testBytes = new byte[] { 1, 2, 123 };

            Assert.Equal(testBytes, SerDeExtensions.ToBytes(testBytes));
        }
Beispiel #3
0
        public void StringToBytesRoundtripTest()
        {
            string testStr = "Test String Value";

            byte[] bytes        = SerDeExtensions.ToBytes(testStr);
            string convertedStr = SerDeExtensions.FromBytes(bytes);

            Assert.Equal(testStr, convertedStr);
        }
Beispiel #4
0
        public void StringToBytesTest()
        {
            byte[] bytes = SerDeExtensions.ToBytes(null);
            Assert.NotNull(bytes);
            Assert.Empty(bytes);

            bytes = SerDeExtensions.ToBytes("  ");
            Assert.NotNull(bytes);
            Assert.Empty(bytes);
        }
        public void StringToBytesTest()
        {
            byte[] bytes = SerDeExtensions.ToBytes(null);
            Assert.NotNull(bytes);
            Assert.Equal(0, bytes.Length);

            bytes = SerDeExtensions.ToBytes("  ");
            Assert.NotNull(bytes);
            Assert.Equal(0, bytes.Length);
        }
Beispiel #6
0
        public void FromJsonTest()
        {
            Assert.Null(SerDeExtensions.FromJson <ITestInterface>(null));
            Assert.Null(SerDeExtensions.FromJson <ITestInterface>(string.Empty));

            Assert.Equal(0, SerDeExtensions.FromJson <int>(null));
            Assert.Equal(0, SerDeExtensions.FromJson <long>(string.Empty));

            string str = "Foo Bar";

            Assert.Equal(str, SerDeExtensions.FromJson <string>(str));
        }
Beispiel #7
0
        public void ObjectToBytesRoundtripTest()
        {
            ITestInterface testObj = new TestClass("Foo")
            {
                Prop2 = 100
            };

            byte[]         bytes    = SerDeExtensions.ToBytes(testObj);
            ITestInterface testObj2 = SerDeExtensions.FromBytes <TestClass>(bytes);

            Assert.NotNull(testObj2);
            Assert.Equal(testObj.GetProp1(), testObj2.GetProp1());
            Assert.Equal(testObj.GetProp2(), testObj2.GetProp2());
        }
Beispiel #8
0
        public void ToJsonTest()
        {
            Assert.Equal(string.Empty, SerDeExtensions.ToJson(null));

            string str = "Foo Bar";

            Assert.Equal(str, SerDeExtensions.ToJson(str));

            ITestInterface testObj = new TestClass("Foo")
            {
                Prop2 = 100
            };
            string json         = SerDeExtensions.ToJson(testObj);
            string expectedJson = @"{""Prop1"":""Foo"",""Prop2"":100}";

            Assert.Equal(expectedJson, json);

            ITestInterface jsonConvertedObj = SerDeExtensions.FromJson <TestClass>(json);

            Assert.NotNull(jsonConvertedObj);
            Assert.Equal("Foo", jsonConvertedObj.GetProp1());
            Assert.Equal(100, jsonConvertedObj.GetProp2());
        }
Beispiel #9
0
 public void FromBytesTest()
 {
     Assert.Equal(string.Empty, SerDeExtensions.FromBytes(null));
     Assert.Equal(string.Empty, SerDeExtensions.FromBytes(new byte[0]));
 }
Beispiel #10
0
        public void StringToJsonRoundtripTest(string input)
        {
            string value = SerDeExtensions.FromJson <string>(SerDeExtensions.ToJson(input));

            Assert.Equal(input, value);
        }