Exemple #1
0
        public async Task WhenSinceDateTimeInRequest_ThenGetProductDataSinceDateTimeReturnsNotModified()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.NotModified
            };

            var validationMessage = new ValidationFailure("SinceDateTime", "NotModified.");

            validationMessage.ErrorCode = HttpStatusCode.NotModified.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (StatusCodeResult)await controller.GetProductDataSinceDateTime("Wed, 21 Oct 2015 07:28:00 GMT", "https://www.abc.com");

            Assert.AreEqual(304, result.StatusCode);
        }
Exemple #2
0
        public async Task WhenInvalidProductIdentifiersRequest_ThenPostProductIdentifiersReturnsBadRequest()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.BadRequest
            };

            var validationMessage = new ValidationFailure("ProductIdentifiers", "Product Identifiers cannot be null or empty.");

            validationMessage.ErrorCode = HttpStatusCode.BadRequest.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            string[] productIdentifiers = new string[] { "", "GB160060", "AU334550" };
            string   callbackUri        = string.Empty;

            var result = (BadRequestObjectResult)await controller.PostProductIdentifiers(productIdentifiers, callbackUri);

            var errors = (ErrorDescription)result.Value;

            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Product Identifiers cannot be null or empty.", errors.Errors.Single().Description);
        }
Exemple #3
0
        public async Task WhenEmptySinceDateTimeInRequest_ThenGetProductDataSinceDateTimeReturnsBadRequest()
        {
            var validationMessage = new ValidationFailure("SinceDateTime", "Query parameter 'sinceDateTime' is required.")
            {
                ErrorCode = HttpStatusCode.BadRequest.ToString()
            };

            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.BadRequest
            };

            A.CallTo(() => fakeProductDataService.ValidateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (BadRequestObjectResult)await controller.GetProductDataSinceDateTime(null, "https://www.abc.com");

            var errors = (ErrorDescription)result.Value;

            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Query parameter 'sinceDateTime' is required.", errors.Errors.Single().Description);
        }
Exemple #4
0
        public async Task WhenInvalidSinceDateTimeInRequest_ThenGetProductDataSinceDateTimeReturnsInternalServerError()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.InternalServerError
            };

            var validationMessage = new ValidationFailure("SinceDateTime", "Internal Server Error");

            validationMessage.ErrorCode = HttpStatusCode.InternalServerError.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataSinceDateTime(A <ProductDataSinceDateTimeRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (ObjectResult)await controller.GetProductDataSinceDateTime("Wed, 21 Oct 2015 07:28:00 GMT", "https://www.abc.com");

            Assert.AreSame("Internal Server Error", ((UKHO.ExchangeSetService.Common.Models.Response.InternalServerError)result.Value).Detail);
            Assert.AreEqual(500, result.StatusCode);
        }
Exemple #5
0
        public async Task WhenInvalidNullProductVersionRequest_ThenPostProductDataByProductVersionsReturnsBadRequest()
        {
            var validationMessage = new ValidationFailure("RequestBody", "Either body is null or malformed.")
            {
                ErrorCode = HttpStatusCode.BadRequest.ToString()
            };

            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.BadRequest
            };

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (BadRequestObjectResult)await controller.PostProductDataByProductVersions(new List <ProductVersionRequest>(), "");

            var errors = (ErrorDescription)result.Value;

            Assert.AreEqual(400, result.StatusCode);
            Assert.AreEqual("Either body is null or malformed.", errors.Errors.Single().Description);
        }
Exemple #6
0
        public async Task WhenInvalidProductVersionRequest_ThenPostProductDataByProductVersionsReturnsNotModified()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = (HttpStatusCode)(int)HttpStatusCode.NotModified
            };

            var validationMessage = new ValidationFailure("ProductVersions", "NotModified.");

            validationMessage.ErrorCode = HttpStatusCode.NotModified.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (StatusCodeResult)await controller.PostProductDataByProductVersions(new List <ProductVersionRequest>()
                                                                                             { new ProductVersionRequest()
                                                                                               {
                                                                                                   ProductName = "demo"
                                                                                               } }, "");

            Assert.AreEqual(304, result.StatusCode);
        }
