public async Task TestCapturePass(Setting.ValueKind kind, SystemValueKind valueKind, object systemValue, object value)
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddSingleton <IServiceProvider>(provider => provider);
            services.AddSingleton <ISystemSettingFactory, MockSystemSettingFactory>();
            var mockFactory     = new MockSystemSettingFactory();
            var serviceProvider = services.BuildServiceProvider();
            var loggerFactory   = new LoggerFactory();
            var logger          = loggerFactory.CreateLogger <SystemSettingHandler>();

            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            var handlerDescription = new SystemSettingHandlerDescription("thesetting", valueKind);

            handlerDescription.IntegerMap = new string[3] {
                "zero", "one", "two"
            };
            handlerDescription.ReverseIntegerMap = new Dictionary <string, long> {
                { "zero", 0L }, { "one", 1L }, { "two", 2L }
            };
            var setting = new Setting()
            {
                Name = "test",
                Kind = kind,
                HandlerDescription = handlerDescription
            };
            var handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);

            MockSystemSetting.nextGetResponder = () =>
            {
                return(systemValue);
            };

            var result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.True(result.Success);
            Assert.NotNull(result.Value);
            Assert.Equal(value, result.Value);
        }
        public async Task TestCaptureFail(Setting.ValueKind kind, SystemValueKind valueKind, object value)
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddSingleton <IServiceProvider>(provider => provider);
            services.AddSingleton <ISystemSettingFactory, MockSystemSettingFactory>();
            var mockFactory     = new MockSystemSettingFactory();
            var serviceProvider = services.BuildServiceProvider();
            var loggerFactory   = new LoggerFactory();
            var logger          = loggerFactory.CreateLogger <SystemSettingHandler>();

            createCount = 0;
            getCount    = 0;
            setCount    = 0;

            var setting = new Setting()
            {
                Name = "test",
                Kind = kind,
                HandlerDescription = new SystemSettingHandlerDescription("thesetting", valueKind)
            };
            var handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);

            MockSystemSetting.nextGetResponder = () =>
            {
                return(value);
            };

            var result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
        }
        public async Task TestCaptureExceptions()
        {
            var services = new ServiceCollection();

            services.AddLogging();
            services.AddSingleton <IServiceProvider>(provider => provider);
            services.AddSingleton <ISystemSettingFactory, MockSystemSettingFactory>();
            var mockFactory     = new MockSystemSettingFactory();
            var serviceProvider = services.BuildServiceProvider();
            var loggerFactory   = new LoggerFactory();
            var logger          = loggerFactory.CreateLogger <SystemSettingHandler>();

            var setting = new Setting()
            {
                Name = "test",
                HandlerDescription = new SystemSettingHandlerDescription("thesetting", SystemValueKind.Boolean)
            };

            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            var handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);

            MockSystemSetting.nextGetResponder = () =>
            {
                throw new ArgumentException();
            };
            var result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            handler     = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);
            MockSystemSetting.nextGetResponder = () =>
            {
                throw new ArgumentNullException();
            };
            result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            handler     = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);
            MockSystemSetting.nextGetResponder = () =>
            {
                throw new SecurityException();
            };
            result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            handler     = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);
            MockSystemSetting.nextGetResponder = () =>
            {
                throw new ObjectDisposedException("ayylmao");
            };
            result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            handler     = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);
            MockSystemSetting.nextGetResponder = () =>
            {
                throw new System.IO.IOException();
            };
            result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
            createCount = 0;
            getCount    = 0;
            setCount    = 0;
            handler     = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger);
            MockSystemSetting.nextGetResponder = () =>
            {
                throw new UnauthorizedAccessException();
            };
            result = await handler.Capture();

            Assert.Equal(1, createCount);
            Assert.Equal(1, getCount);
            Assert.Equal(0, setCount);
            Assert.False(result.Success);
            Assert.Null(result.Value);
        }