Exemplo n.º 1
0
        public async Task ShouldHandleNotification()
        {
            var inputStream           = new MemoryStream(Encoding.ASCII.GetBytes("Content-Length: 2\r\n\r\n{}"));
            var outputHandler         = Substitute.For <IOutputHandler>();
            var reciever              = Substitute.For <IReceiver>();
            var incomingRequestRouter = Substitute.For <IRequestRouter <IHandlerDescriptor> >();

            var notification = new Notification("abc", null);

            reciever.IsValid(Arg.Any <JToken>()).Returns(true);
            reciever.GetRequests(Arg.Any <JToken>())
            .Returns(c => (new Renor[] { notification }, false));

            using (NewHandler(
                       inputStream,
                       outputHandler,
                       reciever,
                       Substitute.For <IRequestProcessIdentifier>(),
                       incomingRequestRouter,
                       Substitute.For <IResponseRouter>(),
                       cts => {
                incomingRequestRouter.When(x => x.RouteNotification(Arg.Any <IHandlerDescriptor>(), Arg.Any <Notification>(), CancellationToken.None))
                .Do(x => {
                    cts.Cancel();
                });
            }))
            {
                await incomingRequestRouter.Received().RouteNotification(Arg.Any <IHandlerDescriptor>(), notification, CancellationToken.None);
            }
        }
 private SchedulerDelegate RouteNotification(
     IRequestDescriptor <IHandlerDescriptor?> descriptors,
     Notification notification) =>
 (_, scheduler) =>
 // ITS A RACE!
 Observable.Amb(
     Observable.Timer(_options.RequestTimeout, scheduler)
     .Select(_ => Unit.Default)
     .Do(
         _ => _logger.LogTrace("Notification was cancelled due to timeout")
         ),
     Observable.FromAsync(
        public override void InvokeNotification(IRequestDescriptor <IHandlerDescriptor?> descriptor, Notification notification)
        {
            if (descriptor.Default is null)
            {
                throw new ArgumentNullException(nameof(descriptor.Default));
            }

            var type = _requestProcessIdentifier.Identify(descriptor.Default);
            var schedulerDelegate = RouteNotification(descriptor, notification);

            _processScheduler.Add(type, notification.Method, schedulerDelegate);
        }
 public abstract void InvokeNotification(IRequestDescriptor <IHandlerDescriptor?> descriptor, Notification notification);