Exemple #7
0
        public async Task WhenInvalidProductVersionRequest_ThenPostProductDataByProductVersionsReturnsInternalServerError()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.InternalServerError
            };

            var validationMessage = new ValidationFailure("ProductVersions", "Internal Server Error.");

            validationMessage.ErrorCode = HttpStatusCode.InternalServerError.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductVersions(A <ProductDataProductVersionsRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            var result = (ObjectResult)await controller.PostProductDataByProductVersions(new List <ProductVersionRequest>()
                                                                                         { new ProductVersionRequest()
                                                                                           {
                                                                                               ProductName = "demo"
                                                                                           } }, "");

            Assert.AreSame("Internal Server Error", ((UKHO.ExchangeSetService.Common.Models.Response.InternalServerError)result.Value).Detail);
            Assert.AreEqual(500, result.StatusCode);
        }
Exemple #8
0
        public async Task WhenInvalidProductIdentifiersRequest_ThenPostProductIdentifiersReturnsNotModified()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.NotModified
            };

            var validationMessage = new ValidationFailure("ProductIdentifiers", "NotModified.");

            validationMessage.ErrorCode = HttpStatusCode.NotModified.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            string[] productIdentifiers = new string[] { "GB123456", "GB160060", "AU334550" };
            string   callbackUri        = string.Empty;

            var result = (StatusCodeResult)await controller.PostProductIdentifiers(productIdentifiers, callbackUri);

            Assert.AreEqual(304, result.StatusCode);
        }
Exemple #9
0
        public async Task WhenInvalidProductIdentifiersRequest_ThenPostProductIdentifiersReturnsInternalServerError()
        {
            var exchangeSetResponse = new ExchangeSetResponse()
            {
            };
            var exchangeSetServiceResponse = new ExchangeSetServiceResponse()
            {
                ExchangeSetResponse = exchangeSetResponse,
                HttpStatusCode      = HttpStatusCode.InternalServerError
            };

            var validationMessage = new ValidationFailure("ProductIdentifiers", "Internal Server Error.");

            validationMessage.ErrorCode = HttpStatusCode.InternalServerError.ToString();

            A.CallTo(() => fakeProductDataService.ValidateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored))
            .Returns(new ValidationResult(new List <ValidationFailure> {
                validationMessage
            }));

            A.CallTo(() => fakeProductDataService.CreateProductDataByProductIdentifiers(A <ProductIdentifierRequest> .Ignored, A <AzureAdB2C> .Ignored))
            .Returns(exchangeSetServiceResponse);

            string[] productIdentifiers = new string[] { "GB123456", "GB160060", "AU334550" };
            string   callbackUri        = string.Empty;

            var result = (ObjectResult)await controller.PostProductIdentifiers(productIdentifiers, callbackUri);

            Assert.AreSame("Internal Server Error", ((UKHO.ExchangeSetService.Common.Models.Response.InternalServerError)result.Value).Detail);
            Assert.AreEqual(500, result.StatusCode);
        }
Exemple #10
0
        public async Task <bool> SendCallBackResponse(SalesCatalogueProductResponse salesCatalogueProductResponse, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage)
        {
            if (!string.IsNullOrWhiteSpace(scsResponseQueueMessage.CallbackUri))
            {
                try
                {
                    ExchangeSetResponse exchangeSetResponse = SetExchangeSetResponse(salesCatalogueProductResponse, scsResponseQueueMessage);

                    CallBackResponse callBackResponse = SetCallBackResponse(exchangeSetResponse);
                    callBackResponse.Subject = essCallBackConfiguration.Value.Subject;

                    if (ValidateCallbackRequestPayload(callBackResponse))
                    {
                        string payloadJson = JsonConvert.SerializeObject(callBackResponse);

                        return(await SendResponseToCallBackApi(false, payloadJson, scsResponseQueueMessage));
                    }
                    else
                    {
                        logger.LogError(EventIds.ExchangeSetCreatedPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} as payload data is incorrect.", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(EventIds.ExchangeSetCreatedPostCallbackUriNotCalled.ToEventId(), ex, "Post Callback uri is not called after exchange set is created for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId, ex.Message);
                    return(false);
                }
            }
            else
            {
                logger.LogInformation(EventIds.ExchangeSetCreatedPostCallbackUriNotProvided.ToEventId(), "Post callback uri was not provided by requestor for successful exchange set creation for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId);
                return(false);
            }
        }
Exemple #11
0
 public CallBackResponse SetCallBackResponse(ExchangeSetResponse exchangeSetResponse)
 {
     return(new CallBackResponse()
     {
         SpecVersion = essCallBackConfiguration.Value.SpecVersion,
         Type = essCallBackConfiguration.Value.Type,
         Source = essCallBackConfiguration.Value.Source,
         Id = Guid.NewGuid().ToString(),
         Time = DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture),
         Subject = string.Empty,
         DataContentType = "application/json",
         Data = exchangeSetResponse
     });
 }
Exemple #12
0
        public async Task <bool> SendCallBackErrorResponse(SalesCatalogueProductResponse salesCatalogueProductResponse, SalesCatalogueServiceResponseQueueMessage scsResponseQueueMessage)
        {
            salesCatalogueProductResponse.ProductCounts.ReturnedProductCount         = 0;
            salesCatalogueProductResponse.ProductCounts.RequestedProductsNotReturned = new List <RequestedProductsNotReturned> {
                new RequestedProductsNotReturned {
                    ProductName = null, Reason = essCallBackConfiguration.Value.Reason
                }
            };

            if (!string.IsNullOrWhiteSpace(scsResponseQueueMessage.CallbackUri))
            {
                try
                {
                    ExchangeSetResponse exchangeSetResponse = SetExchangeSetResponse(salesCatalogueProductResponse, scsResponseQueueMessage);
                    exchangeSetResponse.Links.ExchangeSetFileUri      = null;
                    exchangeSetResponse.Links.ExchangeSetErrorFileUri = new LinkSetErrorFileUri {
                        Href = $"{fileShareServiceConfig.Value.PublicBaseUrl}/batch/{scsResponseQueueMessage.BatchId}/files/{fileShareServiceConfig.Value.ErrorFileName}"
                    };

                    CallBackResponse callBackResponse = SetCallBackResponse(exchangeSetResponse);
                    callBackResponse.Subject = essCallBackConfiguration.Value.ErrorSubject;

                    if (ValidateCallbackErrorRequestPayload(callBackResponse))
                    {
                        string payloadJson = JsonConvert.SerializeObject(callBackResponse);

                        return(await SendResponseToCallBackApi(true, payloadJson, scsResponseQueueMessage));
                    }
                    else
                    {
                        logger.LogError(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} as payload data is incorrect.", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    logger.LogError(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotCalled.ToEventId(), "Post Callback uri is not called after exchange set is created with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId} and Exception:{Message}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId, ex.Message);
                    return(false);
                }
            }
            else
            {
                logger.LogInformation(EventIds.ExchangeSetCreatedWithErrorPostCallbackUriNotProvided.ToEventId(), "Post callback uri was not provided by requestor for exchange set creation with error for BatchId:{BatchId} and _X-Correlation-ID:{CorrelationId}", scsResponseQueueMessage.BatchId, scsResponseQueueMessage.CorrelationId);
                return(false);
            }
        }
Exemple #13
0
        private ExchangeSetResponse GetExchangeSetResponse()
        {
            LinkSetBatchStatusUri linkSetBatchStatusUri = new LinkSetBatchStatusUri()
            {
                Href = @"http://fss.ukho.gov.uk/batch/7b4cdf10-adfa-4ed6-b2fe-d1543d8b7272/status"
            };
            LinkSetBatchDetailsUri linkSetBatchDetailsUri = new LinkSetBatchDetailsUri()
            {
                Href = @"http://fss.ukho.gov.uk/batch/7b4cdf10-adfa-4ed6-b2fe-d1543d8b7272"
            };
            LinkSetFileUri linkSetFileUri = new LinkSetFileUri()
            {
                Href = @"http://fss.ukho.gov.uk/batch/7b4cdf10-adfa-4ed6-b2fe-d1543d8b7272/files/exchangeset123.zip",
            };
            Links links = new Links()
            {
                ExchangeSetBatchStatusUri  = linkSetBatchStatusUri,
                ExchangeSetBatchDetailsUri = linkSetBatchDetailsUri,
                ExchangeSetFileUri         = linkSetFileUri
            };
            List <RequestedProductsNotInExchangeSet> lstRequestedProductsNotInExchangeSet = new List <RequestedProductsNotInExchangeSet>()
            {
                new RequestedProductsNotInExchangeSet()
                {
                    ProductName = "GB123456",
                    Reason      = "productWithdrawn"
                },
                new RequestedProductsNotInExchangeSet()
                {
                    ProductName = "GB123789",
                    Reason      = "invalidProduct"
                }
            };
            ExchangeSetResponse exchangeSetResponse = new ExchangeSetResponse()
            {
                Links = links,
                ExchangeSetUrlExpiryDateTime          = Convert.ToDateTime("2021-02-17T16:19:32.269Z").ToUniversalTime(),
                RequestedProductCount                 = 22,
                ExchangeSetCellCount                  = 15,
                RequestedProductsAlreadyUpToDateCount = 5,
                RequestedProductsNotInExchangeSet     = lstRequestedProductsNotInExchangeSet
            };

            return(exchangeSetResponse);
        }