/// <summary> /// Handles a request /// </summary> /// <param name="request">The request</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns> /// Response from the request /// </returns> public async Task <String> Handle(AddProductToContractRequest request, CancellationToken cancellationToken) { await this.ContractDomainService.AddProductToContract(request.ProductId, request.ContractId, request.ProductName, request.DisplayText, request.Value, cancellationToken); return(string.Empty); }
public void ContractRequestHandler_AddProductToContractRequest_IsHandled() { Mock <IContractDomainService> contractDomainService = new Mock <IContractDomainService>(); ContractRequestHandler handler = new ContractRequestHandler(contractDomainService.Object); AddProductToContractRequest request = TestData.AddProductToContractRequest; Should.NotThrow(async() => { await handler.Handle(request, CancellationToken.None); }); }
public void AddProductToContractRequest_WithVariableValue_CanBeCreated_IsCreated() { AddProductToContractRequest addProductToContractRequest = AddProductToContractRequest.Create(TestData.ContractId, TestData.EstateId, TestData.ProductId, TestData.ProductName, TestData.ProductDisplayText, null); addProductToContractRequest.ShouldNotBeNull(); addProductToContractRequest.ContractId.ShouldBe(TestData.ContractId); addProductToContractRequest.EstateId.ShouldBe(TestData.EstateId); addProductToContractRequest.ProductId.ShouldBe(TestData.ProductId); addProductToContractRequest.ProductName.ShouldBe(TestData.ProductName); addProductToContractRequest.DisplayText.ShouldBe(TestData.ProductDisplayText); addProductToContractRequest.Value.ShouldBeNull(); }
/// <summary> /// Adds the product to contract. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="estateId">The estate identifier.</param> /// <param name="contractId">The contract identifier.</param> /// <param name="addProductToContractRequest">The add product to contract request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <AddProductToContractResponse> AddProductToContract(String accessToken, Guid estateId, Guid contractId, AddProductToContractRequest addProductToContractRequest, CancellationToken cancellationToken) { AddProductToContractResponse response = null; String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts/{contractId}/products"); try { String requestSerialised = JsonConvert.SerializeObject(addProductToContractRequest); StringContent httpContent = new StringContent(requestSerialised, Encoding.UTF8, "application/json"); // Add the access token to the client headers this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.PostAsync(requestUri, httpContent, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <AddProductToContractResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error adding product [{addProductToContractRequest.ProductName}] to contract [{contractId}] for estate {estateId}.", ex); throw exception; } return(response); }
public async Task WhenICreateTheFollowingProducts(Table table) { foreach (TableRow tableRow in table.Rows) { EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); String token = this.TestingContext.AccessToken; if (String.IsNullOrEmpty(estateDetails.AccessToken) == false) { token = estateDetails.AccessToken; } String contractName = SpecflowTableHelper.GetStringRowValue(tableRow, "ContractDescription"); Contract contract = estateDetails.GetContract(contractName); String productValue = SpecflowTableHelper.GetStringRowValue(tableRow, "Value"); AddProductToContractRequest addProductToContractRequest = new AddProductToContractRequest { ProductName = SpecflowTableHelper.GetStringRowValue(tableRow, "ProductName"), DisplayText = SpecflowTableHelper.GetStringRowValue(tableRow, "DisplayText"), Value = null }; if (String.IsNullOrEmpty(productValue) == false) { addProductToContractRequest.Value = Decimal.Parse(productValue); } AddProductToContractResponse addProductToContractResponse = await this.TestingContext.DockerHelper.EstateClient.AddProductToContract(token, estateDetails.EstateId, contract.ContractId, addProductToContractRequest, CancellationToken.None); contract.AddProduct(addProductToContractResponse.ProductId, addProductToContractRequest.ProductName, addProductToContractRequest.DisplayText, addProductToContractRequest.Value); } }