protected BaseApiTestsFixture(Type startupType) { MockLogger = MockLoggerExtensions.CreateMockLogger(); var environment = Environment.GetEnvironmentVariable("Hosting:Environment") ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? EnvironmentName.Development; var currentDirectory = Path.GetDirectoryName(startupType.GetTypeInfo().Assembly.Location); Func <IConfigurationBuilder, string, string, IConfigurationBuilder> configurationSetup = (builder, configsPath, environmentName) => builder .AddDefaultConfigs(configsPath, environmentName) .AddCiDependentSettings(environmentName); Configuration = configurationSetup(new ConfigurationBuilder(), currentDirectory, environment).Build(); TimeoutInMilliseconds = Configuration.GetValue <int>("ApiTimeoutInMilliseconds"); Server = new TestServer( new WebHostBuilder() .UseEnvironment(environment) .ConfigureAppConfiguration(builder => configurationSetup(builder, currentDirectory, environment)) .UseMockLogger(MockLogger) .UseStartup(startupType)); }
public BaseApiTestsFixture() { _environmentName = Environment.GetEnvironmentVariable("Hosting:Environment") ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? EnvironmentName.Development; _configsDirectory = Path.GetDirectoryName(typeof(TStartup).GetTypeInfo().Assembly.Location); Configuration = ConfigurationSetup(new ConfigurationBuilder(), _configsDirectory, _environmentName).Build(); ApiTimeout = Configuration.GetValue <TimeSpan>("ApiTimeout"); MockLogger = MockLoggerExtensions.CreateMockLogger(); }
public RabbitQueueTests() { _mockLogger = MockLoggerExtensions.CreateMockLogger(); var mockLoggerFactory = new Mock <ILoggerFactory>(); mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(_mockLogger.Object); _loggerFactory = mockLoggerFactory.Object; var configuration = new ConfigurationBuilder() .AddDefaultConfigs(Path.GetDirectoryName(GetType().GetTypeInfo().Assembly.Location), Environments.Development) .AddCiDependentSettings(Environments.Development) .Build(); _completionTimeout = configuration.GetSection("CompletionTimeout").Get <TimeSpan>(); var queuesFactoryOptions = configuration.GetSection("QueuesFactoryOptions").Get <TypedRabbitQueuesFactoryOptions>(); _connectionsFactory = new ConnectionFactory { UserName = queuesFactoryOptions.Credentials.UserName, Password = queuesFactoryOptions.Credentials.Password, AutomaticRecoveryEnabled = true, NetworkRecoveryInterval = queuesFactoryOptions.NetworkRecoveryInterval, TopologyRecoveryEnabled = true, HostName = queuesFactoryOptions.Hosts.Single() }; _queuesFactory = new RabbitQueuesFactory( new ExceptionHandlersFactory <RabbitMessageDescription>( new ExceptionHandlerBase <RabbitMessageDescription>[] { new EmptyExceptionHandler <RabbitMessageDescription>( _loggerFactory.CreateLogger <EmptyExceptionHandler <RabbitMessageDescription> >() ), new RequeuingExceptionHandler <RabbitMessageDescription>( _loggerFactory.CreateLogger <RequeuingExceptionHandler <RabbitMessageDescription> >() ), new ErrorsQueuingExceptionHandler <RabbitMessageDescription>( _loggerFactory.CreateLogger <ErrorsQueuingExceptionHandler <RabbitMessageDescription> >() ) } ), _loggerFactory, Options.Create(queuesFactoryOptions) ); }
public MessagesProcessingServiceTests() { _mockLogger = MockLoggerExtensions.CreateMockLogger(); _messageHandler = new CatchingMessageHandler <string>(); _host = new HostBuilder() .UseEnvironment(EnvironmentName.Development) .UseContentRoot(Path.GetDirectoryName(GetType().GetTypeInfo().Assembly.Location)) .ConfigureAppConfiguration( (context, builder) => { var hostingEnvironment = context.HostingEnvironment; builder .AddDefaultConfigs(hostingEnvironment.ContentRootPath, hostingEnvironment.EnvironmentName) .AddCiDependentSettings(hostingEnvironment.EnvironmentName); } ) .ConfigureServices( (context, collection) => collection .AddRabbitMqSupport() .AddNotificationsProcessingService(context.Configuration.GetSection("NotificationsProcessingServiceOptions")) .Configure <TypedRabbitQueuesFactoryOptions>(context.Configuration.GetSection("QueuesFactoryOptions")) ) .UseServiceProviderFactory(new AutofacServiceProviderFactory()) .ConfigureContainer <ContainerBuilder>( builder => { builder.RegisterInstance(_messageHandler).As <IMessageHandler <string> >(); } ) .ConfigureLogging( builder => { var mockLoggerFactory = new Mock <ILoggerFactory>(); mockLoggerFactory.Setup(x => x.CreateLogger(It.IsAny <string>())).Returns(_mockLogger.Object); builder.Services.Replace(ServiceDescriptor.Singleton(mockLoggerFactory.Object)); }) .Build(); _completionTimeout = _host.Services.GetService <IConfiguration>().GetSection("CompletionTimeout").Get <TimeSpan>(); }
public BaseApiTestsFixture(Type startupType) { MockLogger = MockLoggerExtensions.CreateMockLogger(); var environment = Environment.GetEnvironmentVariable("Hosting:Environment") ?? Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? EnvironmentName.Development; var currentDirectory = Path.GetDirectoryName(startupType.GetTypeInfo().Assembly.Location); Server = new TestServer( new WebHostBuilder() .UseContentRoot(currentDirectory) .UseEnvironment(environment) .ConfigureServices(services => services.CaptureCommandLineArguments(new string[0])) .UseMockLogger(MockLogger) .UseStartup(startupType)); Configuration = new ConfigurationBuilder() .SetBasePath(currentDirectory) .AddJsonFile("appsettings.json", false, false) .AddJsonFile($"appsettings.{environment}.json", true, false) .Build(); TimeoutInMilliseconds = Configuration.GetValue <int>("ApiTimeoutInMilliseconds"); }
public UnhandledExceptionsLoggingMiddlewareTests() { _mockLogger = MockLoggerExtensions.CreateMockLogger(); }