Exemplo n.º 1
0
        public void ShouldInclude()
        {
            //Arrange
            var srcDoc     = ConfigDocument.Load("{/*include:123*/\"foo\": \"bar\"}");
            var includeDoc = ConfigDocument.Load("{\"baz\":\"quux\"}");

            _output.WriteLine("Source:");
            _output.WriteLine(srcDoc.Serialize(true));
            _output.WriteLine("");
            _output.WriteLine("Include:");
            _output.WriteLine(includeDoc.Serialize(true));
            _output.WriteLine("");

            var includes = srcDoc.GetIncludes().ToArray();

            //Act
            includes.First().Resolve(includeDoc);

            _output.WriteLine("Result:");
            _output.WriteLine(srcDoc.Serialize(true));

            //Assert
            Assert.Single(includes);
            Assert.Equal("{\"foo\":\"bar\",\"baz\":\"quux\"}", srcDoc.Serialize(false));
        }
Exemplo n.º 2
0
        public async Task <ConfigInfo> LoadInclude(string id)
        {
            var str = await File.ReadAllTextAsync(Path.Combine(IncludePath, id + ".json"));

            var config = ConfigDocument.Load(str);

            return(new ConfigInfo
            {
                Secrets = _secretsAnalyzer.GetSecrets(config).ToArray(),
                Content = JsonPrettify(str)
            });
        }
        public void ShouldApplySecrets()
        {
            //Arrange
            var secretProvider = new DefaultSecretsProvider("[{ \"key\": \"some-secret\", \"value\": \"some-val\" }]");
            var config         = ConfigDocument.Load("{\"secret\":\"[secret:some-secret]\"}");

            //Act
            config.ApplySecrets(secretProvider);

            //Assert
            Assert.Equal("{\"secret\":\"some-val\"}", config.Serialize(false));
        }
        public async Task ShouldUseBaseValueWhenConflict()
        {
            //Arrange
            var doc             = ConfigDocument.Load(SrcConfig);
            var includeProvider = new TestIncludeProvider(IncludeSimple);

            //Act
            await doc.ApplyIncludes(includeProvider);

            var res = TestModel.Create(doc);

            //Assert
            Assert.Equal("from-base-val", res.IncludeConflict);
        }
        public async Task ShouldResolveIncludes()
        {
            //Arrange
            var doc             = ConfigDocument.Load(SrcConfig);
            var includeProvider = new TestIncludeProvider(IncludeSimple);

            //Act
            await doc.ApplyIncludes(includeProvider);

            var res = TestModel.Create(doc);

            //Assert
            Assert.Equal("from-include-val", res.Included);
        }
        public void ShouldOverrideSubElements()
        {
            //Arrange
            var originDoc   = ConfigDocument.Load(SrcConfig);
            var overrideDoc = ConfigDocument.Load(OverrideConfig);
            var overrides   = overrideDoc.CreateOverrides();

            //Act
            originDoc.ApplyOverrides(overrides);

            var res = TestModel.Create(originDoc);

            //Assert
            Assert.Equal("NewBarVal", res.InnerObject.Bar);
        }
        public void ShouldOverride()
        {
            //Arrange
            var originDoc   = ConfigDocument.Load(SrcConfig);
            var overrideDoc = ConfigDocument.Load(OverrideConfig);
            var overrides   = overrideDoc.CreateOverrides();

            //Act
            originDoc.ApplyOverrides(overrides);

            var res = TestModel.Create(originDoc);

            //Assert
            Assert.Equal("NewVal", res.ParamForOverride);
        }
Exemplo n.º 8
0
        public async Task <ConfigDocument> LoadConfigCore(string id)
        {
            var originStr = await File.ReadAllTextAsync(Path.Combine(ConfigsPath, id + ".json"));

            var originDoc = ConfigDocument.Load(originStr);

            await originDoc.ApplyIncludes(new DefaultIncludeProvider(IncludePath));

            var overridePath  = Path.Combine(OverridesPath, id + ".json");
            var overridingStr = File.Exists(overridePath) ? await File.ReadAllTextAsync(overridePath) : null;

            if (!string.IsNullOrWhiteSpace(overridingStr))
            {
                var overrideDoc = ConfigDocument.Load(overridingStr);
                originDoc.ApplyOverride(overrideDoc);
            }

            return(originDoc);
        }
        public async Task ShouldIncludeOneItemArray()
        {
            //Arrange
            const string includeArray =
                "{" +
                "\"IncludedArray\":[\"foo\"]," +
                "\"IncludeConflict\":\"from-include-val\"" +
                "}";
            var doc             = ConfigDocument.Load(SrcConfig);
            var includeProvider = new TestIncludeProvider(includeArray);

            //Act
            await doc.ApplyIncludes(includeProvider);

            var res = TestModel.Create(doc);

            //Assert
            Assert.NotNull(res.IncludedArray);
            Assert.Single(res.IncludedArray);
            Assert.Equal("foo", res.IncludedArray[0]);
        }
 public Task <ConfigDocument> GetInclude(string id)
 {
     return(Task.FromResult(ConfigDocument.Load(_cfg)));
 }