Пример #1
0
        public void FromJson_CorrectJsonClass(char expectedCharacter, string property)
        {
            //arrange
            var json      = $"{{\"Property\":{property}}}";
            var jsonClass = new JsonCharClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.Property, Is.EqualTo(expectedCharacter));
        }
Пример #2
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <bool>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(2));
            Assert.That(list[0], Is.True);
            Assert.That(list[1], Is.False);
        }
Пример #3
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var array = new bool[0];

            //act
            array = _convert.FromJson(array, ExpectedJson);

            //assert
            Assert.That(array.Length, Is.EqualTo(2));
            Assert.That(array[0], Is.True);
            Assert.That(array[1], Is.False);
        }
Пример #4
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <Guid>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(2));
            Assert.That(list[0], Is.EqualTo(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
            Assert.That(list[1], Is.EqualTo(new Guid(2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
        }
Пример #5
0
        public void FromJson_EmptyArray_CorrectArray()
        {
            //arrange
            var array = new byte[] {};

            //act
            array = _convert.FromJson(array, ExpectedJson);

            //assert
            Assert.That(array.Length, Is.EqualTo(3));
            Assert.That(array[0], Is.EqualTo(0));
            Assert.That(array[1], Is.EqualTo(1));
            Assert.That(array[2], Is.EqualTo(255));
        }
Пример #6
0
        public void FromJson_EmptyArray_CorrectArray()
        {
            //arrange
            var array = new DateTime[] {};

            //act
            array = _convert.FromJson(array, ExpectedJson);

            //assert
            Assert.That(array.Length, Is.EqualTo(3));
            Assert.That(array[0], Is.EqualTo(new DateTime(2017, 7, 25)));
            Assert.That(array[1], Is.EqualTo(new DateTime(2017, 7, 25, 23, 59, 58)));
            Assert.That(array[2], Is.EqualTo(new DateTime(2017, 7, 25, 23, 59, 58).AddMilliseconds(196)));
        }
Пример #7
0
        public void FromJson_EmptyArray_CorrectArray()
        {
            //arrange
            var array = new string[] {};

            //act
            array = _convert.FromJson(array, ExpectedJson.ToString());

            //assert
            Assert.That(array.Length, Is.EqualTo(3));
            Assert.That(array[0], Is.EqualTo("one"));
            Assert.That(array[1], Is.Null);
            Assert.That(array[2], Is.EqualTo("two"));
        }
Пример #8
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <byte>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(3));
            Assert.That(list[0], Is.EqualTo(0));
            Assert.That(list[1], Is.EqualTo(1));
            Assert.That(list[2], Is.EqualTo(255));
        }
Пример #9
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <string>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(3));
            Assert.That(list[0], Is.EqualTo("one"));
            Assert.That(list[1], Is.Null);
            Assert.That(list[2], Is.EqualTo("two"));
        }
Пример #10
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <DateTime>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(3));
            Assert.That(list[0], Is.EqualTo(new DateTime(2017, 7, 25)));
            Assert.That(list[1], Is.EqualTo(new DateTime(2017, 7, 25, 23, 59, 58)));
            Assert.That(list[2], Is.EqualTo(new DateTime(2017, 7, 25, 23, 59, 58).AddMilliseconds(196)));
        }
Пример #11
0
        public void FromJson_EmptyDictionary_CorrectList()
        {
            //arrange
            var dictionary = new Dictionary <string, int>();

            //act
            dictionary = _convert.FromJson(dictionary, ExpectedJson);

            //assert
            Assert.That(dictionary.Count, Is.EqualTo(3));
            Assert.That(dictionary["First"], Is.EqualTo(1));
            Assert.That(dictionary["Second"], Is.EqualTo(2));
            Assert.That(dictionary["Third"], Is.EqualTo(3));
        }
Пример #12
0
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = ExpectedJson;
            var jsonClass = new JsonParentClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.Child.Name, Is.EqualTo("Samuel"));
            Assert.That(jsonClass.Child.Age, Is.EqualTo(8));
            Assert.That(jsonClass.Null, Is.Null);
        }
Пример #13
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <ushort>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(4));
            Assert.That(list[0], Is.EqualTo(0));
            Assert.That(list[1], Is.EqualTo(1));
            Assert.That(list[2], Is.EqualTo(42));
            Assert.That(list[3], Is.EqualTo(ushort.MaxValue));
        }
