Beispiel #1
0
        public async Task Dispatcher_MessageHandler_Should_Not_BeAble_ToHandle_AfterRemove()
        {
            CleanRegistrationInDispatcher();
            var message = new TestMessage();

            var h = new TestMessageHandler();

            CoreDispatcher.AddHandlerToDispatcher(h);

            TestMessageHandler.IsHandled.Should().BeFalse();

            await CoreDispatcher.DispatchMessageAsync(message).ConfigureAwait(false);

            TestMessageHandler.IsHandled.Should().BeTrue();

            TestMessageHandler.ResetFlag();

            CoreDispatcher.RemoveHandlerFromDispatcher(h);

            TestMessageHandler.IsHandled.Should().BeFalse();

            await CoreDispatcher.DispatchMessageAsync(message).ConfigureAwait(false);

            TestMessageHandler.IsHandled.Should().BeFalse();
        }
Beispiel #2
0
 public MainPage()
 {
     InitializeComponent();
     CoreDispatcher.AddHandlerToDispatcher(this);
     SayHelloBtn.Clicked += async(s, e) =>
     {
         await CoreDispatcher.DispatchCommandAsync(new SayHello());
     };
 }
        public void TryGetEventHandlerByType_Should_Returns_Instance()
        {
            var h = new TestEventHandler();

            CoreDispatcher.AddHandlerToDispatcher(h);

            var instance = CoreDispatcher.TryGetEventHandlerByType(typeof(TestEventHandler));

            instance.Should().NotBeNull();
            instance.Should().BeOfType <TestEventHandler>();
        }
Beispiel #4
0
 protected BaseViewModel(IScopeFactory?scopeFactory = null)
 {
     if (scopeFactory != null)
     {
         _scope = scopeFactory.CreateScope();
     }
     _logger =
         _scope?.Resolve <ILoggerFactory>()?.CreateLogger(GetType().Name)
         ??
         new LoggerFactory(new[] { new DebugLoggerProvider() }).CreateLogger(GetType().Name);
     CoreDispatcher.AddHandlerToDispatcher(this);
 }
Beispiel #5
0
        public async Task InMemoryEventBus_PublishEventAsync_HandlerInDispatcher()
        {
            CoreDispatcher.AddHandlerToDispatcher(new TestEventContextHandler(1));
            var b = new InMemoryEventBus();

            (await b.PublishEventAsync(new TestEvent {
                Data = "to_ctx"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestEventContextHandler.Data.Should().Be("to_ctx");
            TestEventContextHandler.Dispatcher.Should().Be(1);
        }
Beispiel #6
0
        public async Task InMemoryCommandBus_DispatchAsync_FromCoreDispatcher()
        {
            CleanRegistrationInDispatcher();
            CoreDispatcher.AddHandlerToDispatcher(new TestCommandHandler("coreDispatcher"));
            var bus = new InMemoryCommandBus();

            (await bus.DispatchAsync(new TestCommand {
                Data = "test_dispatcher"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestCommandHandler.HandlerData.Should().Be("test_dispatcher");
            TestCommandHandler.Origin.Should().Be("spec_ctor");
        }
Beispiel #7
0
        public async Task Dispatcher_MessageHandler_Handling_AsExpected()
        {
            CleanRegistrationInDispatcher();
            var message = new TestMessage();

            CoreDispatcher.AddHandlerToDispatcher(new TestMessageHandler());

            TestMessageHandler.IsHandled.Should().BeFalse();

            await CoreDispatcher.DispatchMessageAsync(message).ConfigureAwait(false);

            TestMessageHandler.IsHandled.Should().BeTrue();
        }
        public void CoreDispatcher_RemoveHandlerFromDispatcher_CommandHandler()
        {
            var h = new TestCommandHandler();

            CoreDispatcher.AddHandlerToDispatcher(h);

            var coreHandler = CoreDispatcher.TryGetHandlersForCommandType(typeof(TestCommand));

            coreHandler.Should().NotBeEmpty();

            CoreDispatcher.RemoveHandlerFromDispatcher(h);

            coreHandler = CoreDispatcher.TryGetHandlersForCommandType(typeof(TestCommand));
            coreHandler.Should().BeEmpty();
        }
        public void CoreDispatcher_RemoveHandlerFromDispatcher_EventHandler()
        {
            var h = new TestEventHandler();

            CoreDispatcher.AddHandlerToDispatcher(h);

            var all = CoreDispatcher.TryGetHandlersForEventType(typeof(TestEvent));

            all.Should().HaveCount(1);

            CoreDispatcher.RemoveHandlerFromDispatcher(h);

            all = CoreDispatcher.TryGetHandlersForEventType(typeof(TestEvent));
            all.Should().HaveCount(0);
        }
Beispiel #10
0
        public async Task InMemoryEventBus_PublishEventAsync_HandlerSameInstance_Should_NotBeCalledTwice()
        {
            TestEventContextHandler.CallTimes = 0;
            var h = new TestEventContextHandler(1);

            CoreDispatcher.AddHandlerToDispatcher(new TestEventContextHandler(1));
            CoreDispatcher.AddHandlerToDispatcher(h);
            CoreDispatcher.AddHandlerToDispatcher(h);

            var b = new InMemoryEventBus();

            (await b.PublishEventAsync(new TestEvent {
                Data = "to_ctx"
            }).ConfigureAwait(false)).IsSuccess.Should().BeTrue();

            TestEventContextHandler.Data.Should().Be("to_ctx");
            TestEventContextHandler.Dispatcher.Should().Be(1);
            TestEventContextHandler.CallTimes.Should().Be(1);
        }
Beispiel #11
0
        /// <summary>
        /// Creates a new instance of <see cref="CQEMetroWindow"/>
        /// </summary>
        public CQEMetroWindow()
        {
            Loaded += async(s, e) =>
            {
                if (DataContext is BaseViewModel viewModel)
                {
                    await viewModel.OnLoadCompleteAsync();
                }
            };
            Closing += async(s, e) =>
            {
                if (DataContext is BaseViewModel bvm)
                {
                    var handled = await bvm.OnCloseAsync();

                    if (!handled)
                    {
                        e.Cancel = true;
                    }
                }
            };
            CoreDispatcher.AddHandlerToDispatcher(this);
        }
Beispiel #12
0
 /// <summary>
 /// Creates a new Saga.
 /// </summary>
 protected Saga()
 {
     Id = Guid.NewGuid();
     CoreDispatcher.AddHandlerToDispatcher(this);
 }
 public ContentPageCQELight()
 {
     InitializeComponent();
     CoreDispatcher.AddHandlerToDispatcher(this);
 }