public static IServiceProvider BuildServicesProvider(IConfiguration config, IDbConnection dbConnection)
        {
            var services = new ServiceCollection();

            var kConfig = new ProducerConfig
            {
                BootstrapServers = config.GetValue <string>("ServerKafka")
            };

            var externalConfig = new ExternalConfigVO
            {
                GatewayUrl     = config.GetValue <string>("GATEWAY__URL"),
                DeliveryUrl    = config.GetValue <string>("DELIVERY_URL"),
                TopicPagamento = config.GetValue <string>("PAGAMENTO_TOPIC")
            };

            services.AddSingleton(p => externalConfig);

            services.AddSingleton(config);
            services.AddScoped <IPagamentoCommand, PagamentoCommand>();
            services.AddScoped <IPagamentoRepository, PagamentoRepository>();

            services.AddScoped <IGatewayExternalService, GatewayExternalService>();
            services.AddScoped <IDeliveryExternalService, DeliveryExternalService>();

            services.AddScoped <IGatewayExternalContext, GatewayExternalContext>();
            services.AddScoped <IDeliveryExternalContext, DeliveryExternalContext>();

            services.ResolveConverters();

            //services.AddScoped<IDeliveryExternalContext>((idel) =>
            //{
            //    var mockDeliveryExternalContext = new Mock<DeliveryExternalContext>(externalConfig, kConfig);
            //    mockDeliveryExternalContext.Setup(s => s.AtualizaStatusPagamento(It.IsAny<DeliveryExternalParam>()))
            //        .Verifiable();

            //    return mockDeliveryExternalContext.Object;
            //});


            services.AddScoped((kf) =>
            {
                var result    = new AutoFaker <DeliveryResult <Null, string> >().Generate();
                var kafkaMock = new Mock <IProducer <Null, string> >();
                kafkaMock.Setup(r => r.ProduceAsync(It.IsAny <string>(), It.IsAny <Message <Null, string> >(),
                                                    It.IsAny <CancellationToken>())).ReturnsAsync(result);
                return(kafkaMock.Object);
            });

            services.AddTransient((db) =>
            {
                return(dbConnection);
            });

            return(services.BuildServiceProvider());
        }
        public static IServiceProvider BuildServicesProvider(IConfiguration config, IDbConnection dbConnection)
        {
            var services = new ServiceCollection();

            var externalConfig = new ExternalConfigVO
            {
                GatewayUrl  = config.GetValue <string>("GATEWAY__URL"),
                DeliveryUrl = config.GetValue <string>("DELIVERY_URL")
            };

            services.AddSingleton(p => externalConfig);

            services.AddSingleton(config);
            services.AddScoped <IPagamentoCommand, PagamentoCommand>();
            services.AddScoped <IPagamentoRepository, PagamentoRepository>();

            services.AddScoped <IGatewayExternalService, GatewayExternalService>();
            services.AddScoped <IDeliveryExternalService, DeliveryExternalService>();

            services.AddScoped <IGatewayExternalContext, GatewayExternalContext>();

            services.ResolveConverters();

            services.AddScoped <IDeliveryExternalContext>((idel) =>
            {
                var mockDeliveryExternalContext = new Mock <DeliveryExternalContext>(externalConfig);
                mockDeliveryExternalContext.Setup(s => s.AtualizaStatusPagamento(It.IsAny <DeliveryExternalParam>())).Returns(Task.Factory.StartNew(() => string.Empty));

                return(mockDeliveryExternalContext.Object);
            });

            services.AddTransient((db) =>
            {
                return(dbConnection);
            });

            return(services.BuildServiceProvider());
        }
示例#3
0
 public PagamentoExternalContext(ExternalConfigVO config)
 {
     _config = config;
 }
示例#4
0
 public DeliveryExternalContext(ExternalConfigVO config)
 {
     _config = config;
 }
示例#5
0
 public DeliveryExternalContext(ExternalConfigVO config, IProducer <Null, string> producer)
 {
     _config   = config;
     _producer = producer;
 }
示例#6
0
 public GatewayExternalContext(ExternalConfigVO config)
 {
     _config = config;
 }