Esempio n. 1
0
        public RouterTest()
        {
            var services = new ServiceCollection();

            services.AddSingleton <ILoggerFactory>(NullLoggerFactory.Instance);
            services.AddSingleton <NavigationManager, TestNavigationManager>();
            services.AddSingleton <INavigationInterception, TestNavigationInterception>();
            var serviceProvider = services.BuildServiceProvider();

            _renderer = new TestRenderer(serviceProvider);
            _renderer.ShouldHandleExceptions = true;
            _router             = (Router)_renderer.InstantiateComponent <Router>();
            _router.AppAssembly = Assembly.GetExecutingAssembly();
            _router.Found       = routeData => (builder) => builder.AddContent(0, "Rendering route...");
            _renderer.AssignRootComponentId(_router);
        }
        public void CreatesScopeAndService()
        {
            var services = new ServiceCollection();

            services.AddSingleton <Counter>();
            services.AddTransient <MyService>();
            var serviceProvider = services.BuildServiceProvider();

            var counter    = serviceProvider.GetRequiredService <Counter>();
            var renderer   = new TestRenderer(serviceProvider);
            var component1 = (MyOwningComponent)renderer.InstantiateComponent <MyOwningComponent>();

            Assert.NotNull(component1.MyService);
            Assert.Equal(1, counter.CreatedCount);
            Assert.Equal(0, counter.DisposedCount);

            ((IDisposable)component1).Dispose();
            Assert.Equal(1, counter.CreatedCount);
            Assert.Equal(1, counter.DisposedCount);
        }