Пример #14
0
        public void FromJson_EmptyArray_CorrectArray()
        {
            //arrange
            var jsonClass = new JsonArrayClass()
            {
                BooleanArray = new bool[0]
            };

            //act
            _convert.FromJson(jsonClass, ExpectedJson);

            //assert
            Assert.That(jsonClass.BooleanArray.Length, Is.EqualTo(2));
            Assert.That(jsonClass.BooleanArray[0], Is.True);
            Assert.That(jsonClass.BooleanArray[1], Is.False);
        }
Пример #15
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <float>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(5));
            Assert.That(list[0], Is.EqualTo(42.21f));
            Assert.That(list[1], Is.EqualTo(176.568f));
            Assert.That(list[2], Is.EqualTo(float.MaxValue));
            Assert.That(list[3], Is.EqualTo(float.MinValue));
            Assert.That(list[4], Is.EqualTo(0));
        }
Пример #16
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var jsonClass = new JsonListClass()
            {
                BooleanList = new List <bool>()
            };

            //act
            _convert.FromJson(jsonClass, ExpectedJson);

            //assert
            Assert.That(jsonClass.BooleanList.Count, Is.EqualTo(2));
            Assert.That(jsonClass.BooleanList[0], Is.True);
            Assert.That(jsonClass.BooleanList[1], Is.False);
        }
Пример #17
0
        public void FromJson_EmptyDictionary_CorrectDictionary()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = new Dictionary <string, string>()
            };

            //act
            _convert.FromJson(jsonClass, ExpectedJson);

            //assert
            Assert.That(jsonClass.Dictionary.Count, Is.EqualTo(2));
            Assert.That(jsonClass.Dictionary["FirstName"], Is.EqualTo("Luke"));
            Assert.That(jsonClass.Dictionary["LastName"], Is.EqualTo("Skywalker"));
        }
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var array = new double?[] {};

            //act
            array = _convert.FromJson(array, ExpectedJson);

            //assert
            Assert.That(array.Length, Is.EqualTo(6));
            Assert.That(array[0], Is.EqualTo(42.21d));
            Assert.That(array[1], Is.EqualTo(176.568d));
            Assert.That(array[2], Is.EqualTo(double.MaxValue));
            Assert.That(array[3], Is.EqualTo(double.MinValue));
            Assert.That(array[4], Is.Null);
            Assert.That(array[5], Is.EqualTo(0));
        }
Пример #19
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <double?>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(6));
            Assert.That(list[0], Is.EqualTo(42.21d));
            Assert.That(list[1], Is.EqualTo(176.568d));
            Assert.That(list[2], Is.EqualTo(double.MaxValue));
            Assert.That(list[3], Is.EqualTo(double.MinValue));
            Assert.That(list[4], Is.Null);
            Assert.That(list[5], Is.EqualTo(0));
        }
Пример #20
0
        public void FromJson_CorrectJsonClass(string expectedValue, string json)
        {
            //arrange
            //act
            string value = _convert.FromJson((string)null, json);

            //assert
            Assert.That(value, Is.EqualTo(expectedValue));
        }
Пример #21
0
        public void FromJson_EmptyList_CorrectList()
        {
            //arrange
            var list = new List <long?>();

            //act
            _convert.FromJson(list, ExpectedJson);

            //assert
            Assert.That(list.Count, Is.EqualTo(7));
            Assert.That(list[0], Is.EqualTo(long.MinValue));
            Assert.That(list[1], Is.EqualTo(-1));
            Assert.That(list[2], Is.EqualTo(0));
            Assert.That(list[3], Is.EqualTo(1));
            Assert.That(list[4], Is.EqualTo(42));
            Assert.That(list[5], Is.Null);
            Assert.That(list[6], Is.EqualTo(long.MaxValue));
        }
Пример #22
0
        public void FromJson_CorrectJsonClass_PT_BR()
        {
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("pt-BR");
            Thread.CurrentThread.CurrentCulture   = Thread.CurrentThread.CurrentUICulture;

            //arrange
            var json    = ExpectedJson_PT_BR;
            var jsonDec = new JsonDecimal();

            //act
            _convert.FromJson(jsonDec, json);

            //assert
            Assert.That(jsonDec.DecNull, Is.Null);
            Assert.That(jsonDec.Value, Is.EqualTo(-200000.01m));
            Assert.That(jsonDec.Value2, Is.EqualTo(1.5m));
            Assert.That(jsonDec.Min, Is.EqualTo(MIN));
        }
Пример #23
0
        public void FromJson_CorrectJsonClass(int expectedValue, string json)
        {
            //arrange
            int value = 0;

            //act
            value = _convert.FromJson(value, json);

            //assert
            Assert.That(value, Is.EqualTo(expectedValue));
        }
