private static void ShouldBeSingleInstance <TService>(ISlackServiceFactory sut, Func <ISlackServiceFactory, TService> getService, TService service) where TService : class { getService(sut).ShouldBe(service); getService(sut).ShouldBe(service, "Should be same instance"); DuringRequest(sut, _ => getService(sut).ShouldBe(service, "Should be same instance during request")); }
protected void HandleInRequest <THandler, TInput>(ISlackServiceFactory services, Func <ISlackHandlerFactory, SlackRequestContext, THandler> createHandler, Action <THandler, TInput> handle, TInput[] inputs) { DuringRequest(services, ctx => { var handler = createHandler(services.GetHandlerFactory(), ctx); foreach (var input in inputs) { handle(handler, input); } }); }
protected static void DuringRequest(ISlackServiceFactory services, Action <SlackRequestContext> duringRequest) { var requestListener = services.GetRequestListener(); var requestContext = new SlackRequestContext(); requestListener.OnRequestBegin(requestContext); duringRequest(requestContext); requestListener.OnRequestEnd(requestContext); }
protected void HandleLegacyDialogCancellations(ISlackServiceFactory services, DialogCancellation[] cancellations) => HandleInRequest(services, (hf, ctx) => hf.CreateLegacyDialogSubmissionHandler(ctx), (h, c) => h.HandleCancel(c), cancellations);
protected void HandleLegacyDialogSubmissions(ISlackServiceFactory services, DialogSubmission[] submissions) => HandleInRequest(services, (hf, ctx) => hf.CreateLegacyDialogSubmissionHandler(ctx), (h, s) => h.Handle(s), submissions);
protected void HandleLegacyOptionsRequest(ISlackServiceFactory services, OptionsRequest[] requests) => HandleInRequest(services, (hf, ctx) => hf.CreateLegacyOptionProvider(ctx), (h, r) => h.GetOptions(r), requests);
protected void HandleLegacyInteractiveMessages(ISlackServiceFactory services, InteractiveMessage[] messages) => HandleInRequest(services, (hf, ctx) => hf.CreateLegacyInteractiveMessageHandler(ctx), (h, m) => h.Handle(m), messages);
protected void HandleWorkflowStepEdits(ISlackServiceFactory services, Responder responder, WorkflowStepEdit[] edits) => HandleInRequest(services, (hf, ctx) => hf.CreateWorkflowStepEditHandler(ctx), (h, e) => h.Handle(e, responder), edits);
protected void HandleSlashCommands(ISlackServiceFactory services, Responder <SlashCommandResponse> responder, SlashCommand[] commands) => HandleInRequest(services, (hf, ctx) => hf.CreateSlashCommandHandler(ctx), (h, c) => h.Handle(c, responder), commands);
protected void HandleViewCloses(ISlackServiceFactory services, Responder responder, ViewClosed[] closes) => HandleInRequest(services, (hf, ctx) => hf.CreateViewSubmissionHandler(ctx), (h, c) => h.HandleClose(c, responder), closes);
protected void HandleViewSubmissions(ISlackServiceFactory services, Responder <ViewSubmissionResponse> responder, ViewSubmission[] submissions) => HandleInRequest(services, (hf, ctx) => hf.CreateViewSubmissionHandler(ctx), (h, s) => h.Handle(s, responder), submissions);
protected void HandleGlobalShortcuts(ISlackServiceFactory services, Responder responder, GlobalShortcut[] shortcuts) => HandleInRequest(services, (hf, ctx) => hf.CreateGlobalShortcutHandler(ctx), (h, s) => h.Handle(s, responder), shortcuts);
protected void HandleBlockActions(ISlackServiceFactory services, Responder responder, BlockActionRequest[] requests) => HandleInRequest(services, (hf, ctx) => hf.CreateBlockActionHandler(ctx), (h, r) => h.Handle(r, responder), requests);
protected void HandleEvents(ISlackServiceFactory services, EventCallback[] eventCallbacks) => HandleInRequest(services, (hf, ctx) => hf.CreateEventHandler(ctx), (h, e) => h.Handle(e), eventCallbacks);