public void Should_ReturnDedicatedRepositoryInstance(Type desiredObjectType) { // Arrange _umbracoBuilder.Build(); var serviceProvider = _serviceCollection.BuildServiceProvider(); using (var scope = serviceProvider.CreateScope()) { // Act var instance = scope.ServiceProvider.GetService(desiredObjectType); // Assert Assert.NotNull(instance); Assert.True(desiredObjectType.IsInstanceOfType(instance)); Assert.NotEmpty(instance.GetType().GenericTypeArguments); Assert.Equal(desiredObjectType.GenericTypeArguments[0], instance.GetType().GenericTypeArguments[0]); } }
protected void ConfigureServices(IServiceCollection services) { services.AddTransient <TestUmbracoDatabaseFactoryProvider>(); Core.Hosting.IHostingEnvironment hostingEnvironment = TestHelper.GetHostingEnvironment(); TypeLoader typeLoader = services.AddTypeLoader( GetType().Assembly, hostingEnvironment, TestHelper.ConsoleLoggerFactory, AppCaches.NoCache, Configuration, TestHelper.Profiler); services.AddLogger(TestHelper.GetWebHostEnvironment(), Configuration); var builder = new UmbracoBuilder(services, Configuration, typeLoader, TestHelper.ConsoleLoggerFactory, TestHelper.Profiler, AppCaches.NoCache, hostingEnvironment); builder .AddConfiguration() .AddUmbracoCore() .AddWebComponents() .AddNuCache() .AddRuntimeMinifier() .AddBackOfficeCore() .AddBackOfficeAuthentication() .AddBackOfficeIdentity() .AddMembersIdentity() .AddBackOfficeAuthorizationPolicies(TestAuthHandler.TestAuthenticationScheme) .AddPreviewSupport() .AddMvcAndRazor(mvcBuilding: mvcBuilder => { // Adds Umbraco.Web.BackOffice mvcBuilder.AddApplicationPart(typeof(ContentController).Assembly); // Adds Umbraco.Web.Common mvcBuilder.AddApplicationPart(typeof(RenderController).Assembly); // Adds Umbraco.Web.Website mvcBuilder.AddApplicationPart(typeof(SurfaceController).Assembly); // Adds Umbraco.Tests.Integration mvcBuilder.AddApplicationPart(typeof(UmbracoTestServerTestBase).Assembly); }) .AddWebServer() .AddWebsite() .AddUmbracoSqlServerSupport() .AddUmbracoSqliteSupport() .AddTestServices(TestHelper); // This is the important one! CustomTestSetup(builder); builder.Build(); }
protected void ConfigureServices(IServiceCollection services) { services.AddUnique(CreateLoggerFactory()); services.AddTransient <TestUmbracoDatabaseFactoryProvider>(); IWebHostEnvironment webHostEnvironment = TestHelper.GetWebHostEnvironment(); services.AddRequiredNetCoreServices(TestHelper, webHostEnvironment); // We register this service because we need it for IRuntimeState, if we don't this breaks 900 tests services.AddSingleton <IConflictingRouteService, TestConflictingRouteService>(); // Add it! Core.Hosting.IHostingEnvironment hostingEnvironment = TestHelper.GetHostingEnvironment(); TypeLoader typeLoader = services.AddTypeLoader( GetType().Assembly, hostingEnvironment, TestHelper.ConsoleLoggerFactory, AppCaches.NoCache, Configuration, TestHelper.Profiler); var builder = new UmbracoBuilder(services, Configuration, typeLoader, TestHelper.ConsoleLoggerFactory, TestHelper.Profiler, AppCaches.NoCache, hostingEnvironment); builder.Services.AddLogger(hostingEnvironment, TestHelper.GetLoggingConfiguration(), Configuration); builder.AddConfiguration() .AddUmbracoCore() .AddWebComponents() .AddRuntimeMinifier() .AddBackOfficeAuthentication() .AddBackOfficeIdentity() .AddMembersIdentity() .AddExamine() .AddUmbracoSqlServerSupport() .AddUmbracoSqliteSupport() .AddTestServices(TestHelper); if (TestOptions.Mapper) { // TODO: Should these just be called from within AddUmbracoCore/AddWebComponents? builder .AddCoreMappingProfiles() .AddWebMappingProfiles(); } services.AddSignalR(); services.AddMvc(); CustomTestSetup(builder); builder.Build(); }
public virtual void ConfigureServices(IServiceCollection services) { services.AddSingleton(TestHelper.DbProviderFactoryCreator); services.AddTransient <TestUmbracoDatabaseFactoryProvider>(); IWebHostEnvironment webHostEnvironment = TestHelper.GetWebHostEnvironment(); services.AddRequiredNetCoreServices(TestHelper, webHostEnvironment); // Add it! Core.Hosting.IHostingEnvironment hostingEnvironment = TestHelper.GetHostingEnvironment(); TypeLoader typeLoader = services.AddTypeLoader( GetType().Assembly, hostingEnvironment, TestHelper.ConsoleLoggerFactory, AppCaches.NoCache, Configuration, TestHelper.Profiler); var builder = new UmbracoBuilder(services, Configuration, typeLoader, TestHelper.ConsoleLoggerFactory, TestHelper.Profiler, AppCaches.NoCache, hostingEnvironment); builder.Services.AddLogger(hostingEnvironment, TestHelper.GetLoggingConfiguration(), Configuration); builder.AddConfiguration() .AddUmbracoCore() .AddWebComponents() .AddRuntimeMinifier() .AddBackOfficeAuthentication() .AddBackOfficeIdentity() .AddMembersIdentity() .AddExamine() .AddTestServices(TestHelper, GetAppCaches()); if (TestOptions.Mapper) { // TODO: Should these just be called from within AddUmbracoCore/AddWebComponents? builder .AddCoreMappingProfiles() .AddWebMappingProfiles(); } services.AddSignalR(); services.AddMvc(); CustomTestSetup(builder); builder.Build(); }