public async Task WhenIAddTheFollowingTransactionFees(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"); String productName = SpecflowTableHelper.GetStringRowValue(tableRow, "ProductName"); Contract contract = estateDetails.GetContract(contractName); Product product = contract.GetProduct(productName); AddTransactionFeeForProductToContractRequest addTransactionFeeForProductToContractRequest = new AddTransactionFeeForProductToContractRequest { Value = SpecflowTableHelper .GetDecimalValue(tableRow, "Value"), Description = SpecflowTableHelper.GetStringRowValue(tableRow, "FeeDescription"), CalculationType = SpecflowTableHelper .GetEnumValue <CalculationType>(tableRow, "CalculationType") }; AddTransactionFeeForProductToContractResponse addTransactionFeeForProductToContractResponse = await this.TestingContext.DockerHelper.EstateClient.AddTransactionFeeForProductToContract(token, estateDetails.EstateId, contract.ContractId, product.ProductId, addTransactionFeeForProductToContractRequest, CancellationToken.None); product.AddTransactionFee(addTransactionFeeForProductToContractResponse.TransactionFeeId, addTransactionFeeForProductToContractRequest.CalculationType, addTransactionFeeForProductToContractRequest.Description, addTransactionFeeForProductToContractRequest.Value); } }
/// <summary> /// Adds the transaction fee for 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="productId">The product identifier.</param> /// <param name="addTransactionFeeForProductToContractRequest">The add transaction fee for product to contract request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <AddTransactionFeeForProductToContractResponse> AddTransactionFeeForProductToContract(String accessToken, Guid estateId, Guid contractId, Guid productId, AddTransactionFeeForProductToContractRequest addTransactionFeeForProductToContractRequest, CancellationToken cancellationToken) { AddTransactionFeeForProductToContractResponse response = null; String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/contracts/{contractId}/products/{productId}/transactionFees"); try { String requestSerialised = JsonConvert.SerializeObject(addTransactionFeeForProductToContractRequest); 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 <AddTransactionFeeForProductToContractResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error adding transaction fee [{addTransactionFeeForProductToContractRequest.Description}] for product [{productId}] to contract [{contractId}] for estate {estateId}.", ex); throw exception; } return(response); }