public void StaticAccessorOnUnknownTypeThrowsTypeLoadException(string input, Type targetType)
        {
            var stringArgumentValue = new StringArgumentValue(() => $"{input}");

            Assert.Throws <TypeLoadException>(() =>
                                              stringArgumentValue.ConvertTo(targetType, new Dictionary <string, LoggingLevelSwitch>())
                                              );
        }
        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);
        }
Ejemplo n.º 4
0
        public void StringValuesConvertToDefaultInstancesIfTargetIsInterface()
        {
            var stringArgumentValue = new StringArgumentValue("Serilog.Formatting.Json.JsonFormatter, Serilog");

            var result = stringArgumentValue.ConvertTo(typeof(ITextFormatter), new ResolutionContext());

            Assert.IsType <JsonFormatter>(result);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        public void StaticAccessorOnUnknownTypeThrowsTypeLoadException(string input, Type targetType)
        {
            var stringArgumentValue = new StringArgumentValue($"{input}");

            Assert.Throws <TypeLoadException>(() =>
                                              stringArgumentValue.ConvertTo(targetType, new ResolutionContext())
                                              );
        }
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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);
        }