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 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); }