Ejemplo n.º 1
0
 public override void ConfigureServices(IServiceCollection services)
 {
     // Test Startup
     services.ConfigureSqlServer(Configuration.GetConnectionString("HEDWIG"));
     // Main Startup
     // Excluding ConfigureSqlServer, ConfigureHostedServices, and ConfigureAuthentication
     services.ConfigureCors();
     services.ConfigureFilters();
     services.ConfigureControllers();
     services.ConfigureSpa();
     services.ConfigureMapping();
     services.ConfigureRepositories();
     services.ConfigureAuthorization();
     services.ConfigureValidation();
     services.AddSingleton <IDateTime, SystemDateTime>();
     services.ConfigureSwagger();
     services.AddHttpContextAccessor();
     // End main startup
     // Test Startup
     if (TestEnvironmentFlags.ShouldLogSQL())
     {
         services.AddLogging(configure => configure.AddConsole());
     }
     services.ConfigureAuthentication();
 }
        public TestHedwigContextProvider(bool callBase = true)
        {
            var configuration  = EnvironmentConfiguration.GetIConfigurationRoot();
            var optionsBuilder = new DbContextOptionsBuilder <HedwigContext>()
                                 .UseSqlServer(configuration.GetConnectionString("HEDWIG"))
                                 .EnableSensitiveDataLogging();

            if (TestEnvironmentFlags.ShouldLogSQL())
            {
                var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
                optionsBuilder.UseLoggerFactory(loggerFactory);
            }

            HttpContextAccessor = new TestHttpContextAccessorProvider().HttpContextAccessor;

            ContextMock          = new Mock <HedwigContext>(optionsBuilder.Options, HttpContextAccessor);
            ContextMock.CallBase = callBase;
            ContextMock.Object.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
            Context = ContextMock.Object;
        }