public void Convert_FromDocumentModelToJsont()
        {
            var model = MockAssets.SeedDocumentTestDocument();

            var expectedJson = MockAssets.SeedJsonDocument(model);

            var actualJson = _sut.Convert(model);

            actualJson.Should().BeEquivalentTo(expectedJson);
        }
        public void ResourcesWithMixedKeys_MixedOrder()
        {
            var sut = new JsonConverter(new QueryExecutor(new ConfigurationContext().TypeFactory));

            var resources = new List <LocalizationResource>
            {
                new LocalizationResource("This.Is.Resource.Key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.Resource.AnotherKey", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.YetAnotherResource.AnotherKey", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english 2"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is another norsk 2"
                        }
                    }
                }
            };

            var resourcesAsJson = sut.Convert(resources, "en", CultureInfo.InvariantCulture, false);

            Assert.Equal("this is english", resourcesAsJson["This"]["Is"]["Resource"]["Key"]);
        }
        public void ResourcesWithMixedKeys_MixedOrder()
        {
            var sut = new JsonConverter();

            var resources = new List <LocalizationResource>
            {
                new LocalizationResource("This.Is.Resource.Key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.Resource.AnotherKey")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.YetAnotherResource.AnotherKey")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english 2"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is another norsk 2"
                        }
                    }
                }
            };

            var resourcesAsJson = sut.Convert(resources, "en", true, false);

            Assert.Equal("this is english", resourcesAsJson["This"]["Is"]["Resource"]["Key"]);
        }
Beispiel #4
0
        public void ThrowJsonExceptionWhenTryingToConvertImproperlyFormattedJsonToEntity()
        {
            var converter = new JsonConverter <TestClass>();

            Action action = () => converter.Convert(GetSampleImproperlyFormattedJson());

            action.Should().Throw <JsonException>();
        }
Beispiel #5
0
        public void ConvertReturnsString()
        {
            JsonConverter converter      = new JsonConverter();
            string        convertedValue = converter.Convert(new TestClass {
                Name = "name"
            });

            Assert.Equal("{\"Name\":\"name\"}", convertedValue);
        }
Beispiel #6
0
        public void ConvertJsonToEntity()
        {
            var converter = new JsonConverter <TestClass>();

            TestClass expected = GetSampleClass();
            var       actual   = converter.Convert(GetSampleJson());

            actual.Should().BeOfType(typeof(TestClass));
            ((TestClass)actual).Should().BeEquivalentTo(expected);
        }
Beispiel #7
0
        private void ExportData()
        {
            //_server.Write(_graphConverter.ToJson());

            //return;
            var toJson = new OuterJsonExportFormat {
                IsGameRunning = _gameReader.IsActive,
                Data          = _aggregator.Export()
            };
            var json = JsonConverter.Convert(toJson);

            _browser.JsPojo.GraphJson = json;
            _server.Write(json);
        }
Beispiel #8
0
        public void ConvertImproperlyFormattedJsonToEntityWhenUsingCorrectOptions()
        {
            var converter = new JsonConverter <TestClass>(new JsonSerializerOptions()
            {
                AllowTrailingCommas         = true,
                PropertyNameCaseInsensitive = true
            });

            TestClass expected = GetSampleClass();
            var       actual   = converter.Convert(GetSampleImproperlyFormattedJson());

            actual.Should().BeOfType(typeof(TestClass));
            ((TestClass)actual).Should().BeEquivalentTo(expected);
        }
        public void VariousResources_WithMixedKeyNames()
        {
            var resources = new List <LocalizationResource>
            {
                new LocalizationResource("/another/mixmatch/key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english"
                        }
                    }
                },
                new LocalizationResource("This.Is.Resource.Key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.AnotherResource.Key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this is another english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this is another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Totally.Another.Resource.Key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this totally another english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this totally another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.Back.Resource.Key", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this is back english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this is back norsk"
                        }
                    }
                },
                new LocalizationResource("This.Resource.Is.The.Last.Resource", false)
                {
                    Translations = new LocalizationResourceTranslationCollection(false)
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "last"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "siste"
                        }
                    }
                }
            };

            var sut = new JsonConverter(new QueryExecutor(new ConfigurationContext().TypeFactory));

            var resourcesAsJson = sut.Convert(resources, "en", CultureInfo.InvariantCulture, false);

            Assert.Equal("this is english", resourcesAsJson["This"]["Is"]["Resource"]["Key"]);

            Assert.Single(resourcesAsJson);
        }
        public void VariousResources_WithMixedKeyNames()
        {
            var resources = new List <LocalizationResource>
            {
                new LocalizationResource("/another/mixmatch/key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is another english"
                        }
                    }
                },
                new LocalizationResource("This.Is.Resource.Key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation
                        {
                            Language = "en",
                            Value    = "this is english"
                        },
                        new LocalizationResourceTranslation
                        {
                            Language = "no",
                            Value    = "this is norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.AnotherResource.Key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this is another english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this is another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Totally.Another.Resource.Key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this totally another english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this totally another norsk"
                        }
                    }
                },
                new LocalizationResource("This.Is.Back.Resource.Key")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "this is back english"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "this is back norsk"
                        }
                    }
                },
                new LocalizationResource("This.Resource.Is.The.Last.Resource")
                {
                    Translations = new List <LocalizationResourceTranslation>
                    {
                        new LocalizationResourceTranslation {
                            Language = "en", Value = "last"
                        },
                        new LocalizationResourceTranslation {
                            Language = "no", Value = "siste"
                        }
                    }
                }
            };

            var sut = new JsonConverter();

            var resourcesAsJson = sut.Convert(resources, "en", true, false);

            Assert.Equal("this is english", resourcesAsJson["This"]["Is"]["Resource"]["Key"]);

            Assert.Single(resourcesAsJson);
        }