コード例 #1
0
        public void DelegationBehaviors()
        {
            var innerFactory      = new CustomizedFactory(this.context, this.AddToLog);
            var delegatingFactory = new DelegatingFactory(innerFactory, this.AddToLog);

            delegatingFactory.Run(async delegate
            {
                await Task.Delay(1);
            });

            var jt = delegatingFactory.RunAsync(async delegate
            {
                await TaskScheduler.Default;
                await delegatingFactory.SwitchToMainThreadAsync();
            });

            jt.Join();

            lock (this.logLock)
            {
                while (!ValidateDelegatingLog(this.log.ToList()))
                {
                    this.Logger.WriteLine("Waiting with a count of {0}", this.log.Count);
                    Assert.True(Monitor.Wait(this.logLock, AsyncDelay));
                }
            }
        }
コード例 #2
0
        public void TestingInfrastructure_GenericHost_WithWithHostBuilderHasServices()
        {
            // Act
            using var factory = new CustomizedFactory <GenericHostWebSite.Startup>();

            // Assert
            Assert.NotNull(factory.Services);
            Assert.NotNull(factory.Services.GetService(typeof(IConfiguration)));
        }
コード例 #3
0
        public async Task TestingInfrastructure_GenericHost_HostDisposeAsync()
        {
            // Arrange
            using var factory = new CustomizedFactory <GenericHostWebSite.Startup>().WithWebHostBuilder(ConfigureWebHostBuilder);
            var sink = factory.Services.GetRequiredService <DisposableService>();

            // Act
            await factory.DisposeAsync();

            // Assert
            Assert.True(sink._asyncDisposed);
        }
コード例 #4
0
        public void TestingInfrastructure_GenericHost_HostShouldStopBeforeDispose()
        {
            // Act
            using var factory = new CustomizedFactory <GenericHostWebSite.Startup>();
            var callbackCalled = false;

            var lifetimeService = (IHostApplicationLifetime)factory.Services.GetService(typeof(IHostApplicationLifetime));

            lifetimeService.ApplicationStopped.Register(() => { callbackCalled = true; });
            factory.Dispose();

            // Assert
            Assert.True(callbackCalled);
        }
コード例 #5
0
        public void TestingInfrastructure_WithWebHostBuilderRespectsCustomizations()
        {
            // Act
            var factory    = new CustomizedFactory <BasicWebSite.Startup>();
            var customized = factory
                             .WithWebHostBuilder(builder => factory.ConfigureWebHostCalled.Add("Customization"))
                             .WithWebHostBuilder(builder => factory.ConfigureWebHostCalled.Add("FurtherCustomization"));
            var client = customized.CreateClient();

            // Assert
            Assert.Equal(new[] { "ConfigureWebHost", "Customization", "FurtherCustomization" }, factory.ConfigureWebHostCalled.ToArray());
            Assert.True(factory.CreateServerCalled);
            Assert.True(factory.CreateWebHostBuilderCalled);
            Assert.True(factory.GetTestAssembliesCalled);
        }
コード例 #6
0
        public void TestingInfrastructure_WebHost_WithWebHostBuilderRespectsCustomizations()
        {
            // Act
            using var factory    = new CustomizedFactory <BasicWebSite.StartupWithoutEndpointRouting>();
            using var customized = factory
                                   .WithWebHostBuilder(builder => factory.ConfigureWebHostCalled.Add("Customization"))
                                   .WithWebHostBuilder(builder => factory.ConfigureWebHostCalled.Add("FurtherCustomization"));
            var client = customized.CreateClient();

            // Assert
            Assert.Equal(new[] { "ConfigureWebHost", "Customization", "FurtherCustomization" }, factory.ConfigureWebHostCalled.ToArray());
            Assert.True(factory.CreateServerCalled);
            Assert.True(factory.CreateWebHostBuilderCalled);
            // GetTestAssemblies is not called when reading content roots from MvcAppManifest
            Assert.False(factory.GetTestAssembliesCalled);
            Assert.True(factory.CreateHostBuilderCalled);
            Assert.False(factory.CreateHostCalled);
        }