public void TestJsonReadOnlyDictionaryToJsonWithStringDictionary()
        {
            // Arrange
            var innerDictionary = new Dictionary <string, string>
            {
                { "one", "1" },
                { "two", "2" },
                { "three", "3" }
            };
            var stringDictionary = new JsonReadOnlyDictionary <string>(innerDictionary);

            // Act
            var toJsonSerializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
            var json = stringDictionary.ToJson(toJsonSerializerSettings);

            this.Output.WriteLine(json);

            // Assert
            Assert.NotNull(json);
            Assert.False(String.IsNullOrEmpty(json));

            var jObject = JObject.Parse(json);

            Assert.NotNull(jObject);
            Assert.Equal(3, jObject.Count);

            Assert.Equal("1", (string)jObject.SelectToken("one"));
            Assert.Equal("2", (string)jObject.SelectToken("two"));
            Assert.Equal("3", (string)jObject.SelectToken("three"));
        }
        public void TestJsonReadOnlyDictionaryToJsonWithObjectDictionary()
        {
            // Arrange
            var emptyObject  = new Empty();
            var personObject = new Person
            {
                PersonId  = "1234",
                FirstName = "John",
                LastName  = "Doe"
            };
            var innerDictionary = new Dictionary <string, object>
            {
                { "oneAsLong", 1 },
                { "twoAsString", "2" },
                { "emptyObject", emptyObject },
                { "personObject", personObject },
            };
            var stringDictionary = new JsonReadOnlyDictionary <object>(innerDictionary);

            // Act
            var toJsonSerializerSettings = new JsonSerializerSettings
            {
                Formatting       = Formatting.Indented,
                TypeNameHandling = TypeNameHandling.Auto
            };
            var json = stringDictionary.ToJson(toJsonSerializerSettings);

            this.Output.WriteLine(json);

            // Assert
            Assert.NotNull(json);
            Assert.False(String.IsNullOrEmpty(json));

            var jObject = JObject.Parse(json);

            Assert.NotNull(jObject);
            Assert.Equal(4, jObject.Count);

            Assert.Equal(1, (long)jObject.SelectToken("oneAsLong"));

            Assert.Equal("2", (string)jObject.SelectToken("twoAsString"));

            var jEmptyObject = (JObject)jObject.SelectToken("emptyObject");

            Assert.Equal(1 + 0, jEmptyObject.Count); // 1 + is for the $type property

            var jPersonObject = (JObject)jObject.SelectToken("personObject");

            Assert.Equal(1 + 3, jPersonObject.Count); // 1 + is for the $type property

            Assert.Equal("1234", (string)jPersonObject.SelectToken(personObject.GetMemberName(x => x.PersonId)));
            Assert.Equal("John", (string)jPersonObject.SelectToken(personObject.GetMemberName(x => x.FirstName)));
            Assert.Equal("Doe", (string)jPersonObject.SelectToken(personObject.GetMemberName(x => x.LastName)));
        }
        public void TestJsonReadOnlyDictionaryToJsonWithEmptyDictionary()
        {
            // Arrange
            var empty = new JsonReadOnlyDictionary <object>(new Dictionary <string, object>());

            // Act
            var toJsonSerializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
            var json = empty.ToJson(toJsonSerializerSettings);

            this.Output.WriteLine(json);

            // Assert
            Assert.NotNull(json);
            Assert.False(String.IsNullOrEmpty(json));

            var jObject = JObject.Parse(json);

            Assert.NotNull(jObject);
            Assert.Equal(0, jObject.Count);
        }