Пример #1
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new bool[] { true, false };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
        public void ToJson_CorrectString()
        {
            //arrange
            var array = new double?[] { 42.21d, 176.568d, double.MaxValue, double.MinValue, null, 0 };

            //act
            var json = _convert.ToJson(array);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #3
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new byte[] { 0, 1, 255 };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #4
0
        public void ToJson_CorrectString()
        {
            //arrange
            var array = new DateTime[] { new DateTime(2017, 7, 25), new DateTime(2017, 7, 25, 23, 59, 58), new DateTime(2017, 7, 25, 23, 59, 58).AddMilliseconds(196) };

            //act
            var json = _convert.ToJson(array);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #5
0
        public void ToJson_CorrectString()
        {
            //arrange
            var array = new string[] { "one", null, "two" };

            //act
            var json = _convert.ToJson(array);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson.ToString()));
        }
Пример #6
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <long>()
            {
                long.MinValue, -1, 0, 1, 42, long.MaxValue
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #7
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <float>()
            {
                42.21f, 176.568f, float.MaxValue, float.MinValue, 0
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #8
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <uint>()
            {
                0, 1, 42, 4294967295
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #9
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <ushort?>()
            {
                0, 1, 42, null, ushort.MaxValue
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #10
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <string>()
            {
                "one", null, "two"
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #11
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonArrayClass()
            {
                BooleanArray = new bool[] { true, false }
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson.ToString()));
        }
Пример #12
0
        public void ToJson_CorrectString()
        {
            //arrange
            var list = new List <Guid>()
            {
                new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), new Guid(2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
            };

            //act
            var json = _convert.ToJson(list);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #13
0
        public void ToJson_CorrectString()
        {
            //arrange
            var dictionary = new Dictionary <string, int>()
            {
                { "First", 1 },
                { "Second", 2 },
                { "Third", 3 },
            };

            //act
            var json = _convert.ToJson(dictionary);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #14
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonListClass()
            {
                BooleanList = new List <bool>()
                {
                    true, false
                }
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #15
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = new Dictionary <string, string>()
                {
                    { "FirstName", "Luke" },
                    { "LastName", "Skywalker" }
                }
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #16
0
        public void ToJson_Null_CorrectString()
        {
            //arrange
            //act
            var json = _convert.ToJson((double?[])null);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("null"));
        }
Пример #17
0
        public void ToJson_CorrectString(string value, string expectedJson)
        {
            //arrange
            //act
            var json = _convert.ToJson(value);

            //asserts
            Assert.That(json.ToString(), Is.EqualTo(expectedJson));
        }
Пример #18
0
        public void ToJson_CorrectString_PT_BR()
        {
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;

            //arrange
            var jsonDec = new JsonDecimal()
            {
                DecNull = null,
                Min     = MIN,
                Value   = -200000.01m,
                Value2  = 1.5m,
            };

            //act
            var json = _convert.ToJson(jsonDec);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson_PT_BR));
        }
Пример #19
0
        public void ToJson_CorrectString(char character, string expectedPropertyValue)
        {
            //arrange
            var jsonClass = new JsonCharClass()
            {
                Property = character
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo($"{{\"Property\":{expectedPropertyValue}}}"));
        }
Пример #20
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonGuidClass()
            {
                GuidProperty = new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11),
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #21
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonBooleanClass()
            {
                IsTrue  = true,
                IsFalse = false
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"IsFalse\":false,\"IsTrue\":true}"));
        }
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonNullableBooleanClass()
            {
                IsTrue  = true,
                IsFalse = false,
                IsNull  = null
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(_json));
        }
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonIgnoredPropertyClass()
            {
                Age      = 42,
                Height   = 176,
                Escaping = 12,
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #24
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonClass()
            {
                EscapingNeeded = NeedsEscaping,
                FirstName      = "Bob",
                LastName       = "Marley",
                NullProperty   = null
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #25
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonUIntClass()
            {
                Age    = 42,
                Height = 176,
                Max    = uint.MaxValue,
                Min    = uint.MinValue
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Пример #26
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new MixedJsonClass()
            {
                Age          = 97,
                Name         = "Jack",
                NullProperty = null,
                IsTrue       = true
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Age\":97,\"IsTrue\":true,\"Name\":\"Jack\",\"NullProperty\":null}"));
        }
Пример #27
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonFloatClass()
            {
                Age    = 42.21f,
                Height = 176.568f,
                Max    = float.MaxValue,
                Min    = float.MinValue,
                Zero   = 0
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonNullableULongClass()
            {
                Age    = 42,
                Height = 176,
                Max    = ulong.MaxValue,
                Min    = ulong.MinValue,
                Null   = null
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
        public void ToJson_DoesntIncludeNulls()
        {
            //arrange
            var jsonClass = new IgnoreNullClass()
            {
                Age         = 97,
                AgeNull     = null,
                Boolean     = true,
                CustomClass = new CustomClass()
                {
                    Name = "Name"
                },
                CustomClassNull    = null,
                DateTime           = DateTime.MinValue,
                DateTimeNull       = null,
                DateTimeOffset     = DateTimeOffset.MinValue,
                DateTimeOffsetNull = null,
                Dictionary         = new Dictionary <string, int>()
                {
                    { "one", 1 }
                },
                DictionaryNull = null,
                Guid           = Guid.Empty,
                GuidNull       = null,
                Name           = "Jack",
                NameNull       = null,
                Array          = new int[] { 1 },
                List           = new List <int>()
                {
                    1
                },
                ListNull = null
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(
                            "{\"Age\":97,\"Array\":[1],\"Boolean\":true,\"CustomClass\":{\"Name\":\"Name\"},\"DateTime\":\"0001-01-01T00:00:00\"," +
                            "\"DateTimeOffset\":\"0001-01-01T00:00:00+00:00\",\"Dictionary\":{\"one\":1},\"Guid\":\"00000000-0000-0000-0000-000000000000\"," +
                            "\"List\":[1],\"Name\":\"Jack\"}"));
        }
Пример #30
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonNullableDoubleClass()
            {
                Age    = 42.21d,
                Height = 176.568d,
                Max    = double.MaxValue,
                Min    = double.MinValue,
                Null   = null,
                Zero   = 0
            };

            //act
            var json = _convert.ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }