Exemplo n.º 1
0
        public void WhenInvalidCallbackuriInProductIdentifierRequest_ThenReturnBadRequest()
        {
            var model = new ProductIdentifierRequest {
                CallbackUri = "demo uri"
            };
            var result = validator.TestValidate(model);

            result.ShouldHaveValidationErrorFor(fb => fb.CallbackUri);
            Assert.IsTrue(result.Errors.Any(x => x.ErrorMessage == "Invalid callbackUri format."));
        }
Exemplo n.º 2
0
        public void WhenValidProductIdentifiersAndvalidCallBackuriInProductIdentifiersRequest_ThenReturnSuccess()
        {
            string[] productIdentifiers = new string[] { "GB123456", "GB160060", "AU334550" };
            string   callbackUri        = "https://exchange-set-service.com/myCallback?secret=sharedSecret&po=1234";
            var      model = new ProductIdentifierRequest
            {
                ProductIdentifier = productIdentifiers,
                CallbackUri       = callbackUri
            };
            var result = validator.TestValidate(model);

            Assert.AreEqual(0, result.Errors.Count);
        }
Exemplo n.º 3
0
        public void WhenEmptyCallbackuriInProductDataProductIdentifierRequest_ThenReturnSuccess()
        {
            string[] productIdentifiers = new string[] { "GB123456", "GB160060", "AU334550" };
            string   callbackUri        = string.Empty;
            var      model = new ProductIdentifierRequest
            {
                ProductIdentifier = productIdentifiers,
                CallbackUri       = callbackUri
            };
            var result = validator.TestValidate(model);

            Assert.IsTrue(result.Errors.Count == 0);
        }
Exemplo n.º 4
0
        public virtual Task <IActionResult> PostProductIdentifiers([FromBody] string[] productIdentifiers, [FromQuery] string callbackUri)
        {
            return(Logger.LogStartEndAndElapsedTimeAsync(EventIds.ESSPostProductIdentifiersRequestStart, EventIds.ESSPostProductIdentifiersRequestCompleted,
                                                         "Product Identifiers Endpoint request for _X-Correlation-ID:{correlationId}",
                                                         async() => {
                if (productIdentifiers == null || productIdentifiers.Length == 0)
                {
                    var error = new List <Error>
                    {
                        new Error()
                        {
                            Source = "requestBody",
                            Description = "Either body is null or malformed."
                        }
                    };
                    return BuildBadRequestErrorResponse(error);
                }
                var productIdentifierRequest = new ProductIdentifierRequest()
                {
                    ProductIdentifier = productIdentifiers,
                    CallbackUri = callbackUri,
                    CorrelationId = GetCurrentCorrelationId()
                };

                var validationResult = await productDataService.ValidateProductDataByProductIdentifiers(productIdentifierRequest);

                if (!validationResult.IsValid)
                {
                    List <Error> errors;

                    if (validationResult.HasBadRequestErrors(out errors))
                    {
                        return BuildBadRequestErrorResponse(errors);
                    }
                }
                var azureAdB2C = new AzureAdB2C()
                {
                    AudToken = TokenAudience,
                    IssToken = TokenIssuer
                };

                var productDetail = await productDataService.CreateProductDataByProductIdentifiers(productIdentifierRequest, azureAdB2C);

                if (productDetail.IsExchangeSetTooLarge)
                {
                    Logger.LogError(EventIds.ExchangeSetTooLarge.ToEventId(), "Requested exchange set is too large for product identifiers endpoint for _X-Correlation-ID:{correlationId}", GetCurrentCorrelationId());
                    return BuildBadRequestErrorResponseForTooLargeExchangeSet();
                }
                return GetEssResponse(productDetail);
            }, GetCurrentCorrelationId()));
        }
Exemplo n.º 5
0
        public void WhenEmptyProductIdentifiersInProductIdentifiersRequest_ThenReturnBadRequest()
        {
            string[] productIdentifiers = new string[] { string.Empty };
            string   callbackUri        = string.Empty;
            var      model = new ProductIdentifierRequest
            {
                ProductIdentifier = productIdentifiers,
                CallbackUri       = callbackUri
            };
            var result = validator.TestValidate(model);

            result.ShouldHaveValidationErrorFor(fb => fb.ProductIdentifier);
            Assert.IsTrue(result.Errors.Any(x => x.ErrorMessage == "productIdentifiers cannot be null or empty."));
        }
Exemplo n.º 6
0
        public async Task <ExchangeSetServiceResponse> CreateProductDataByProductIdentifiers(ProductIdentifierRequest productIdentifierRequest, AzureAdB2C azureAdB2C)
        {
            DateTime salesCatalogueServiceRequestStartedAt = DateTime.UtcNow;
            var      salesCatalogueResponse = await salesCatalogueService.PostProductIdentifiersAsync(productIdentifierRequest.ProductIdentifier.ToList(), productIdentifierRequest.CorrelationId);

            long fileSize = 0;

            if (salesCatalogueResponse.ResponseCode == HttpStatusCode.OK)
            {
                fileSize = CommonHelper.GetFileSize(salesCatalogueResponse.ResponseBody);
                bool isAzureB2C = azureAdB2CHelper.IsAzureB2CUser(azureAdB2C, productIdentifierRequest.CorrelationId);
                if (isAzureB2C)
                {
                    var checkFileResponse = CheckIfExchangeSetTooLarge(fileSize);
                    if (checkFileResponse.HttpStatusCode != HttpStatusCode.OK)
                    {
                        return(checkFileResponse);
                    }
                }
            }
            DateTime salesCatalogueServiceRequestCompletedAt = DateTime.UtcNow;

            monitorHelper.MonitorRequest("Sales Catalogue Service Product Identifier Request", salesCatalogueServiceRequestStartedAt, salesCatalogueServiceRequestCompletedAt, productIdentifierRequest.CorrelationId, null, null, fileSize, null);

            var response = SetExchangeSetResponse(salesCatalogueResponse, false);

            if (response.HttpStatusCode != HttpStatusCode.OK && response.HttpStatusCode != HttpStatusCode.NotModified)
            {
                return(response);
            }

            var exchangeSetServiceResponse = await SetExchangeSetResponseLinks(response, productIdentifierRequest.CorrelationId);

            if (exchangeSetServiceResponse.HttpStatusCode != HttpStatusCode.Created)
            {
                return(exchangeSetServiceResponse);
            }

            string expiryDate = exchangeSetServiceResponse.ExchangeSetResponse.ExchangeSetUrlExpiryDateTime.Value.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture);

            if (!string.IsNullOrEmpty(exchangeSetServiceResponse.BatchId))
            {
                await SaveSalesCatalogueStorageDetails(salesCatalogueResponse.ResponseBody, exchangeSetServiceResponse.BatchId, productIdentifierRequest.CallbackUri, productIdentifierRequest.CorrelationId, expiryDate);
            }

            return(response);
        }
Exemplo n.º 7
0
 public Task <ValidationResult> ValidateProductDataByProductIdentifiers(ProductIdentifierRequest productIdentifierRequest)
 {
     return(productIdentifierValidator.Validate(productIdentifierRequest));
 }