public void StaticAccessorOnUnknownTypeThrowsTypeLoadException(string input, Type targetType) { var stringArgumentValue = new StringArgumentValue(() => $"{input}"); Assert.Throws <TypeLoadException>(() => stringArgumentValue.ConvertTo(targetType, new Dictionary <string, LoggingLevelSwitch>()) ); }
public void StaticAccessorOnUnknownTypeThrowsTypeLoadException(string input, Type targetType) { var stringArgumentValue = new StringArgumentValue($"{input}"); Assert.Throws <TypeLoadException>(() => stringArgumentValue.ConvertTo(targetType, new ResolutionContext()) ); }
public void StringValuesConvertToDefaultInstancesIfTargetIsAbstractClass() { var stringArgumentValue = new StringArgumentValue(() => "Serilog.Settings.Configuration.Tests.Support.ConcreteClass, Serilog.Settings.Configuration.Tests"); var result = stringArgumentValue.ConvertTo(typeof(AbstractClass), new Dictionary <string, LoggingLevelSwitch>()); Assert.IsType <ConcreteClass>(result); }
public void StringValuesConvertToDefaultInstancesIfTargetIsInterface() { var stringArgumentValue = new StringArgumentValue(() => "Serilog.Formatting.Json.JsonFormatter, Serilog"); var result = stringArgumentValue.ConvertTo(typeof(ITextFormatter), new Dictionary <string, LoggingLevelSwitch>()); Assert.IsType <JsonFormatter>(result); }
public void StringValuesConvertToDefaultInstancesIfTargetIsInterface() { var stringArgumentValue = new StringArgumentValue("Serilog.Formatting.Json.JsonFormatter, Serilog"); var result = stringArgumentValue.ConvertTo(typeof(ITextFormatter), new ResolutionContext()); Assert.IsType <JsonFormatter>(result); }
public void StringValuesConvertToDefaultInstancesIfTargetIsAbstractClass() { var stringArgumentValue = new StringArgumentValue("Serilog.Settings.Configuration.Tests.Support.ConcreteClass, Serilog.Settings.Configuration.Tests"); var result = stringArgumentValue.ConvertTo(typeof(AbstractClass), new ResolutionContext()); Assert.IsType <ConcreteClass>(result); }
private void StaticMembersAccessorsCanBeUsedForReferenceTypes(string input, Type targetType) { var stringArgumentValue = new StringArgumentValue(() => $"{input}"); var actual = stringArgumentValue.ConvertTo(targetType, new Dictionary <string, LoggingLevelSwitch>()); Assert.IsAssignableFrom(targetType, actual); Assert.Equal(ConcreteImpl.Instance, actual); }
public void StringValuesConvertToTypeFromAssemblyQualifiedName() { var assemblyQualifiedName = typeof(Version).AssemblyQualifiedName; var stringArgumentValue = new StringArgumentValue(() => assemblyQualifiedName); var actual = (Type)stringArgumentValue.ConvertTo(typeof(Type), new Dictionary <string, LoggingLevelSwitch>()); Assert.Equal(typeof(Version), actual); }
public void StaticMembersAccessorsCanBeUsedForReferenceTypes(string input, Type targetType) { var stringArgumentValue = new StringArgumentValue($"{input}"); var actual = stringArgumentValue.ConvertTo(targetType, new ResolutionContext()); Assert.IsAssignableFrom(targetType, actual); Assert.Equal(ConcreteImpl.Instance, actual); }
public void StringValuesConvertToTypeFromShortTypeName() { var shortTypeName = "System.Version"; var stringArgumentValue = new StringArgumentValue(() => shortTypeName); var actual = (Type)stringArgumentValue.ConvertTo(typeof(Type), new Dictionary <string, LoggingLevelSwitch>()); Assert.Equal(typeof(Version), actual); }
public void StringValuesConvertToTypeFromAssemblyQualifiedName() { var assemblyQualifiedName = typeof(Version).AssemblyQualifiedName; var stringArgumentValue = new StringArgumentValue(assemblyQualifiedName); var actual = (Type)stringArgumentValue.ConvertTo(typeof(Type), new ResolutionContext()); Assert.Equal(typeof(Version), actual); }
public void StringValuesConvertToTypeFromShortTypeName() { var shortTypeName = "System.Version"; var stringArgumentValue = new StringArgumentValue(shortTypeName); var actual = (Type)stringArgumentValue.ConvertTo(typeof(Type), new ResolutionContext()); Assert.Equal(typeof(Version), actual); }
public void StaticAccessorWithInvalidMemberThrowsInvalidOperationException(string input, Type targetType) { var stringArgumentValue = new StringArgumentValue($"{input}"); var exception = Assert.Throws <InvalidOperationException>(() => stringArgumentValue.ConvertTo(targetType, new ResolutionContext()) ); Assert.Contains("Could not find a public static property or field ", exception.Message); Assert.Contains("on type `Serilog.Settings.Configuration.Tests.Support.ClassWithStaticAccessors, Serilog.Settings.Configuration.Tests`", exception.Message); }
public void ReferencingUndeclaredLevelSwitchThrows() { var resolutionContext = new ResolutionContext(); resolutionContext.AddLevelSwitch("$anotherSwitch", new LoggingLevelSwitch(LogEventLevel.Verbose)); var stringArgumentValue = new StringArgumentValue("$mySwitch"); var ex = Assert.Throws <InvalidOperationException>(() => stringArgumentValue.ConvertTo(typeof(LoggingLevelSwitch), resolutionContext) ); Assert.Contains("$mySwitch", ex.Message); Assert.Contains("\"LevelSwitches\":{\"$mySwitch\":", ex.Message); }
public void LevelSwitchesCanBeLookedUpByName() { var @switch = new LoggingLevelSwitch(LogEventLevel.Verbose); var switchName = "$theSwitch"; var resolutionContext = new ResolutionContext(); resolutionContext.AddLevelSwitch(switchName, @switch); var stringArgumentValue = new StringArgumentValue(switchName); var resolvedSwitch = stringArgumentValue.ConvertTo(typeof(LoggingLevelSwitch), resolutionContext); Assert.IsType <LoggingLevelSwitch>(resolvedSwitch); Assert.Same(@switch, resolvedSwitch); }
public void LevelSwitchesCanBeLookedUpByName() { var @switch = new LoggingLevelSwitch(LogEventLevel.Verbose); var switchName = "$theSwitch"; var declaredSwitches = new Dictionary <string, LoggingLevelSwitch>() { { switchName, @switch } }; var stringArgumentValue = new StringArgumentValue(() => switchName); var resolvedSwitch = stringArgumentValue.ConvertTo(typeof(LoggingLevelSwitch), declaredSwitches); Assert.IsType <LoggingLevelSwitch>(resolvedSwitch); Assert.Same(@switch, resolvedSwitch); }
public void ReferencingUndeclaredLevelSwitchThrows() { var declaredSwitches = new Dictionary <string, LoggingLevelSwitch>() { { "$anotherSwitch", new LoggingLevelSwitch(LogEventLevel.Verbose) } }; var stringArgumentValue = new StringArgumentValue(() => "$mySwitch"); var ex = Assert.Throws <InvalidOperationException>(() => stringArgumentValue.ConvertTo(typeof(LoggingLevelSwitch), declaredSwitches) ); Assert.Contains("$mySwitch", ex.Message); Assert.Contains("\"LevelSwitches\":{\"$mySwitch\":", ex.Message); }
public void TryParseStaticMemberAccessorReturnsExpectedResults(string input, string expectedAccessorType, string expectedPropertyName) { var actual = StringArgumentValue.TryParseStaticMemberAccessor(input, out var actualAccessorType, out var actualMemberName); if (expectedAccessorType == null) { Assert.False(actual, $"Should not parse {input}"); } else { Assert.True(actual, $"should successfully parse {input}"); Assert.Equal(expectedAccessorType, actualAccessorType); Assert.Equal(expectedPropertyName, actualMemberName); } }
public void FindTypeSupportsSimpleNamesForSerilogTypes(string input, Type targetType) { var type = StringArgumentValue.FindType(input); Assert.Equal(targetType, type); }