public async Task TestApplyFail(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", HandlerDescription = new SystemSettingHandlerDescription("thesetting", valueKind) }; var handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { Assert.Equal(value, nvalue); }; var pass = await handler.Apply(value); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(0, setCount); Assert.False(pass); }
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 TestApplyExceptions() { 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", Kind = Setting.ValueKind.Boolean, HandlerDescription = new SystemSettingHandlerDescription("thesetting", SystemValueKind.Boolean) }; createCount = 0; getCount = 0; setCount = 0; var handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new ArgumentException(); }; var pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); createCount = 0; getCount = 0; setCount = 0; handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new ArgumentNullException(); }; pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); createCount = 0; getCount = 0; setCount = 0; handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new SecurityException(); }; pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); createCount = 0; getCount = 0; setCount = 0; handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new ObjectDisposedException("ayylmao"); }; pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); createCount = 0; getCount = 0; setCount = 0; handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new System.IO.IOException(); }; pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); createCount = 0; getCount = 0; setCount = 0; handler = new SystemSettingHandler(setting, mockFactory, serviceProvider, logger); MockSystemSetting.nextSetResponder = (object nvalue) => { throw new UnauthorizedAccessException(); }; pass = await handler.Apply(true); Assert.Equal(1, createCount); Assert.Equal(0, getCount); Assert.Equal(1, setCount); Assert.False(pass); }