public static CreateMerchantResponse Unmarshall(UnmarshallerContext context) { CreateMerchantResponse createMerchantResponse = new CreateMerchantResponse(); createMerchantResponse.HttpResponse = context.HttpResponse; createMerchantResponse.RequestId = context.StringValue("CreateMerchant.RequestId"); createMerchantResponse.Success = context.BooleanValue("CreateMerchant.Success"); return(createMerchantResponse); }
/// <summary> /// Creates the merchant. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="estateId">The estate identifier.</param> /// <param name="createMerchantRequest">The create merchant request.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <CreateMerchantResponse> CreateMerchant(String accessToken, Guid estateId, CreateMerchantRequest createMerchantRequest, CancellationToken cancellationToken) { CreateMerchantResponse response = null; String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants"); try { String requestSerialised = JsonConvert.SerializeObject(createMerchantRequest); 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 <CreateMerchantResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error creating new merchant {createMerchantRequest.Name} for estate {estateId}.", ex); throw exception; } return(response); }
public async Task WhenICreateTheFollowingMerchants(Table table) { foreach (TableRow tableRow in table.Rows) { // lookup the estate id based on the name in the table EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); String token = this.TestingContext.AccessToken; if (String.IsNullOrEmpty(estateDetails.AccessToken) == false) { token = estateDetails.AccessToken; } String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName"); CreateMerchantRequest createMerchantRequest = new CreateMerchantRequest { Name = merchantName, Contact = new Contact { ContactName = SpecflowTableHelper.GetStringRowValue(tableRow, "ContactName"), EmailAddress = SpecflowTableHelper.GetStringRowValue(tableRow, "EmailAddress") }, Address = new Address { AddressLine1 = SpecflowTableHelper.GetStringRowValue(tableRow, "AddressLine1"), Town = SpecflowTableHelper.GetStringRowValue(tableRow, "Town"), Region = SpecflowTableHelper.GetStringRowValue(tableRow, "Region"), Country = SpecflowTableHelper.GetStringRowValue(tableRow, "Country") } }; CreateMerchantResponse response = await this.TestingContext.DockerHelper.EstateClient .CreateMerchant(token, estateDetails.EstateId, createMerchantRequest, CancellationToken.None).ConfigureAwait(false); response.ShouldNotBeNull(); response.EstateId.ShouldBe(estateDetails.EstateId); response.MerchantId.ShouldNotBe(Guid.Empty); // Cache the merchant id estateDetails.AddMerchant(response.MerchantId, merchantName); this.TestingContext.Logger.LogInformation($"Merchant {merchantName} created with Id {response.MerchantId} for Estate {estateDetails.EstateName}"); } foreach (TableRow tableRow in table.Rows) { EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName"); Guid merchantId = estateDetails.GetMerchantId(merchantName); String token = this.TestingContext.AccessToken; if (String.IsNullOrEmpty(estateDetails.AccessToken) == false) { token = estateDetails.AccessToken; } await Retry.For(async() => { MerchantResponse merchant = await this.TestingContext.DockerHelper.EstateClient .GetMerchant(token, estateDetails.EstateId, merchantId, CancellationToken.None) .ConfigureAwait(false); merchant.MerchantName.ShouldBe(merchantName); }); } }