Пример #24
0
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = ExpectedJson;
            var jsonClass = new JsonGuidClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.GuidProperty, Is.EqualTo(new Guid(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)));
        }
Пример #25
0
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = "{\"IsFalse\":false,\"IsTrue\":true}";
            var jsonClass = new JsonBooleanClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.IsTrue, Is.True);
            Assert.That(jsonClass.IsFalse, Is.False);
        }
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var jsonClass = new JsonNullableBooleanClass();

            //act
            _convert.FromJson(jsonClass, _json);

            //assert
            Assert.That(jsonClass.IsTrue, Is.True);
            Assert.That(jsonClass.IsFalse, Is.False);
            Assert.That(jsonClass.IsNull, Is.Null);
        }
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = "{}";
            var jsonClass = new OptionalPropertyClass()
            {
                OptionalBool   = true,
                OptionalInt    = 42,
                OptionalArray  = new int[] { 42 },
                OptionalChar   = '4',
                OptionalMyType = new MyType {
                    Name = "Bob"
                },
                OptionalMyType2 = new MyType2 {
                    Name = "Bob"
                },
                OptionalDateTime               = DateTime.MaxValue,
                OptionalDateTimeOffset         = DateTimeOffset.MaxValue,
                OptionalDictionary             = new Dictionary <string, int>(),
                OptionalGuid                   = new Guid(),
                OptionalList                   = new List <int>(),
                OptionalNullableInt            = 42,
                OptionalNullableBoolean        = true,
                OptionalNullableDateTime       = DateTime.MaxValue,
                OptionalNullableDateTimeOffset = DateTimeOffset.MaxValue,
                OptionalNullableGuid           = new Guid(),
                OptionalString                 = "string"
            };

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.OptionalBool, Is.EqualTo(default(bool)));
            Assert.That(jsonClass.OptionalInt, Is.EqualTo(default(int)));
            Assert.That(jsonClass.OptionalArray, Is.Null);
            Assert.That(jsonClass.OptionalChar, Is.EqualTo(default(char)));
            Assert.That(jsonClass.OptionalMyType, Is.EqualTo(default(MyType)));
            Assert.That(jsonClass.OptionalMyType2, Is.EqualTo(default(MyType2)));
            Assert.That(jsonClass.OptionalDateTime, Is.EqualTo(default(DateTime)));
            Assert.That(jsonClass.OptionalDateTimeOffset, Is.EqualTo(default(DateTimeOffset)));
            Assert.That(jsonClass.OptionalDictionary, Is.EqualTo(default(Dictionary <string, int>)));
            Assert.That(jsonClass.OptionalGuid, Is.EqualTo(default(Guid)));
            Assert.That(jsonClass.OptionalList, Is.EqualTo(default(List <int>)));
            Assert.That(jsonClass.OptionalNullableInt, Is.EqualTo(default(int?)));
            Assert.That(jsonClass.OptionalNullableBoolean, Is.EqualTo(default(bool?)));
            Assert.That(jsonClass.OptionalNullableDateTime, Is.EqualTo(default(DateTime?)));
            Assert.That(jsonClass.OptionalNullableDateTimeOffset, Is.EqualTo(default(DateTimeOffset?)));
            Assert.That(jsonClass.OptionalNullableGuid, Is.EqualTo(default(Guid?)));
            Assert.That(jsonClass.OptionalString, Is.EqualTo(default(string)));
        }
Пример #28
0
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = "{\"Aaa\":\"one\",\"Abb\":\"two\",\"Aab\":\"three\"}";
            var jsonClass = new CollisionJsonClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.Aaa, Is.EqualTo("one"));
            Assert.That(jsonClass.Abb, Is.EqualTo("two"));
            Assert.That(jsonClass.Aab, Is.EqualTo("three"));
        }
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = ExpectedJson;
            var jsonClass = new JsonIgnoredPropertyClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.Age, Is.EqualTo(42));
            Assert.That(jsonClass.Height, Is.EqualTo(176));
            Assert.That(jsonClass.Escaping, Is.EqualTo(12));
        }
Пример #30
0
        public void FromJson_CorrectJsonClass()
        {
            //arrange
            var json      = "{\r\n\"FirstName\": \"Bob\",\r\n\t\"LastName\":\r   \"Marley\",\n\"NullProperty\": null\n}";
            var jsonClass = new JsonClass();

            //act
            _convert.FromJson(jsonClass, json);

            //assert
            Assert.That(jsonClass.FirstName, Is.EqualTo("Bob"));
            Assert.That(jsonClass.LastName, Is.EqualTo("Marley"));
            Assert.That(jsonClass.NullProperty, Is.EqualTo(null));
        }