public InstalledAppTokenManager(ILogger <IInstalledAppTokenManager> logger,
                                 IInstalledAppManager installedAppManager)
 {
     _logger = logger ??
               throw new ArgumentNullException(nameof(logger));
     _installedAppManager = installedAppManager ??
                            throw new ArgumentNullException(nameof(installedAppManager));
 }
コード例 #2
0
 public MyEventWebhookHandler(ILogger <EventWebhookHandler> logger,
                              IInstalledAppManager installedAppManager,
                              IStateManager <MyState> stateManager,
                              IInstallUpdateWebhookHandler installUpdateHandler)
     : base(logger, installedAppManager)
 {
     this.stateManager         = stateManager;
     this.installUpdateHandler = installUpdateHandler;
 }
コード例 #3
0
        protected UninstallWebhookHandler(ILogger <IUninstallWebhookHandler> logger,
                                          IInstalledAppManager installedAppManager)
        {
            _ = logger ?? throw new ArgumentNullException(nameof(logger));
            _ = installedAppManager ?? throw new ArgumentNullException(nameof(installedAppManager));

            this.Logger = logger;
            this.InstalledAppManager = installedAppManager;
        }
コード例 #4
0
 public MyUninstallWebhookHandler(ILogger <UninstallWebhookHandler> logger,
                                  IInstalledAppManager installedAppManager,
                                  IStateManager <MyState> stateManager)
     : base(logger, installedAppManager)
 {
     _ = stateManager ??
         throw new ArgumentNullException(nameof(stateManager));
     this.stateManager = stateManager;
 }
コード例 #5
0
 public InstalledAppTokenManagerService(ILogger <IInstalledAppTokenManager> logger,
                                        IInstalledAppManager installedAppManager,
                                        IOptions <InstalledAppTokenManagerConfig> options)
     : base(logger, installedAppManager)
 {
     _logger = logger ??
               throw new ArgumentNullException(nameof(logger));
     _installedAppTokenManagerConfig = options?.Value ??
                                       throw new ArgumentNullException(nameof(options));
 }
 public MyInstallUpdateDataHandler(ILogger <IInstallUpdateWebhookHandler> logger,
                                   IOptions <SmartAppConfig> options,
                                   IInstalledAppManager installedAppManager,
                                   ISmartThingsAPIHelper smartThingsAPIHelper,
                                   IStateManager <MyState> stateManager)
     : base(logger, options, installedAppManager, smartThingsAPIHelper)
 {
     _ = stateManager ?? throw new ArgumentNullException(nameof(stateManager));
     this.stateManager = stateManager;
 }
コード例 #7
0
 public MyService(ILogger <IMyService> logger,
                  IRootWebhookHandler rootHandler,
                  IStateManager <MyState> stateManager,
                  IInstalledAppManager installedAppManager,
                  ISmartThingsAPIHelper smartThingsAPIHelper)
 {
     _logger               = logger ?? throw new ArgumentNullException(nameof(logger));
     _rootHandler          = rootHandler ?? throw new ArgumentNullException(nameof(rootHandler));
     _stateManager         = stateManager ?? throw new ArgumentNullException(nameof(stateManager));
     _installedAppManager  = installedAppManager ?? throw new ArgumentNullException(nameof(installedAppManager));
     _smartThingsAPIHelper = smartThingsAPIHelper ?? throw new ArgumentNullException(nameof(smartThingsAPIHelper));
 }
コード例 #8
0
        protected InstallUpdateWebhookHandler(ILogger <IInstallUpdateWebhookHandler> logger,
                                              IOptions <SmartAppConfig> options,
                                              IInstalledAppManager installedAppManager,
                                              ISmartThingsAPIHelper smartThingsAPIHelper)
        {
            _ = logger ??
                throw new ArgumentNullException(nameof(logger));
            _ = options ??
                throw new ArgumentNullException(nameof(options));
            _ = installedAppManager ??
                throw new ArgumentNullException(nameof(installedAppManager));
            _ = smartThingsAPIHelper ??
                throw new ArgumentNullException(nameof(smartThingsAPIHelper));

            this.Logger               = logger;
            this.AppConfig            = options.Value;
            this.InstalledAppManager  = installedAppManager;
            this.SmartThingsAPIHelper = smartThingsAPIHelper;
        }
