protected IntegrationTestsBase()
        {
            Fixture = new Fixture();

            var server   = GetSettingsValue("ElasticSearch.ReadModelNodeList", "http://localhost:9200");
            var username = GetSettingsValue("ElasticSearch.UserName", "");
            var password = GetSettingsValue("ElasticSearch.Password", "");

            ElasticClient = ElasticClientFactory.CreateElasticClient(server, username, password);

            if (ElasticClient.Indices.Exists(IndexName).Exists)
            {
                ElasticClient.Indices.Delete(IndexName);
            }

            ElasticClient.Indices.Create(IndexName, d => d.Settings(descriptor => descriptor).Map(m => m.AutoMap <T>()));

            Sut = new ElasticQueryable <T>(ElasticClient, IndexName);
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                //TODO: Think about a more appropriate restriction policy
                options.AddPolicy("CorsPolicy",
                                  builder =>
                {
                    builder
                    .AllowAnyOrigin()
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .DisallowCredentials();
                });
            });

            services.AddControllers();

            services.AddAutoMapper(config =>
            {
                config.CreateMap <Book, BookDto>().ReverseMap();
                config.CreateMap <OperationResult, OperationResultDto>().ReverseMap();
            }, typeof(Startup));

            services.AddMediatR(typeof(GetBooksQueryHandler).Assembly);
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>));
            services.AddValidatorsFromAssembly(typeof(UpsertBookValidator).Assembly);


            services.AddTransient <IElasticRepository, ElasticRepository>();
            services.AddTransient <IBookService, BookService>();
            services.AddTransient <IBookRepository, ElasticBookRepository>();
            services.AddTransient <IFileService>(x => new BlobFileService("UseDevelopmentStorage=true"));
            services.AddTransient <IPdfParser, PdfParser>();


            services.AddRabbitMQ(Configuration["RabbitMq:Host"]);
            services.AddTransient <IMessageProducerService, MessageProducerService>();
            services.AddHostedService <BookUpsertSubscriberService>();
            services.AddHostedService <BookUpsertedSubscriberService>();


            var elasticHosts = Configuration.GetSection("Elasticsearch:Hosts")
                               .AsEnumerable()
                               .Where(x => x.Value != null)
                               .Select(x => x.Value);

            services.AddSingleton(x =>
                                  ElasticClientFactory.CreateElasticClient(elasticHosts, Configuration["Elasticsearch:Username"], Configuration["Elasticsearch:Password"]));
            services.AddTransient <IEnumerable <IElasticQuery> >(x => new List <IElasticQuery> {
                new GetBooksQuery()
            });

            services.AddTransient <IEnumerable <IElasticCommand> >(x => new List <IElasticCommand> {
                new UpsertBookCommand()
            });

            services.AddSignalR();


            var redisHosts = Configuration.GetSection("Redis:Hosts")
                             .AsEnumerable()
                             .Where(x => x.Value != null)
                             .Select(x => x.Value);

            services.UseRedisCaching(redisHosts, uint.Parse(Configuration["Redis:Database"]));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(
                    "v1",
                    info: new Microsoft.OpenApi.Models.OpenApiInfo()
                {
                    Title       = "Book Store",
                    Version     = "1.0",
                    Description = "Book Store"
                }
                    );
            });
        }