Ejemplo n.º 1
0
        public void ConventionBasedStartup_GetConfigureMethod_OverloadedThrows()
        {
            // Arrange
            var startup = new ConventionBasedStartup(new MyStartup7());

            // Act
            var ex = Assert.Throws <InvalidOperationException>(() => startup.GetConfigureMethod());

            // Assert
            Assert.Equal("Overloading the 'Configure' method is not supported.", ex.Message);
        }
Ejemplo n.º 2
0
        public void ConventionBasedStartup_GetConfigureServicesMethod_NoMethodFound()
        {
            // Arrange
            var startup = new ConventionBasedStartup(new MyStartup2());

            // Act
            var method = startup.GetConfigureServicesMethod();

            // Assert
            Assert.Null(method);
        }
Ejemplo n.º 3
0
        public void ConventionBasedStartup_GetConfigureServicesMethod_FindsConfigureServices()
        {
            // Arrange
            var startup = new ConventionBasedStartup(new MyStartup1());

            // Act
            var method = startup.GetConfigureServicesMethod();

            // Assert
            Assert.Equal(typeof(IServiceCollection), method.GetParameters()[0].ParameterType);
        }
Ejemplo n.º 4
0
        public void ConventionBasedStartup_GetConfigureMethod_NoMethodFoundThrows()
        {
            // Arrange
            var startup = new ConventionBasedStartup(new MyStartup6());

            // Act
            var ex = Assert.Throws <InvalidOperationException>(() => startup.GetConfigureMethod());

            // Assert
            Assert.Equal("The startup class must define a 'Configure' method.", ex.Message);
        }
Ejemplo n.º 5
0
        public void ConventionBasedStartup_GetConfigureMethod_FindsConfigure()
        {
            // Arrange
            var startup = new ConventionBasedStartup(new MyStartup5());

            // Act
            var method = startup.GetConfigureMethod();

            // Assert
            Assert.Empty(method.GetParameters());
        }
Ejemplo n.º 6
0
        public void ConventionBasedStartup_ConfigureServices_NoMethodFound()
        {
            // Arrange
            var startup  = new ConventionBasedStartup(new MyStartup4());
            var services = new ServiceCollection();

            // Act
            startup.ConfigureServices(services);

            // Assert
            Assert.Empty(services);
        }
Ejemplo n.º 7
0
        public void ConventionBasedStartup_Configure()
        {
            // Arrange
            var instance = new MyStartup8();
            var startup  = new ConventionBasedStartup(instance);

            var services = new ServiceCollection().AddSingleton("foo").BuildServiceProvider();
            var builder  = new WebAssemblyBlazorApplicationBuilder(services);

            // Act
            startup.Configure(builder, services);

            // Assert
            Assert.Collection(
                instance.Arguments,
                a => Assert.Same(builder, a),
                a => Assert.Equal("foo", a));
        }
        /// <summary>
        /// Configures the <see cref="IWebAssemblyHostBuilder"/> to use the provided startup class.
        /// </summary>
        /// <param name="builder">The <see cref="IWebAssemblyHostBuilder"/>.</param>
        /// <param name="startupType">A type that configures a Blazor application.</param>
        /// <returns>The <see cref="IWebAssemblyHostBuilder"/>.</returns>
        public static IWebAssemblyHostBuilder UseBlazorStartup(this IWebAssemblyHostBuilder builder, Type startupType)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (builder.Properties.ContainsKey(BlazorStartupKey))
            {
                throw new InvalidOperationException("A startup class has already been registered.");
            }

            // It would complicate the implementation to allow multiple startup classes, and we don't
            // really have a need for it.
            builder.Properties.Add(BlazorStartupKey, bool.TrueString);

            var startup = new ConventionBasedStartup(Activator.CreateInstance(startupType));

            builder.ConfigureServices(startup.ConfigureServices);
            builder.ConfigureServices(s => s.AddSingleton <IBlazorStartup>(startup));

            return(builder);
        }