public void Calls_Handle_on_each_component() { var events = new List <IEvent>(); var eventHandler1 = Substitute.For <IEventHandler>(); var eventHandler2 = Substitute.For <IEventHandler>(); IEnumerable <IEventHandler> componentEventHandlers = new IEventHandler[] { eventHandler1, eventHandler2 }; var compositeEventHandler = new CompositeEventHandler(componentEventHandlers); compositeEventHandler.Handle(events); eventHandler1.Received(1).Handle(Arg.Is(events)); eventHandler2.Received(1).Handle(Arg.Is(events)); }
private void RunUploadLauncher(UploadLauncher uploadLauncher) { if (File.Exists(LogFileName)) { File.Delete(LogFileName); } IEnumerable <IUploadEventHandler> ehs = new List <IUploadEventHandler>() { new ConsoleEventHandler(), new TextFileEventHandler(LogFileName) }; IUploadEventHandler eh = new CompositeEventHandler(ehs); TestContext.WriteLine(String.Format("{0} ; {1}", DateTime.Now.ToLongTimeString(), "Begin")); uploadLauncher.TableProcessor.TableProcessorBegin += eh.HandleTableProcessorBegin; uploadLauncher.TableProcessor.TableProcessorEnd += eh.HandleTableProcessorEnd; uploadLauncher.TableProcessor.TableProcessorException += eh.HandleTableProcessorException; uploadLauncher.Launch(); TestContext.WriteLine(String.Format("{0} ; {1}", DateTime.Now.ToLongTimeString(), "End")); TestContext.WriteLine("Done"); }
public void RequestHandler_LogsInnerHandlers() { var eventHandler = new CompositeEventHandler(new[] { new TestEventHandler(), new TestMessageEventHandler().ToEventHandler() }); var blockActionHandler = new CompositeBlockActionHandler(new[] { new TestAsyncBlockActionHandler(), new TestBlockActionHandler().ToBlockActionHandler(), new TestAsyncButtonActionHandler().ToBlockActionHandler(), new TestButtonActionHandler().ToBlockActionHandler(), new TestSpecificButtonActionHandler().ToBlockActionHandler("matching") }); var interactiveMessageHandler = new SwitchingInteractiveMessageHandler(new TestHandlerIndex <IInteractiveMessageHandler> { ["matching"] = new TestInteractiveMessageHandler() }); var dialogSubmissionHandler = new SwitchingDialogSubmissionHandler(new TestHandlerIndex <IDialogSubmissionHandler> { ["matching"] = new TestDialogSubmissionHandler() }); var messageShortcutHandler = new CompositeMessageShortcutHandler(new[] { new TestAsyncMessageShortcutHandler(), new TestMessageShortcutHandler().ToMessageShortcutHandler(), new TestSpecificMessageShortcutHandler().ToMessageShortcutHandler("matching") }); var globalShortcutHandler = new CompositeGlobalShortcutHandler(new[] { new TestAsyncGlobalShortcutHandler(), new TestGlobalShortcutHandler().ToGlobalShortcutHandler(), new TestSpecificGlobalShortcutHandler().ToGlobalShortcutHandler("matching") }); var viewSubmissionHandler = new SwitchingViewSubmissionHandler(new TestHandlerIndex <IAsyncViewSubmissionHandler> { ["async"] = new TestAsyncViewSubmissionHandler(), ["sync"] = new TestViewSubmissionHandler().ToViewSubmissionHandler() }); var workflowStepEditHandler = new CompositeWorkflowStepEditHandler(new[] { new TestAsyncWorkflowStepEditHandler(), new TestWorkflowStepEditHandler().ToWorkflowStepEditHandler(), new TestSpecificWorkflowStepEditHandler().ToWorkflowStepEditHandler("matching") }); var blockOptionProvider = new SwitchingBlockOptionProvider(new TestHandlerIndex <IBlockOptionProvider> { ["matching"] = new TestBlockOptionProvider() }); var legacyOptionProvider = new SwitchingOptionProvider(new TestHandlerIndex <IOptionProvider> { ["matching"] = new TestLegacyOptionProvider() }); var slashCommandHandler = new SwitchingSlashCommandHandler(new TestHandlerIndex <IAsyncSlashCommandHandler> { ["/async"] = new TestAsyncSlashCommandHandler(), ["/sync"] = new TestSlashCommandHandler().ToSlashCommandHandler() }); _sut.RequestHandler(eventHandler, new EventCallback { Event = new Hello() }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestEventHandler).FullName}"); _sut.RequestHandler(eventHandler, new EventCallback { Event = new MessageEvent() }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestEventHandler).FullName}, {typeof(TestMessageEventHandler).FullName}"); _sut.RequestHandler(blockActionHandler, new BlockActionRequest { Actions = { new StaticSelectAction() } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncBlockActionHandler).FullName}, {typeof(TestBlockActionHandler).FullName}"); _sut.RequestHandler(blockActionHandler, new BlockActionRequest { Actions = { new ButtonAction() } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncBlockActionHandler).FullName}, {typeof(TestBlockActionHandler).FullName}, {typeof(TestAsyncButtonActionHandler).FullName}, {typeof(TestButtonActionHandler).FullName}"); _sut.RequestHandler(blockActionHandler, new BlockActionRequest { Actions = { new ButtonAction { ActionId = "matching" } } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncBlockActionHandler).FullName}, {typeof(TestBlockActionHandler).FullName}, {typeof(TestAsyncButtonActionHandler).FullName}, {typeof(TestButtonActionHandler).FullName}, {typeof(TestSpecificButtonActionHandler).FullName}"); _sut.RequestHandler(interactiveMessageHandler, new InteractiveMessage { Action = new Interaction.Button { Name = "other" } }, "Handled"); _sut.Event.FullMessage().ShouldBe("Handled with <none>"); _sut.RequestHandler(interactiveMessageHandler, new InteractiveMessage { Action = new Interaction.Button { Name = "matching" } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestInteractiveMessageHandler).FullName}"); _sut.RequestHandler(dialogSubmissionHandler, new DialogSubmission { CallbackId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe("Handled with <none>"); _sut.RequestHandler(dialogSubmissionHandler, new DialogSubmission { CallbackId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestDialogSubmissionHandler).FullName}"); _sut.RequestHandler(dialogSubmissionHandler, new DialogCancellation { CallbackId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe("Handled with <none>"); _sut.RequestHandler(dialogSubmissionHandler, new DialogCancellation { CallbackId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestDialogSubmissionHandler).FullName}"); _sut.RequestHandler(messageShortcutHandler, new MessageShortcut { CallbackId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncMessageShortcutHandler).FullName}, {typeof(TestMessageShortcutHandler).FullName}"); _sut.RequestHandler(messageShortcutHandler, new MessageShortcut { CallbackId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncMessageShortcutHandler).FullName}, {typeof(TestMessageShortcutHandler).FullName}, {typeof(TestSpecificMessageShortcutHandler).FullName}"); _sut.RequestHandler(globalShortcutHandler, new GlobalShortcut { CallbackId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncGlobalShortcutHandler).FullName}, {typeof(TestGlobalShortcutHandler).FullName}"); _sut.RequestHandler(globalShortcutHandler, new GlobalShortcut { CallbackId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncGlobalShortcutHandler).FullName}, {typeof(TestGlobalShortcutHandler).FullName}, {typeof(TestSpecificGlobalShortcutHandler).FullName}"); _sut.RequestHandler(viewSubmissionHandler, new ViewSubmission { View = new HomeViewInfo { CallbackId = "async" } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncViewSubmissionHandler).FullName}"); _sut.RequestHandler(viewSubmissionHandler, new ViewSubmission { View = new HomeViewInfo { CallbackId = "sync" } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestViewSubmissionHandler).FullName}"); _sut.RequestHandler(viewSubmissionHandler, new ViewClosed { View = new HomeViewInfo { CallbackId = "async" } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncViewSubmissionHandler).FullName}"); _sut.RequestHandler(viewSubmissionHandler, new ViewClosed { View = new HomeViewInfo { CallbackId = "sync" } }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestViewSubmissionHandler).FullName}"); _sut.RequestHandler(workflowStepEditHandler, new WorkflowStepEdit { CallbackId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncWorkflowStepEditHandler).FullName}, {typeof(TestWorkflowStepEditHandler).FullName}"); _sut.RequestHandler(workflowStepEditHandler, new WorkflowStepEdit { CallbackId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncWorkflowStepEditHandler).FullName}, {typeof(TestWorkflowStepEditHandler).FullName}, {typeof(TestSpecificWorkflowStepEditHandler).FullName}"); _sut.RequestHandler(blockOptionProvider, new BlockOptionsRequest { ActionId = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe("Handled with <none>"); _sut.RequestHandler(blockOptionProvider, new BlockOptionsRequest { ActionId = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestBlockOptionProvider).FullName}"); _sut.RequestHandler(legacyOptionProvider, new OptionsRequest { Name = "other" }, "Handled"); _sut.Event.FullMessage().ShouldBe("Handled with <none>"); _sut.RequestHandler(legacyOptionProvider, new OptionsRequest { Name = "matching" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestLegacyOptionProvider).FullName}"); _sut.RequestHandler(slashCommandHandler, new SlashCommand { Command = "/async" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestAsyncSlashCommandHandler).FullName}"); _sut.RequestHandler(slashCommandHandler, new SlashCommand { Command = "/sync" }, "Handled"); _sut.Event.FullMessage().ShouldBe($"Handled with {typeof(TestSlashCommandHandler).FullName}"); }
public void Upload() { var appSettings = ConfigurationManager.AppSettings; String restartConnection, restartTable; restartConnection = appSettings[Constants.AppSettingKeys.RestartConnectionName]; restartTable = appSettings[Constants.AppSettingKeys.RestartTableName]; RestartParameter restartParm; restartParm = null; if (!String.IsNullOrEmpty(restartConnection) && !String.IsNullOrEmpty(restartTable)) { System.Console.WriteLine(String.Format("Configured to restart on {0}/{1}", restartConnection, restartTable)); System.Console.WriteLine("Is this correct? (Y/N)"); System.Console.Beep(); String response = System.Console.ReadLine().Trim().ToUpper(); if (response == "Y") { restartParm = new RestartParameter(); restartParm.ConnectionName = restartConnection; restartParm.TableName = restartTable; } else { System.Console.WriteLine("App.Config must be corrected. Processing is terminated"); System.Console.Read(); return; } } IDictionary <String, String> connStrs = new Dictionary <String, String>(); String connName; connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.Host; connStrs.Add(connName, GetConnectionString(connName, true)); connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.Sql; connStrs.Add(connName, GetConnectionString(connName, true)); connName = VfpToSqlBulkCopy.Utility.Constants.ConnectionNames.POS; String connStr = GetConnectionString(connName, false); if (!String.IsNullOrEmpty(connStr)) { connStrs.Add(connName, connStr); } String logFileName = null; try { logFileName = appSettings[Constants.TableProcessorEventsFileNameAppSettingsKey]; } catch (ConfigurationErrorsException) { logFileName = "TableProcessorEvents.Log"; } IList <IUploadEventHandler> eventHandlers = new List <IUploadEventHandler>() { new ConsoleEventHandler(), new TextFileEventHandler(logFileName) }; eventHandlers.Add(new VfpToSqlBulkCopy.Utility.Events.SqlEventHandler()); IUploadEventHandler eventHandler = new CompositeEventHandler(eventHandlers); UploadLauncher uploadLauncher = new UploadLauncher(connStrs, null, restartParm); uploadLauncher.BeginUpload += eventHandler.HandleUploadBegin; uploadLauncher.TableProcessor.TableProcessorBegin += eventHandler.HandleTableProcessorBegin; uploadLauncher.TableProcessor.TableProcessorEnd += eventHandler.HandleTableProcessorEnd; uploadLauncher.TableProcessor.TableProcessorException += eventHandler.HandleTableProcessorException; uploadLauncher.EndUpload += eventHandler.HandleUploadEnd; uploadLauncher.Launch(); }