private static void AppendTextContent( StringBuilder sb, EndpointMethodMetadata endpointMethodMetadata, HttpStatusCode testExpectedHttpStatusCode, ResponseTypeNameAndItemSchema contractReturnTypeName) { sb.AppendLine(8, "{"); if (endpointMethodMetadata.HasContractParameterAnyParametersOrRequestBody()) { sb.AppendLine(12, "// Arrange"); var headerParameters = endpointMethodMetadata.GetHeaderParameters(); if (headerParameters.Count > 0) { foreach (var headerParameter in headerParameters) { var propertyValueGenerated = PropertyValueGenerator(headerParameter, endpointMethodMetadata.ComponentsSchemas, useForBadRequest: false, customValue: null); sb.AppendLine( 12, $"HttpClient.DefaultRequestHeaders.Add(\"{headerParameter.Name}\", \"{propertyValueGenerated}\");"); } sb.AppendLine(); } var isContractParameterRequestBodyUsedAsMultipartOctetStreamData = endpointMethodMetadata.IsContractParameterRequestBodyUsedAsMultipartOctetStreamData(); if (isContractParameterRequestBodyUsedAsMultipartOctetStreamData) { sb.AppendLine(12, "var data = GetTestFile();"); } else { var isModelCreated = AppendNewRequestModel(12, sb, endpointMethodMetadata, contractReturnTypeName.StatusCode); if (!isModelCreated && endpointMethodMetadata.HttpOperation.IsRequestBodySupported()) { sb.AppendLine(12, "var data = \"{ }\";"); } } sb.AppendLine(); if (endpointMethodMetadata.IsContractParameterRequestBodyUsedAsMultipartFormData()) { AppendActHttpClientOperationForMultipartFormData( 12, sb, endpointMethodMetadata.HttpOperation, endpointMethodMetadata.GetRequestBodyModelName() !); } else if (isContractParameterRequestBodyUsedAsMultipartOctetStreamData) { AppendActHttpClientOperationForMultipartFormData( 12, sb, endpointMethodMetadata.HttpOperation, $"{endpointMethodMetadata.MethodName}{NameConstants.Request}"); } else { AppendActHttpClientOperation(12, sb, endpointMethodMetadata.HttpOperation, useData: true); } } else { AppendActHttpClientOperation(12, sb, endpointMethodMetadata.HttpOperation); } sb.AppendLine(); sb.AppendLine(12, "// Assert"); sb.AppendLine(12, "response.Should().NotBeNull();"); sb.AppendLine(12, $"response.StatusCode.Should().Be(HttpStatusCode.{testExpectedHttpStatusCode});"); if (testExpectedHttpStatusCode == HttpStatusCode.OK && !string.IsNullOrEmpty(contractReturnTypeName.FullModelName) && contractReturnTypeName.Schema is not null && !contractReturnTypeName.Schema.IsSimpleDataType() && !(endpointMethodMetadata.IsContractParameterRequestBodyUsedAsMultipartOctetStreamData() || endpointMethodMetadata.IsContractParameterRequestBodyUsedAsMultipartFormData())) { var modelName = OpenApiDocumentSchemaModelNameHelper.EnsureModelNameWithNamespaceIfNeeded(endpointMethodMetadata, contractReturnTypeName.FullModelName); sb.AppendLine(); sb.AppendLine(12, $"var responseData = await response.DeserializeAsync<{modelName}>(JsonSerializerOptions);"); sb.AppendLine(12, "responseData.Should().NotBeNull();"); } sb.AppendLine(8, "}"); }