コード例 #9
0
        public FileBackedTests(ITestOutputHelper output)
        {
            _mockIALogger    = new Mock <ILogger <IInstalledAppManager> >();
            _mockStateLogger = new Mock <ILogger <IStateManager <string> > >();
            _mockIALogger.Setup(log => log.Log(It.IsAny <Microsoft.Extensions.Logging.LogLevel>(),
                                               It.IsAny <EventId>(),
                                               It.IsAny <object>(),
                                               null,
                                               It.IsAny <Func <object, Exception, string> >()))
            .Callback <Microsoft.Extensions.Logging.LogLevel,
                       EventId,
                       object,
                       Exception,
                       Func <object, Exception, string> >((logLevel, e, state, ex, f) =>
            {
                output.WriteLine($"{logLevel} logged: \"{state}\"");
            });
            _mockStateLogger.Setup(log => log.Log(It.IsAny <Microsoft.Extensions.Logging.LogLevel>(),
                                                  It.IsAny <EventId>(),
                                                  It.IsAny <object>(),
                                                  null,
                                                  It.IsAny <Func <object, Exception, string> >()))
            .Callback <Microsoft.Extensions.Logging.LogLevel,
                       EventId,
                       object,
                       Exception,
                       Func <object, Exception, string> >((logLevel, e, state, ex, f) =>
            {
                output.WriteLine($"{logLevel} logged: \"{state}\"");
            });

            _mockSmartThingsAPIHelper = new Mock <ISmartThingsAPIHelper>();
            _mockSmartThingsAPIHelper.Setup(api => api.RefreshTokensAsync(It.IsAny <InstalledAppInstance>()))
            .Returns(() =>
            {
                return(Task.FromResult <InstalledAppInstance>(CommonUtils.GetValidInstalledAppInstance()));
            });

            var iaConfig = new FileBackedConfig <FileBackedInstalledAppManager>()
            {
                BackingStorePath = "data/ia.store"
            };

            var stateConfig = new FileBackedConfig <FileBackedStateManager <string> >()
            {
                BackingStorePath = "data/state.store"
            };

            _mockIAOptions = new Mock <IOptions <FileBackedConfig <FileBackedInstalledAppManager> > >();
            _mockIAOptions.Setup(opt => opt.Value)
            .Returns(iaConfig);

            _mockStateOptions = new Mock <IOptions <FileBackedConfig <FileBackedStateManager <string> > > >();
            _mockStateOptions.Setup(opt => opt.Value)
            .Returns(stateConfig);

            var mockIAFileData = new MockFileData(JsonConvert.SerializeObject(CommonUtils.GetIACache()));

            var mockStateFileData = new MockFileData(JsonConvert.SerializeObject(CommonUtils.GetStateCache()));

            var mockFileSystem = new MockFileSystem();

            mockFileSystem.AddFile("data/ia.store", mockIAFileData);

            mockFileSystem.AddFile("data/state.store", mockStateFileData);

            _mockFileBackedConfigIAValidator = new Mock <FileBackedConfigValidator <FileBackedInstalledAppManager> >();

            _installedAppManager = new FileBackedInstalledAppManager(_mockIALogger.Object,
                                                                     _mockSmartThingsAPIHelper.Object,
                                                                     _mockIAOptions.Object,
                                                                     _mockFileBackedConfigIAValidator.Object,
                                                                     mockFileSystem);

            _mockFileBackedConfigStateValidator = new Mock <FileBackedConfigValidator <FileBackedStateManager <string> > >();

            _stateManager = new FileBackedStateManager <string>(_mockStateLogger.Object,
                                                                _mockStateOptions.Object,
                                                                _mockFileBackedConfigStateValidator.Object,
                                                                mockFileSystem);
        }