Skip to content

Commit

Permalink
Merge branch 'ignore-unknown-property'
Browse files Browse the repository at this point in the history
  • Loading branch information
christianspecht committed Jun 5, 2024
2 parents 4d13e93 + 4392121 commit 1a81e03
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/ScmBackup.Tests.Integration/ConfigReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,14 @@ public void ThrowsExceptionWhenConfigFileIsNotVaild()

Assert.ThrowsAny<YamlException>(() => sut.ReadConfig());
}

[Fact]
public void IgnoresUnknownProperties_Issue76()
{
var sut = new ConfigReader();
sut.ConfigFileName = "settings-unknown-property.yml";

var config = sut.ReadConfig(); // should just ignore the unknown property and NOT throw an exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<None Update="Scm\FakeCommandLineScmTools\FakeCommandLineScm-Command-Windows.bat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="settings-unknown-property.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="testsettings.yml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
5 changes: 5 additions & 0 deletions src/ScmBackup.Tests.Integration/settings-unknown-property.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
localFolder: 'c:\scm-backup'

# this property doesn't exist in the config class:
unknownProperty:
foo: bar
5 changes: 4 additions & 1 deletion src/ScmBackup/Configuration/ConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public Config ReadConfig()
this.config = new Config();

var input = File.ReadAllText(this.ConfigFileName);
var deserializer = new DeserializerBuilder().WithNamingConvention(CamelCaseNamingConvention.Instance).Build();
var deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
this.config = deserializer.Deserialize<Config>(input);
}

Expand Down

0 comments on commit 1a81e03

Please sign in to comment.