Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intercept Reflection exceptions from AppSettingsConfigurationStore #1210

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,36 @@
#if !NETSTANDARD1_3 && !NETSTANDARD1_6

namespace FluentAssertions.Common
{
internal class ConfigurationStoreExceptionInterceptor : IConfigurationStore
{
private bool underlyingStoreUnavailable;

private readonly IConfigurationStore configurationStore;

public ConfigurationStoreExceptionInterceptor(IConfigurationStore configurationStore)
{
this.configurationStore = configurationStore;
}

public string GetSetting(string name)
{
if (underlyingStoreUnavailable)
{
return null;
}

try
{
return configurationStore.GetSetting(name);
}
catch
{
underlyingStoreUnavailable = true;
return null;
}
}
}
}

#endif
2 changes: 1 addition & 1 deletion Src/FluentAssertions/Common/Services.cs
Expand Up @@ -48,7 +48,7 @@ public static void ResetToDefaults()
ConfigurationStore = new NullConfigurationStore();
#else
Reflector = new FullFrameworkReflector();
ConfigurationStore = new AppSettingsConfigurationStore();
ConfigurationStore = new ConfigurationStoreExceptionInterceptor(new AppSettingsConfigurationStore());
#endif

ThrowException = TestFrameworkProvider.Throw;
Expand Down