public RazorOmniSharpRequestInvokerTest()
 {
     Options = new RequestInvokerOptions(
         requestTimeout: TimeSpan.FromSeconds(10),
         supportContentModified: false,
         concurrency: int.MaxValue);
     OutputHandler          = new TestOutputHandler();
     RequestRouter          = new TestRequestRouter(routeDelay: TimeSpan.Zero);
     RequestDescriptor      = new TestRequestDescriptor("textDocument/didOpen");
     Request                = new Request(id: "serial", RequestDescriptor.Default.Method, @params: null);
     NotificationDescriptor = new TestRequestDescriptor("textDocument/didChange");
     Notification           = new Notification(NotificationDescriptor.Default.Method, @params: null);
 }
        private RazorOmniSharpRequestInvoker CreateRequestInvoker(
            TimeSpan?requestTimeout         = null,
            TestRequestRouter requestRouter = null)
        {
            var options = requestTimeout is null ? Options : new RequestInvokerOptions(requestTimeout.Value, supportContentModified: false, concurrency: int.MaxValue);

            requestRouter ??= RequestRouter;
            var requestInvoker = new RazorOmniSharpRequestInvoker(
                options,
                OutputHandler,
                requestRouter,
                TestRequestProcessIdentifier.Instance,
                TestLoggerFactory.Instance);

            return(requestInvoker);
        }
        public async Task InvokeRequest_CanTimeout()
        {
            // Arrange
            var requestRouter = new TestRequestRouter(routeDelay: TimeSpan.FromMinutes(1));

            using var requestInvoker = CreateRequestInvoker(requestTimeout: TimeSpan.FromMilliseconds(1), requestRouter);

            // Act
            var handle = requestInvoker.InvokeRequest(RequestDescriptor, Request);

            using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            await WaitForCompletionAsync(handle, timeoutTokenSource.Token).ConfigureAwait(false);

            // Assert
            var response = Assert.Single(OutputHandler.SentItems);

            Assert.IsType <RequestCancelled>(response);
        }
        public async Task InvokeNotification_CanTimeout()
        {
            // Arrange
            var requestRouter = new TestRequestRouter(routeDelay: TimeSpan.FromMinutes(1));

            using var requestInvoker = CreateRequestInvoker(requestTimeout: TimeSpan.FromMilliseconds(1), requestRouter);
            var asyncResetEvent = new AsyncManualResetEvent(initialState: false);

            requestRouter.OnNotificationCancelled += (notification) =>
            {
                asyncResetEvent.Set();
            };

            // Act
            requestInvoker.InvokeNotification(NotificationDescriptor, Notification);

            // Assert
            using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            await asyncResetEvent.WaitAsync(timeoutTokenSource.Token).ConfigureAwait(false);

            Assert.Empty(OutputHandler.SentItems);
        }