public async Task GetAuthorizationInfo_ShouldRunCorrectly()
        {
            using (var scope = _factory.Services.CreateScope())
            {
                // Arrange
                var Provider1ApiService = scope.ServiceProvider.GetRequiredService <IProvider1ApiService>();

                // Act
                Provider1AuthorizationResponse response = await Provider1ApiService.GetAuthorizationInfo();

                // Assert
                Assert.NotNull(response);
                Assert.NotNull(response.Token);
                Assert.NotNull(response.UserId);
                Assert.NotNull(response.Secret);
                Assert.NotNull(response.AdSessionGuid);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Imports offers.
        /// </summary>
        /// <returns>System.Boolean.</returns>
        public async Task <bool> ImportOffers()
        {
            try
            {
                _logger.LogInformation($"{nameof(ImportOffers)} started");
                _failedProducts           = new List <ProductsByProgramRun>();
                _failedProductsLoggedToDB = new List <ProductsByProgramRun>();

                // Step 1: Gets DB
                _logger.LogInformation($"Step 1: Gets DB");
                List <ProductsByProgramRun> offerProducts = new List <ProductsByProgramRun>();

                if (!offerProducts.Any())
                {
                    _logger.LogInformation($"{nameof(ImportOffers)} ended - There is no product");
                    return(true);
                }

                // Step 2: Calls Apis
                _logger.LogInformation($"Total products from DB {offerProducts.Count}");
                _logger.LogInformation($"Step 2: Calls Apis");

                // Gets Provider1 Authorization info
                Provider1AuthorizationResponse provider1AuthorizationResponse = await _provider1Api.GetAuthorizationInfo();

                // Step 3: Aggregates data
                _logger.LogInformation($"Step 3: Aggregates data");
                for (int i = 0; i *PageSize <= offerProducts.Count; i++)
                {
                    _logger.LogInformation($"Start SearchProductsWithPageSize with PageIndex: {i}, PageSize: {PageSize}");
                    _ = await SearchProductsWithPageSize(offerProducts.Skip(i * PageSize).Take(PageSize).ToList(), provider1AuthorizationResponse.Token);

                    // Step 4: Insert Elasticsearch
                    _logger.LogInformation($"Step 4: Insert Elasticsearch");
                }

                // Step 5: Process failed offerProducts
                _logger.LogInformation($"Step 5: Process failed offerProducts");
                if (_retryFaildedProductsByProgramRun)
                {
                    _retryFaildedProductsByProgramRun = false;

                    if (_failedProducts.Count > 0)
                    {
                        Thread.Sleep(1000 * 60);
                        foreach (ProductsByProgramRun offerProduct in _failedProducts)
                        {
                            // Do something
                        }
                    }
                }

                // Step 6: Updates DB
                _logger.LogInformation($"Step 6: Updates DB");

                _logger.LogInformation($"{nameof(ImportOffers)} ended");
                _logger.LogInformation($"Total failed products logged to DB {_failedProductsLoggedToDB.Count}");
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in {nameof(ImportOffers)}", ex);
                throw;
            }

            return(true);
        }