public CircuitHost( CircuitId circuitId, AsyncServiceScope scope, CircuitOptions options, CircuitClientProxy client, RemoteRenderer renderer, IReadOnlyList <ComponentDescriptor> descriptors, RemoteJSRuntime jsRuntime, RemoteNavigationManager navigationManager, CircuitHandler[] circuitHandlers, ILogger logger) { CircuitId = circuitId; if (CircuitId.Secret is null) { // Prevent the use of a 'default' secret. throw new ArgumentException($"Property '{nameof(CircuitId.Secret)}' cannot be null.", nameof(circuitId)); } _scope = scope; _options = options ?? throw new ArgumentNullException(nameof(options)); Client = client ?? throw new ArgumentNullException(nameof(client)); Renderer = renderer ?? throw new ArgumentNullException(nameof(renderer)); Descriptors = descriptors ?? throw new ArgumentNullException(nameof(descriptors)); JSRuntime = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime)); _navigationManager = navigationManager ?? throw new ArgumentNullException(nameof(navigationManager)); _circuitHandlers = circuitHandlers ?? throw new ArgumentNullException(nameof(circuitHandlers)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); Services = scope.ServiceProvider; Circuit = new Circuit(this); Handle = new CircuitHandle() { CircuitHost = this, }; // An unhandled exception from the renderer is always fatal because it came from user code. Renderer.UnhandledException += ReportAndInvoke_UnhandledException; Renderer.UnhandledSynchronizationException += SynchronizationContext_UnhandledException; JSRuntime.UnhandledException += ReportAndInvoke_UnhandledException; _navigationManager.UnhandledException += ReportAndInvoke_UnhandledException; }
public static CircuitHost Create( CircuitId?circuitId = null, AsyncServiceScope?serviceScope = null, RemoteRenderer remoteRenderer = null, IReadOnlyList <ComponentDescriptor> descriptors = null, CircuitHandler[] handlers = null, CircuitClientProxy clientProxy = null) { serviceScope = serviceScope ?? new AsyncServiceScope(Mock.Of <IServiceScope>()); clientProxy = clientProxy ?? new CircuitClientProxy(Mock.Of <IClientProxy>(), Guid.NewGuid().ToString()); var jsRuntime = new RemoteJSRuntime(Options.Create(new CircuitOptions()), Options.Create(new HubOptions <ComponentHub>()), Mock.Of <ILogger <RemoteJSRuntime> >()); var navigationManager = new RemoteNavigationManager(Mock.Of <ILogger <RemoteNavigationManager> >()); var serviceProvider = new Mock <IServiceProvider>(); serviceProvider .Setup(services => services.GetService(typeof(IJSRuntime))) .Returns(jsRuntime); if (remoteRenderer == null) { remoteRenderer = new RemoteRenderer( serviceProvider.Object, NullLoggerFactory.Instance, new CircuitOptions(), clientProxy, NullLogger.Instance, jsRuntime, new CircuitJSComponentInterop(new CircuitOptions())); } handlers ??= Array.Empty <CircuitHandler>(); return(new TestCircuitHost( circuitId is null ? new CircuitId(Guid.NewGuid().ToString(), Guid.NewGuid().ToString()) : circuitId.Value, serviceScope.Value, new CircuitOptions(), clientProxy, remoteRenderer, descriptors ?? new List <ComponentDescriptor>(), jsRuntime, navigationManager, handlers, NullLogger <CircuitHost> .Instance)); }
private TestCircuitHost(CircuitId circuitId, AsyncServiceScope scope, CircuitOptions options, CircuitClientProxy client, RemoteRenderer renderer, IReadOnlyList <ComponentDescriptor> descriptors, RemoteJSRuntime jsRuntime, RemoteNavigationManager navigationManager, CircuitHandler[] circuitHandlers, ILogger logger) : base(circuitId, scope, options, client, renderer, descriptors, jsRuntime, navigationManager, circuitHandlers, logger) { }