public async void Should_execute()
        {
            Task <ConsumeContext <MagicMade> > received = SubscribeHandler <MagicMade>();

            Uri commandUri = GetCommandContext <MakeMagicHappen>().ExecuteUri;
            var command    = new MakeMagicHappenCommand("Hello, World.");

            DispatchMessageHandle <MakeMagicHappenCommand> handle = await DispatchEndpoint.DispatchMessage(command, commandUri);

            ConsumeContext <DispatchAccepted> accepted = await _accepted;

            Assert.AreEqual(handle.DispatchId, accepted.Message.DispatchId);

            await received;
        }
Example #2
0
        public void Should_execute()
        {
            var received = new TaskCompletionSource<MagicMade>(TestCancellationToken);
            LocalBus.SubscribeHandler<MagicMade>(x => received.SetResult(x));
            Assert.IsTrue(WaitForSubscription<MagicMade>());


            Uri commandUri = GetActivityContext<MakeMagicHappen>().ExecuteUri;
            var command = new MakeMagicHappenCommand("Hello, World.");


            DispatchMessageHandle<MakeMagicHappenCommand> handle = DispatchEndpoint.DispatchMessage(command, commandUri);

            Assert.IsTrue(_accepted.Task.Wait(TestTimeout));
            DispatchAccepted accepted = _accepted.Task.Result;
            Assert.AreEqual(handle.DispatchId, accepted.DispatchId);

            Assert.IsTrue(received.Task.Wait(TestTimeout));
        }
Example #3
0
        public async void Should_succeed_nicely()
        {
            Task <ConsumeContext <HttpRequestSucceeded> >   succeeded = SubscribeHandler <HttpRequestSucceeded>();
            Task <ConsumeContext <HttpRequestFaulted> >     faulted   = SubscribeHandler <HttpRequestFaulted>();
            Task <ConsumeContext <ResourceUsageCompleted> > completed = SubscribeHandler <ResourceUsageCompleted>();


            Uri commandUri = GetCommandContext <ExecuteHttpRequest>().ExecuteUri;

            var webUrl = new Uri("https://help.github.com/");

            var command = new ExecuteHttpRequestCommand(webUrl);


            DispatchMessageHandle <ExecuteHttpRequest> handle = await DispatchEndpoint.DispatchMessage(command, commandUri, webUrl);

            ConsumeContext <DispatchAccepted> accepted = await _accepted;

            Assert.AreEqual(handle.DispatchId, accepted.Message.DispatchId);

            Task waitAny = await Task.WhenAny(succeeded, faulted);

            Console.WriteLine("Request Duration: {0}", (await completed).Message.Duration);
        }
Example #4
0
        public void Should_succeed_nicely()
        {
            var succeeded = new TaskCompletionSource <HttpRequestSucceeded>(TestCancellationToken);

            LocalBus.SubscribeHandler <HttpRequestSucceeded>(x => succeeded.SetResult(x));
            var faulted = new TaskCompletionSource <HttpRequestFaulted>(TestCancellationToken);

            LocalBus.SubscribeHandler <HttpRequestFaulted>(x => faulted.SetResult(x));
            var completed = new TaskCompletionSource <ResourceUsageCompleted>(TestCancellationToken);

            LocalBus.SubscribeHandler <ResourceUsageCompleted>(x => completed.SetResult(x));
            Assert.IsTrue(WaitForSubscription <HttpRequestSucceeded>());
            Assert.IsTrue(WaitForSubscription <HttpRequestFaulted>());
            Assert.IsTrue(WaitForSubscription <ResourceUsageCompleted>());


            Uri commandUri = GetActivityContext <ExecuteHttpRequest>().ExecuteUri;
            var webUrl     = new Uri("https://help.github.com/");

            var command = new ExecuteHttpRequestCommand(webUrl);


            DispatchMessageHandle <ExecuteHttpRequest> handle =
                DispatchEndpoint.DispatchMessage(command, commandUri, webUrl);

            Assert.IsTrue(_accepted.Task.Wait(TestTimeout));
            DispatchAccepted accepted = _accepted.Task.Result;

            Assert.AreEqual(handle.DispatchId, accepted.DispatchId);

            var waitAny = Task.WaitAny(new Task[] { succeeded.Task, faulted.Task }, TestTimeout);

            Assert.AreNotEqual(WaitHandle.WaitTimeout, waitAny);

            Console.WriteLine("Request Duration: {0}", completed.Task.Result.Duration);
        }