Example #1
0
        public void ToJson_Null_CorrectString()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = null
            };

            //act
            var json = ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo("{\"Dictionary\":null}"));
        }
Example #2
0
        public void FromJson_EmptyDictionary_CorrectDictionary()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = new Dictionary <string, string>()
            };

            //act
            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"));
        }
Example #3
0
        public void FromJson_NullDictionary_CorrectDictionary()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = null
            };

            //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"));
        }
Example #4
0
        public void ToJson_CorrectString()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = new Dictionary <string, string>()
                {
                    { "FirstName", "Luke" },
                    { "LastName", "Skywalker" }
                }
            };

            //act
            var json = ToJson(jsonClass);

            //assert
            Assert.That(json.ToString(), Is.EqualTo(ExpectedJson));
        }
Example #5
0
        public void FromJson_PopulatedDictionary_CorrectDictionary()
        {
            //arrange
            var jsonClass = new JsonDictionaryClass()
            {
                Dictionary = new Dictionary <string, string>()
                {
                    { "bar", "asdf" },
                    { "asdg", "asdffs" },
                    { "hghyy", "fdas" }
                }
            };

            //act
            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"));
        }
Example #6
0
 protected abstract ReadOnlySpan <char> FromJson(JsonDictionaryClass value, string json);
Example #7
0
 protected abstract string ToJson(JsonDictionaryClass jsonClass);
Example #8
0
 protected override ReadOnlySpan <char> FromJson(JsonDictionaryClass value, string json)
 {
     return(Encoding.UTF8.GetString(_convert.FromJson(value, Encoding.UTF8.GetBytes(json))));
 }
Example #9
0
        protected override string ToJson(JsonDictionaryClass jsonClass)
        {
            var jsonUtf8 = _convert.ToJsonUtf8(jsonClass);

            return(Encoding.UTF8.GetString(jsonUtf8));
        }
Example #10
0
 protected override ReadOnlySpan <char> FromJson(JsonDictionaryClass value, string json)
 {
     return(_convert.FromJson(value, json));
 }
Example #11
0
 protected override string ToJson(JsonDictionaryClass jsonClass)
 {
     return(_convert.ToJson(jsonClass).ToString());
 }