public async Task HandleAsyncTest()
        {
            var browserServiceMock = new Mock <IBrowserService>();

            var codeStreamAgentServiceMock = new Mock <ICodeStreamAgentService>();
            var router = new WebViewRouter(
                null,
                new Mock <ICodeStreamService>().Object,
                new Mock <IWebviewUserSettingsService>().Object,
                new Mock <ISessionService>().Object,
                codeStreamAgentServiceMock.Object,
                new Mock <ISettingsServiceFactory>().Object,
                new Mock <IEventAggregator>().Object,
                browserServiceMock.Object,
                new Mock <IIdeService>().Object,
                new Mock <IEditorService>().Object,
                new Mock <IAuthenticationServiceFactory>().Object
                );

            await router.HandleAsync(new WindowEventArgs("BOGUS"));

            string message;

            message =
                new WebviewIpcMessage(
                    "123",
                    ReloadWebviewRequestType.MethodName,
                    JToken.Parse("{}"),
                    null).AsJson();
            await router.HandleAsync(new WindowEventArgs(message));

            browserServiceMock.Verify(_ => _.ReloadWebView(), Times.Once);

            message =
                new WebviewIpcMessage(
                    "123",
                    $"{IpcRoutes.Agent}/anything",
                    JToken.Parse("{}"),
                    null).AsJson();
            await router.HandleAsync(new WindowEventArgs(message));

            codeStreamAgentServiceMock.Verify(_ => _.SendAsync <JToken>(It.IsAny <string>(), It.IsAny <JToken>(), null), Times.Once);
        }
Beispiel #2
0
        private void InitializeCore()
        {
            // ReSharper disable InvertIf
            if (!_isInitialized)
            {
                lock (InitializeLock) {
                    if (!_isInitialized)
                    {
                        try {
                            using (Log.CriticalOperation(nameof(InitializeCore), Serilog.Events.LogEventLevel.Debug)) {
                                var router = new WebViewRouter(
                                    _componentModel,
                                    _componentModel.GetService <IWebviewUserSettingsService>(),
                                    _componentModel.GetService <ISessionService>(),
                                    _componentModel.GetService <ICodeStreamAgentService>(),
                                    _componentModel.GetService <ISettingsServiceFactory>(),
                                    _eventAggregator,
                                    _browserService,
                                    _componentModel.GetService <IIdeService>(),
                                    _componentModel.GetService <IEditorService>(),
                                    _componentModel.GetService <IAuthenticationServiceFactory>());

                                _browserService.AddWindowMessageEvent(
                                    async delegate(object sender, WindowEventArgs ea) { await router.HandleAsync(ea); });

                                _isInitialized = true;
                            }
                        }
                        catch (Exception ex) {
                            Log.Fatal(ex, nameof(InitializeCore));
                        }
                    }
                }
            }
            // ReSharper restore InvertIf
        }