This commit is contained in:
Pavel Krymets 2019-12-09 10:08:31 -08:00 коммит произвёл GitHub
Родитель 15585ee168
Коммит 976ab7bcc8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
29 изменённых файлов: 536 добавлений и 233 удалений

Просмотреть файл

@ -1,17 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
namespace AutoRest.CSharp.V3.ClientModels
{
internal struct ClientConstant
{
public ClientConstant(object value, FrameworkTypeReference type)
public ClientConstant(object? value, FrameworkTypeReference type)
{
Debug.Assert(value == null || value.GetType().Namespace?.StartsWith("System") == true);
Value = value;
Type = type;
if (value == null)
{
if (!type.IsNullable)
{
throw new InvalidOperationException("Null constant with non-nullable type");
}
return;
}
if (value.GetType() != type.Type)
{
throw new InvalidOperationException("Constant type mismatch");
}
}
public object? Value { get; }

Просмотреть файл

@ -7,12 +7,12 @@ namespace AutoRest.CSharp.V3.ClientModels
{
public ClientTypeReference ItemType { get; }
public CollectionTypeReference(ClientTypeReference itemType)
public CollectionTypeReference(ClientTypeReference itemType, bool isNullable)
{
ItemType = itemType;
IsNullable = isNullable;
}
//TODO: This should not be defaulted to nullable false
public override bool IsNullable => false;
public override bool IsNullable { get; }
}
}

Просмотреть файл

@ -5,13 +5,15 @@ namespace AutoRest.CSharp.V3.ClientModels
{
internal class PathSegment
{
public PathSegment(ConstantOrParameter value, bool escape)
public PathSegment(ConstantOrParameter value, bool escape, SerializationFormat format)
{
Value = value;
Escape = escape;
Format = format;
}
public ConstantOrParameter Value { get; }
public bool Escape { get; }
public SerializationFormat Format { get; }
}
}

Просмотреть файл

@ -7,9 +7,9 @@ namespace AutoRest.CSharp.V3.ClientModels
{
public string Name { get; }
public ConstantOrParameter Value { get; }
public HeaderSerializationFormat Format { get; }
public SerializationFormat Format { get; }
public RequestHeader(string name, ConstantOrParameter value, HeaderSerializationFormat format = HeaderSerializationFormat.Default)
public RequestHeader(string name, ConstantOrParameter value, SerializationFormat format = SerializationFormat.Default)
{
Name = name;
Value = value;

Просмотреть файл

@ -3,11 +3,12 @@
namespace AutoRest.CSharp.V3.ClientModels
{
internal enum HeaderSerializationFormat
internal enum SerializationFormat
{
Default,
DateTimeRFC1123,
DateTimeISO8601,
DateTimeUnix,
Date
}
}

Просмотреть файл

@ -89,53 +89,18 @@ namespace AutoRest.CSharp.V3.CodeGen
foreach (var segment in operation.Request.PathSegments)
{
var value = segment.Value;
Line(value.IsConstant
? $"request.Uri.AppendPath(\"{value.Constant.Value}\", {segment.Escape.ToString().ToLower()});"
: $"request.Uri.AppendPath({value.Parameter.Name}.ToString()!, {segment.Escape.ToString().ToLower()});");
WritePathSegment(segment);
}
foreach (var header in operation.Request.Headers)
{
if (header.Value.IsConstant)
{
Line($"request.Headers.Add(\"{header.Name}\", \"{header.Value.Constant.Value}\");");
continue;
}
var parameter = header.Value.Parameter;
var type = _typeFactory.CreateType(parameter.Type);
using (type.IsNullable ? If($"{parameter.Name} != null") : null)
{
//TODO: Determine conditions in which to ToString() or not
Append($"request.Headers.Add(\"{header.Name}\",");
Append(parameter.Name);
if (type.IsNullable && type.IsValueType)
{
Append(".Value");
}
WriteHeaderFormat(header.Format);
Line(");");
}
WriteHeader(header);
}
//TODO: Duplicate code between query and header parameter processing logic
foreach (var queryParameter in operation.Request.Query)
{
ConstantOrParameter value = queryParameter.Value;
if (value.IsConstant)
{
Line($"request.Uri.AppendQuery(\"{queryParameter.Name}\", \"{value.Constant.Value}\", {queryParameter.Escape.ToString().ToLower()});");
continue;
}
var parameter = value.Parameter;
using (parameter.Type.IsNullable ? If($"{parameter.Name} != null") : new DisposeAction())
{
//TODO: Determine conditions in which to ToString() or not
Line($"request.Uri.AppendQuery(\"{queryParameter.Name}\", {parameter.Name}.ToString()!, {queryParameter.Escape.ToString().ToLower()});");
}
WriteQueryParameter(queryParameter);
}
@ -172,19 +137,107 @@ namespace AutoRest.CSharp.V3.CodeGen
}
}
private void WriteHeaderFormat(HeaderSerializationFormat format)
private void WritePathSegment(PathSegment segment)
{
var value = segment.Value;
if (value.IsConstant)
{
Append("request.Uri.AppendPath(");
Literal(value.Constant.Value);
WriteSerializationFormat(segment.Format);
Append(", ");
Literal(segment.Escape);
Line(");");
return;
}
Append("request.Uri.AppendPath(");
Append(value.Parameter.Name);
WriteSerializationFormat(segment.Format);
Append(", ");
Literal(segment.Escape);
Line(");");
}
private void WriteHeader(RequestHeader header)
{
if (header.Value.IsConstant)
{
Append("request.Headers.Add(");
Literal(header.Name);
Append(", ");
Literal(header.Value.Constant.Value);
Line(");");
return;
}
var parameter = header.Value.Parameter;
var type = _typeFactory.CreateType(parameter.Type);
using (type.IsNullable ? If($"{parameter.Name} != null") : null)
{
Append("request.Headers.Add(");
Literal(header.Name);
Append(", ");
Append(parameter.Name);
if (type.IsNullable && type.IsValueType)
{
Append(".Value");
}
WriteSerializationFormat(header.Format);
Line(");");
}
}
private void WriteSerializationFormat(SerializationFormat format)
{
var formatSpecifier = format switch
{
HeaderSerializationFormat.DateTimeRFC1123 => "R",
HeaderSerializationFormat.DateTimeISO8601 => "S",
HeaderSerializationFormat.Date => "D",
SerializationFormat.DateTimeRFC1123 => "R",
SerializationFormat.DateTimeISO8601 => "S",
SerializationFormat.Date => "D",
SerializationFormat.DateTimeUnix => "U",
_ => null
};
if (formatSpecifier != null)
{
Append($", \"{formatSpecifier}\"");
Append($", ");
Literal(formatSpecifier);
}
}
private void WriteQueryParameter(QueryParameter queryParameter)
{
ConstantOrParameter value = queryParameter.Value;
if (value.IsConstant)
{
Append("request.Uri.AppendQuery(");
Literal(queryParameter.Name);
Append(", ");
Literal(value.Constant.Value);
Append(", ");
Literal(queryParameter.Escape);
Line(");");
return;
}
var parameter = value.Parameter;
var type = _typeFactory.CreateType(parameter.Type);
using (parameter.Type.IsNullable ? If($"{parameter.Name} != null") : null)
{
Append("request.Uri.AppendQuery(");
Literal(queryParameter.Name);
Append(", ");
Append(parameter.Name);
if (type.IsNullable && type.IsValueType)
{
Append(".Value");
}
Append(", ");
Literal(queryParameter.Escape);
Line(");");
}
}

Просмотреть файл

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using AutoRest.CSharp.V3.Utilities;
using Microsoft.CodeAnalysis.CSharp;
namespace AutoRest.CSharp.V3.CodeGen
{
@ -213,5 +214,20 @@ namespace AutoRest.CSharp.V3.CodeGen
var t when t == typeof(string) => "string",
_ => null
};
public void Literal(object? o)
{
Append(o switch
{
null => "null",
string s => SyntaxFactory.Literal(s).ToString(),
int i => SyntaxFactory.Literal(i).ToString(),
decimal d => SyntaxFactory.Literal(d).ToString(),
double d => SyntaxFactory.Literal(d).ToString(),
float f => SyntaxFactory.Literal(f).ToString(),
bool b => b ? "true" : "false",
_ => throw new NotImplementedException()
});
}
}
}

Просмотреть файл

@ -24,14 +24,7 @@ namespace AutoRest.CSharp.V3.JsonRpc.MessageModels
{
name = name.Substring(2);
}
if (parts.Length == 1)
{
_arguments[name] = "true";
}
else
{
_arguments[name] = parts[1];
}
_arguments[name] = parts.Length == 1 ? "true" : parts[1];
}
_basePath = _arguments["base-path"];

Просмотреть файл

@ -32,7 +32,9 @@ namespace AutoRest.CSharp.V3.Pipeline
// Cannot cache deserializer as parallel plugins will access it and cause failures.
// https://github.com/aaubry/YamlDotNet/pull/353/files#diff-86074b6acff29ccad667aca741f62ac5R83
private static IDeserializer Deserializer => new DeserializerBuilder().WithTagMapping(TagMap).WithTypeConverter(new YamlStringEnumConverter()).Build();
private static IDeserializer Deserializer => new DeserializerBuilder()
.WithTagMapping(TagMap)
.WithTypeConverter(new YamlStringEnumConverter()).Build();
public static CodeModel DeserializeCodeModel(string yaml) => Deserializer.Deserialize<CodeModel>(yaml);
public static Dictionary<string, PropertyInfo> GetDeserializableProperties(this Type type) => type.GetProperties()

Просмотреть файл

@ -12,7 +12,7 @@ using AutoRest.CSharp.V3.JsonRpc.MessageModels;
using AutoRest.CSharp.V3.Pipeline;
using AutoRest.CSharp.V3.Pipeline.Generated;
using Azure.Core;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SerializationFormat = AutoRest.CSharp.V3.ClientModels.SerializationFormat;
namespace AutoRest.CSharp.V3.Plugins
{
@ -59,7 +59,7 @@ namespace AutoRest.CSharp.V3.Plugins
private static ClientConstant? CreateDefaultValueConstant(Parameter requestParameter) =>
requestParameter.ClientDefaultValue != null ?
new ClientConstant(requestParameter.ClientDefaultValue, (FrameworkTypeReference) CreateType(requestParameter.Schema, requestParameter.IsNullable())) :
ParseClientConstant(requestParameter.ClientDefaultValue, (FrameworkTypeReference) CreateType(requestParameter.Schema, requestParameter.IsNullable())) :
(ClientConstant?)null;
private static ClientMethod? BuildMethod(Operation operation)
@ -73,10 +73,13 @@ namespace AutoRest.CSharp.V3.Plugins
return null;
}
Dictionary<string, ConstantOrParameter> parameters = new Dictionary<string, ConstantOrParameter>();
Dictionary<string, ConstantOrParameter> uriParameters = new Dictionary<string, ConstantOrParameter>();
Dictionary<string, PathSegment> pathParameters = new Dictionary<string, PathSegment>();
List<QueryParameter> query = new List<QueryParameter>();
List<RequestHeader> headers = new List<RequestHeader>();
List<ServiceClientMethodParameter> methodParameters = new List<ServiceClientMethodParameter>();
ConstantOrParameter? body = null;
foreach (Parameter requestParameter in operation.Request.Parameters ?? Array.Empty<Parameter>())
{
@ -87,7 +90,7 @@ namespace AutoRest.CSharp.V3.Plugins
switch (requestParameter.Schema)
{
case ConstantSchema constant:
constantOrParameter = new ClientConstant(constant.Value.Value, (FrameworkTypeReference)CreateType(constant.ValueType, false));
constantOrParameter = ParseClientConstant(constant.Value.Value, (FrameworkTypeReference)CreateType(constant.ValueType, false));
break;
case BinarySchema _:
// skip
@ -95,13 +98,13 @@ namespace AutoRest.CSharp.V3.Plugins
//TODO: Workaround for https://github.com/Azure/autorest.csharp/pull/275
case ArraySchema arraySchema when arraySchema.ElementType is ConstantSchema constantInnerType:
constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(),
new CollectionTypeReference(CreateType(constantInnerType.ValueType, false)),
new CollectionTypeReference(CreateType(constantInnerType.ValueType, false), false),
CreateDefaultValueConstant(requestParameter));
break;
//TODO: Workaround for https://github.com/Azure/autorest.csharp/pull/275
case DictionarySchema dictionarySchema when dictionarySchema.ElementType is ConstantSchema constantInnerType:
constantOrParameter = new ServiceClientMethodParameter(requestParameter.CSharpName(),
new CollectionTypeReference(CreateType(constantInnerType.ValueType, false)),
new CollectionTypeReference(CreateType(constantInnerType.ValueType, false), false),
CreateDefaultValueConstant(requestParameter));
break;
default:
@ -116,21 +119,29 @@ namespace AutoRest.CSharp.V3.Plugins
switch (httpParameter.In)
{
case ParameterLocation.Header:
headers.Add(new RequestHeader(serializedName, constantOrParameter.Value, ToHeaderFormat(requestParameter.Schema)));
headers.Add(new RequestHeader(serializedName, constantOrParameter.Value, GetSerializationFormat(requestParameter.Schema)));
break;
case ParameterLocation.Query:
query.Add(new QueryParameter(serializedName, constantOrParameter.Value, true));
break;
case ParameterLocation.Path:
pathParameters.Add(serializedName, new PathSegment(constantOrParameter.Value, true, GetSerializationFormat(requestParameter.Schema)));
break;
case ParameterLocation.Body:
body = constantOrParameter;
break;
case ParameterLocation.Uri:
uriParameters[defaultName] = constantOrParameter.Value;
break;
}
}
parameters[defaultName] = constantOrParameter.Value;
if (!constantOrParameter.Value.IsConstant)
{
methodParameters.Add(constantOrParameter.Value.Parameter);
}
}
if (httpRequest is HttpWithBodyRequest httpWithBodyRequest)
{
headers.AddRange(httpWithBodyRequest.MediaTypes.Select(mediaType => new RequestHeader("Content-Type", new ConstantOrParameter(StringConstant(mediaType)))));
@ -138,8 +149,8 @@ namespace AutoRest.CSharp.V3.Plugins
var request = new ClientMethodRequest(
httpRequest.Method.ToCoreRequestMethod() ?? RequestMethod.Get,
ToParts(httpRequest.Uri, parameters),
ToPathParts(httpRequest.Path, parameters),
ToParts(httpRequest.Uri, uriParameters),
ToPathParts(httpRequest.Path, pathParameters),
query.ToArray(),
headers.ToArray(),
httpResponse.StatusCodes.Select(ToStatusCode).ToArray(),
@ -156,19 +167,20 @@ namespace AutoRest.CSharp.V3.Plugins
return new ClientMethod(
operation.CSharpName(),
request,
parameters.Values.Where(parameter => !parameter.IsConstant).Select(parameter => parameter.Parameter).ToArray(),
methodParameters.ToArray(),
responseType
);
}
private static HeaderSerializationFormat ToHeaderFormat(Schema schema)
private static SerializationFormat GetSerializationFormat(Schema schema)
{
return schema switch
{
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTime => HeaderSerializationFormat.DateTimeISO8601,
DateSchema _ => HeaderSerializationFormat.Date,
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTimeRfc1123 => HeaderSerializationFormat.DateTimeRFC1123,
_ => HeaderSerializationFormat.Default,
UnixTimeSchema _ => SerializationFormat.DateTimeUnix,
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTime => SerializationFormat.DateTimeISO8601,
DateSchema _ => SerializationFormat.Date,
DateTimeSchema dateTimeSchema when dateTimeSchema.Format == DateTimeSchemaFormat.DateTimeRfc1123 => SerializationFormat.DateTimeRFC1123,
_ => SerializationFormat.Default,
};
}
@ -183,17 +195,30 @@ namespace AutoRest.CSharp.V3.Plugins
return host.ToArray();
}
private static PathSegment[] ToPathParts(string httpRequestUri, Dictionary<string, ConstantOrParameter> parameters)
private static PathSegment[] ToPathParts(string httpRequestUri, Dictionary<string, PathSegment> parameters)
{
PathSegment TextSegment(string text)
{
return new PathSegment(StringConstant(text), false, SerializationFormat.Default);
}
List<PathSegment> host = new List<PathSegment>();
foreach ((string text, bool isLiteral) in GetPathParts(httpRequestUri))
{
//TODO: WORKAROUND FOR https://github.com/Azure/autorest.modelerfour/issues/58
if (!isLiteral && !parameters.ContainsKey(text))
if (!isLiteral)
{
parameters[text] = StringConstant(text);
if (!parameters.TryGetValue(text, out var segment))
{
//TODO: WORKAROUND FOR https://github.com/Azure/autorest.modelerfour/issues/58
segment = TextSegment(text);
}
host.Add(segment);
}
else
{
host.Add(TextSegment(text));
}
host.Add(new PathSegment(isLiteral ? StringConstant(text) : parameters[text], !isLiteral));
}
return host.ToArray();
@ -201,7 +226,7 @@ namespace AutoRest.CSharp.V3.Plugins
private static int ToStatusCode(StatusCodes arg) => int.Parse(arg.ToString().Trim('_'));
private static ClientConstant StringConstant(string s) => new ClientConstant(s, new FrameworkTypeReference(typeof(string)));
private static ClientConstant StringConstant(string s) => ParseClientConstant(s, new FrameworkTypeReference(typeof(string)));
private static ClientModel BuildClientEnum(SealedChoiceSchema sealedChoiceSchema) => new ClientEnum(
sealedChoiceSchema,
@ -231,7 +256,7 @@ namespace AutoRest.CSharp.V3.Plugins
{
var constantSchema = (ConstantSchema)property.Schema;
FrameworkTypeReference type = (FrameworkTypeReference)CreateType(constantSchema.ValueType, false);
return new ClientObjectConstant(property.CSharpName(), type, new ClientConstant(constantSchema.Value.Value, type));
return new ClientObjectConstant(property.CSharpName(), type, ParseClientConstant(constantSchema.Value.Value, type));
}
private static ClientObjectProperty CreateProperty(Property property) =>
@ -240,16 +265,21 @@ namespace AutoRest.CSharp.V3.Plugins
//TODO: Handle nullability properly
private static ClientTypeReference CreateType(Schema schema, bool isNullable) => schema switch
{
BinarySchema _ => (ClientTypeReference)new BinaryTypeReference(false),
ByteArraySchema _ => new BinaryTypeReference(false),
BinarySchema _ => (ClientTypeReference)new BinaryTypeReference(isNullable),
ByteArraySchema _ => new BinaryTypeReference(isNullable),
//https://devblogs.microsoft.com/dotnet/do-more-with-patterns-in-c-8-0/
{ Type: AllSchemaTypes.Binary } => new BinaryTypeReference(false),
ArraySchema array => new CollectionTypeReference(CreateType(array.ElementType, false)),
ArraySchema array => new CollectionTypeReference(CreateType(array.ElementType, false), isNullable),
DictionarySchema dictionary => new DictionaryTypeReference(new FrameworkTypeReference(typeof(string)), CreateType(dictionary.ElementType, isNullable)),
_ when schema.Type.ToFrameworkCSharpType() is Type type => new FrameworkTypeReference(type, isNullable),
_ => new SchemaTypeReference(schema, isNullable)
};
private static ClientConstant ParseClientConstant(object? value, FrameworkTypeReference type)
{
return new ClientConstant(Convert.ChangeType(value, type.Type), type);
}
//TODO: Refactor as this is written quite... ugly.
private static IEnumerable<(string Text, bool IsLiteral)> GetPathParts(string? path)
{

Просмотреть файл

@ -10,34 +10,27 @@ namespace Azure.Core
{
public static void Add(this RequestHeaders headers, string name, bool value)
{
headers.Add(name, value ? "true" : "false");
headers.Add(name, TypeFormatters.ToString(value));
}
public static void Add(this RequestHeaders headers, string name, float value)
{
headers.Add(name, value.ToString("G"));
headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat));
}
public static void Add(this RequestHeaders headers, string name, double value)
{
headers.Add(name, value.ToString("G"));
headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat));
}
public static void Add(this RequestHeaders headers, string name, int value)
{
headers.Add(name, value.ToString("G"));
headers.Add(name, value.ToString(TypeFormatters.DefaultNumberFormat));
}
public static void Add(this RequestHeaders headers, string name, DateTime value, string format)
{
string formatted = format switch
{
"D" => value.ToString("yyyy-MM-dd"),
"S" => value.ToString("yyyy-MM-ddTHH:mm:ssZ"),
"R" => value.ToString("R"),
_ => throw new ArgumentException("Format is not supported", nameof(format))
};
headers.Add(name, formatted);
headers.Add(name, TypeFormatters.ToString(value, format));
}
public static void Add(this RequestHeaders headers, string name, TimeSpan value)

Просмотреть файл

@ -0,0 +1,58 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Globalization;
namespace Azure.Core
{
internal class TypeFormatters
{
public static string DefaultNumberFormat { get; } = "G";
public static string ToString(bool value) => value ? "true" : "false";
public static string ToString(DateTime value, string format)
{
return format switch
{
"D" => value.ToString("yyyy-MM-dd"),
"S" => value.ToString("yyyy-MM-ddTHH:mm:ssZ"),
"R" => value.ToString("R"),
"U" => new DateTimeOffset(value).ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture),
_ => throw new ArgumentException("Format is not supported", nameof(format))
};
}
public static string ToBase64UrlString(byte[] value)
{
var numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3;
var size = checked(numWholeOrPartialInputBlocks * 4);
var output = new char[size];
var numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0);
// Fix up '+' -> '-' and '/' -> '_'. Drop padding characters.
int i = 0;
for (; i < numBase64Chars; i++)
{
var ch = output[i];
if (ch == '+')
{
output[i] = '-';
}
else if (ch == '/')
{
output[i] = '_';
}
else if (ch == '=')
{
// We've reached a padding character; truncate the remainder.
break;
}
}
return new string(output, 0, i);
}
}
}

Просмотреть файл

@ -0,0 +1,98 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Xml;
namespace Azure.Core
{
internal static class UriBuilderExtensions
{
public static void AppendPath(this RequestUriBuilder builder, bool value, bool escape = false)
{
builder.AppendPath(TypeFormatters.ToString(value), escape);
}
public static void AppendPath(this RequestUriBuilder builder, float value, bool escape = true)
{
builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendPath(this RequestUriBuilder builder, double value, bool escape = true)
{
builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendPath(this RequestUriBuilder builder, int value, bool escape = true)
{
builder.AppendPath(value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendPath(this RequestUriBuilder builder, byte[] value, bool escape = true)
{
builder.AppendPath(TypeFormatters.ToBase64UrlString(value), escape);
}
public static void AppendPath(this RequestUriBuilder builder, IEnumerable<string> value, bool escape = true)
{
builder.AppendPath(string.Join(",", value), escape);
}
public static void AppendPath<T>(this RequestUriBuilder builder, T value, bool escape = false)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
builder.AppendPath(value.ToString()!, escape);
}
public static void AppendPath(this RequestUriBuilder builder, DateTime value, string format, bool escape = true)
{
builder.AppendPath(TypeFormatters.ToString(value, format), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, bool value, bool escape = false)
{
builder.AppendQuery(name, TypeFormatters.ToString(value), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, float value, bool escape = true)
{
builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, double value, bool escape = true)
{
builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, int value, bool escape = true)
{
builder.AppendQuery(name, value.ToString(TypeFormatters.DefaultNumberFormat), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, TimeSpan value, bool escape = true)
{
builder.AppendQuery(name, XmlConvert.ToString(value), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, byte[] value, bool escape = true)
{
builder.AppendQuery(name, Convert.ToBase64String(value), escape);
}
public static void AppendQuery(this RequestUriBuilder builder, string name, IEnumerable<string> value, bool escape = true)
{
builder.AppendQuery(name, string.Join(",", value), escape);
}
public static void AppendQuery<T>(this RequestUriBuilder builder, string name, T value, bool escape = false)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
builder.AppendQuery(name, value.ToString()!, escape);
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Text;
namespace AutoRest.TestServer.Tests
{
public class TestConstants
{
public static byte[] ByteArray { get; } = Encoding.UTF8.GetBytes("啊齄丂狛狜隣郎隣兀﨩");
}
}

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT License.
using System;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using AutoRest.TestServer.Tests.Infrastructure;
@ -19,9 +18,6 @@ namespace AutoRest.TestServer.Tests
private static readonly DateTime ValidDate = new DateTime(2010, 1, 1, 12, 34, 56);
public HeaderTests(TestServerVersion version) : base(version, "header") { }
public static byte[] ByteArray { get; } =
Encoding.UTF8.GetBytes("啊齄丂狛狜隣郎隣兀﨩");
[Test]
public Task HeaderParameterExistingKey() => TestStatus(async (host, pipeline) => await HeaderOperations.ParamExistingKeyAsync(ClientDiagnostics, pipeline, "overwrite", host: host));
@ -156,7 +152,7 @@ namespace AutoRest.TestServer.Tests
public Task HeaderResponseDurationValid() => TestStatus(async (host, pipeline) => await HeaderOperations.ResponseDurationAsync(ClientDiagnostics, pipeline, scenario: "valid", host: host));
[Test]
public Task HeaderParameterBytesValid() => TestStatus(async (host, pipeline) => await HeaderOperations.ParamByteAsync(ClientDiagnostics, pipeline, scenario: "valid", ByteArray, host: host));
public Task HeaderParameterBytesValid() => TestStatus(async (host, pipeline) => await HeaderOperations.ParamByteAsync(ClientDiagnostics, pipeline, scenario: "valid", TestConstants.ByteArray, host: host));
[Test]
public Task HeaderResponseBytesValid() => TestStatus(async (host, pipeline) => await HeaderOperations.ResponseByteAsync(ClientDiagnostics, pipeline, scenario: "valid", host: host));

Просмотреть файл

@ -42,10 +42,11 @@ namespace AutoRest.TestServer.Tests
public Task UrlQueriesLongNull() => TestStatus(async (host, pipeline) => await QueriesOperations.GetLongNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("Wrong float format")]
[IgnoreOnTestServer(TestServerVersion.V2, "Recording match is too strict")]
public Task UrlQueriesFloatPositive() => TestStatus(async (host, pipeline) => await QueriesOperations.FloatScientificPositiveAsync(ClientDiagnostics, pipeline, host: host));
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "Recording match is too strict")]
public Task UrlQueriesFloatNegative() => TestStatus(async (host, pipeline) => await QueriesOperations.FloatScientificNegativeAsync(ClientDiagnostics, pipeline, host: host));
[Test]
@ -61,7 +62,7 @@ namespace AutoRest.TestServer.Tests
public Task UrlQueriesDoubleNull() => TestStatus(async (host, pipeline) => await QueriesOperations.DoubleNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("Causes 500 server error")]
[Ignore("No test server handler for this one")]
public Task StringUnicodeAsync() => TestStatus(async (host, pipeline) => await QueriesOperations.StringUnicodeAsync(ClientDiagnostics, pipeline, host: host));
[Test]
@ -80,20 +81,14 @@ namespace AutoRest.TestServer.Tests
public Task UrlQueriesEnumNull() => TestStatus(async (host, pipeline) => await QueriesOperations.EnumNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("byte[] not supported")]
public Task UrlQueriesByteMultiByte() => TestStatus(async (host, pipeline) => await QueriesOperations.ByteMultiByteAsync(ClientDiagnostics, pipeline, new byte[0], host: host));
public Task UrlQueriesByteMultiByte() => TestStatus(async (host, pipeline) => await QueriesOperations.ByteMultiByteAsync(ClientDiagnostics, pipeline, TestConstants.ByteArray, host: host));
[Test]
[Ignore("nullref")]
public Task UrlQueriesByteNull() => TestStatus(async (host, pipeline) => await QueriesOperations.ByteNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
public Task UrlQueriesByteEmpty() => TestStatus(async (host, pipeline) => await QueriesOperations.ByteEmptyAsync(ClientDiagnostics, pipeline, host: host));
[Test]
[Ignore("null ref")]
public Task ByteNullAsync() => TestStatus(async (host, pipeline) => await QueriesOperations.ByteNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
public Task UrlQueriesDateValid() => TestStatus(async (host, pipeline) => await QueriesOperations.DateValidAsync(ClientDiagnostics, pipeline, host: host));
@ -108,15 +103,12 @@ namespace AutoRest.TestServer.Tests
public Task UrlQueriesDateTimeNull() => TestStatus(async (host, pipeline) => await QueriesOperations.DateTimeNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("CSV not supported")]
public Task UrlQueriesArrayCsvValid() => TestStatus(async (host, pipeline) => await QueriesOperations.ArrayStringCsvValidAsync(ClientDiagnostics, pipeline, new string[0], host: host));
public Task UrlQueriesArrayCsvValid() => TestStatus(async (host, pipeline) => await QueriesOperations.ArrayStringCsvValidAsync(ClientDiagnostics, pipeline, new[] {"ArrayQuery1", "begin!*'();:@ &=+$,/?#[]end", "", ""}, host: host));
[Test]
[Ignore("CSV not supported")]
public Task UrlQueriesArrayCsvNull() => TestStatus(async (host, pipeline) => await QueriesOperations.ArrayStringCsvNullAsync(ClientDiagnostics, pipeline, new string[0], host: host));
public Task UrlQueriesArrayCsvNull() => TestStatus(async (host, pipeline) => await QueriesOperations.ArrayStringCsvNullAsync(ClientDiagnostics, pipeline, null, host: host));
[Test]
[Ignore("CSV not supported")]
public Task UrlQueriesArrayCsvEmpty() => TestStatus(async (host, pipeline) => await QueriesOperations.ArrayStringCsvEmptyAsync(ClientDiagnostics, pipeline, new string[0], host: host));
[Test]

Просмотреть файл

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
using NUnit.Framework;
@ -22,35 +23,31 @@ namespace AutoRest.TestServer.Tests
public Task UrlPathsEnumValid() => TestStatus(async (host, pipeline) => await PathsOperations.EnumValidAsync(ClientDiagnostics, pipeline, UriColor.GreenColor, host));
[Test]
[Ignore("Wrong url")]
public Task UrlPathsStringUrlEncoded() => TestStatus(async (host, pipeline) => await PathsOperations.StringUrlEncodedAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Wrong url")]
public Task UrlStringNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.StringNullAsync(ClientDiagnostics, pipeline, "", host));
[Ignore("Don't have null-checks yet")]
public Task UrlStringNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.StringNullAsync(ClientDiagnostics, pipeline, null, host));
[Test]
[Ignore("Wrong url")]
[Ignore("Wasn't able to find a server endpoint for this")]
public Task UrlStringUnicodeAsync() => TestStatus(async (host, pipeline) => await PathsOperations.StringUnicodeAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Wrong url")]
public Task UrlPathsArrayCSVInPath() => TestStatus(async (host, pipeline) => await PathsOperations.ArrayCsvInPathAsync(ClientDiagnostics, pipeline, new[] { "a", "b", "c" }, host));
public Task UrlPathsArrayCSVInPath() => TestStatus(async (host, pipeline) => await PathsOperations.ArrayCsvInPathAsync(ClientDiagnostics, pipeline, new[] { "ArrayPath1", "begin!*'();:@ &=+$,/?#[]end", "", "" }, host));
[Test]
[Ignore("Wrong url")]
public Task UrlPathsStringBase64Url() => TestStatus(async (host, pipeline) => await PathsOperations.Base64UrlAsync(ClientDiagnostics, pipeline, new byte[] { 1, 2, 3 }, host));
public Task UrlPathsStringBase64Url() => TestStatus(async (host, pipeline) => await PathsOperations.Base64UrlAsync(ClientDiagnostics, pipeline, Encoding.UTF8.GetBytes("lorem"), host));
[Test]
public Task UrlPathsByteEmpty() => TestStatus(async (host, pipeline) => await PathsOperations.ByteEmptyAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Wrong url")]
public Task UrlPathsByteMultiByte() => TestStatus(async (host, pipeline) => await PathsOperations.ByteMultiByteAsync(ClientDiagnostics, pipeline, new byte[] { 1, 2, 3 }, host));
public Task UrlPathsByteMultiByte() => TestStatus(async (host, pipeline) => await PathsOperations.ByteMultiByteAsync(ClientDiagnostics, pipeline, TestConstants.ByteArray, host));
[Test]
[Ignore("Wrong url")]
public Task UrlByteNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.ByteNullAsync(ClientDiagnostics, pipeline, new byte[0], host));
[Ignore("Don't have null-checks yet")]
public Task UrlByteNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.ByteNullAsync(ClientDiagnostics, pipeline, null, host));
[Test]
[Ignore("Might not apply")]
@ -61,22 +58,21 @@ namespace AutoRest.TestServer.Tests
public Task UrlEnumNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.EnumNullAsync(ClientDiagnostics, pipeline, new UriColor(), host));
[Test]
[Ignore("Wrong url")]
[Ignore("Might not apply")]
public Task UrlDateTimeNullAsync() => TestStatus(async (host, pipeline) => await PathsOperations.DateTimeNullAsync(ClientDiagnostics, pipeline, new DateTime(), host));
[Test]
public Task UrlPathsDateValid() => TestStatus(async (host, pipeline) => await PathsOperations.DateValidAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Wrong url")]
[IgnoreOnTestServer(TestServerVersion.V2, "Too strict")]
public Task UrlPathsDateTimeValid() => TestStatus(async (host, pipeline) => await PathsOperations.DateTimeValidAsync(ClientDiagnostics, pipeline, host));
[Test]
public Task UrlPathsLongPositive() => TestStatus(async (host, pipeline) => await PathsOperations.GetTenBillionAsync(ClientDiagnostics, pipeline, host));
[Test]
[Ignore("Wrong url")]
public Task UrlPathsIntUnixTime() => TestStatus(async (host, pipeline) => await PathsOperations.UnixTimeUrlAsync(ClientDiagnostics, pipeline, new DateTime(), host));
public Task UrlPathsIntUnixTime() => TestStatus(async (host, pipeline) => await PathsOperations.UnixTimeUrlAsync(ClientDiagnostics, pipeline, DateTimeOffset.FromUnixTimeSeconds(1460505600L).UtcDateTime, host));
[Test]
public Task UrlPathsIntNegative() => TestStatus(async (host, pipeline) => await PathsOperations.GetIntNegativeOneMillionAsync(ClientDiagnostics, pipeline, host));
@ -98,6 +94,7 @@ namespace AutoRest.TestServer.Tests
public Task UrlPathsFloatPositive() => TestStatus(async (host, pipeline) => await PathsOperations.FloatScientificPositiveAsync(ClientDiagnostics, pipeline, host));
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "Too strict")]
public Task UrlPathsFloatNegative() => TestStatus(async (host, pipeline) => await PathsOperations.FloatScientificNegativeAsync(ClientDiagnostics, pipeline, host));
[Test]

Просмотреть файл

@ -10,12 +10,15 @@ namespace body_complex.Models.V20160229
internal void Serialize(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WriteStartArray("array");
foreach (var item in Array)
if (Array != null)
{
writer.WriteStringValue(item);
writer.WriteStartArray("array");
foreach (var item in Array)
{
writer.WriteStringValue(item);
}
writer.WriteEndArray();
}
writer.WriteEndArray();
writer.WriteEndObject();
}
internal static ArrayWrapper Deserialize(JsonElement element)

Просмотреть файл

@ -11,8 +11,11 @@ namespace body_complex.Models.V20160229
internal void Serialize(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("field");
writer.WriteBase64StringValue(Field);
if (Field != null)
{
writer.WritePropertyName("field");
writer.WriteBase64StringValue(Field);
}
writer.WriteEndObject();
}
internal static ByteWrapper Deserialize(JsonElement element)

Просмотреть файл

@ -7,6 +7,6 @@ namespace body_complex.Models.V20160229
{
public partial class ByteWrapper
{
public Byte[] Field { get; set; }
public Byte[]? Field { get; set; }
}
}

Просмотреть файл

@ -15,12 +15,15 @@ namespace body_complex.Models.V20160229
writer.WritePropertyName("color");
writer.WriteStringValue(Color);
}
writer.WriteStartArray("hates");
foreach (var item in Hates)
if (Hates != null)
{
item.Serialize(writer);
writer.WriteStartArray("hates");
foreach (var item in Hates)
{
item.Serialize(writer);
}
writer.WriteEndArray();
}
writer.WriteEndArray();
writer.WriteEndObject();
}
internal static Cat Deserialize(JsonElement element)

Просмотреть файл

@ -15,23 +15,29 @@ namespace body_complex.Models.V20160229
writer.WritePropertyName("sampleSalmon");
SampleSalmon?.Serialize(writer);
}
writer.WriteStartArray("salmons");
foreach (var item in Salmons)
if (Salmons != null)
{
item.Serialize(writer);
writer.WriteStartArray("salmons");
foreach (var item in Salmons)
{
item.Serialize(writer);
}
writer.WriteEndArray();
}
writer.WriteEndArray();
if (SampleFish != null)
{
writer.WritePropertyName("sampleFish");
SampleFish?.Serialize(writer);
}
writer.WriteStartArray("fishes");
foreach (var item in Fishes)
if (Fishes != null)
{
item.Serialize(writer);
writer.WriteStartArray("fishes");
foreach (var item in Fishes)
{
item.Serialize(writer);
}
writer.WriteEndArray();
}
writer.WriteEndArray();
writer.WriteEndObject();
}
internal static DotFishMarket Deserialize(JsonElement element)

Просмотреть файл

@ -19,12 +19,15 @@ namespace body_complex.Models.V20160229
}
writer.WritePropertyName("length");
writer.WriteNumberValue(Length);
writer.WriteStartArray("siblings");
foreach (var item in Siblings)
if (Siblings != null)
{
item.Serialize(writer);
writer.WriteStartArray("siblings");
foreach (var item in Siblings)
{
item.Serialize(writer);
}
writer.WriteEndArray();
}
writer.WriteEndArray();
writer.WriteEndObject();
}
internal static Fish Deserialize(JsonElement element)

Просмотреть файл

@ -11,8 +11,11 @@ namespace body_complex.Models.V20160229
internal void Serialize(Utf8JsonWriter writer)
{
writer.WriteStartObject();
writer.WritePropertyName("picture");
writer.WriteBase64StringValue(Picture);
if (Picture != null)
{
writer.WritePropertyName("picture");
writer.WriteBase64StringValue(Picture);
}
writer.WriteEndObject();
}
internal static Sawshark Deserialize(JsonElement element)

Просмотреть файл

@ -7,6 +7,6 @@ namespace body_complex.Models.V20160229
{
public partial class Sawshark
{
public Byte[] Picture { get; set; }
public Byte[]? Picture { get; set; }
}
}

Просмотреть файл

@ -22,12 +22,12 @@ namespace custom_baseUrl_more_options
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{vault}{secret}{dnsSuffix}"));
request.Uri.AppendPath("/customuri/", false);
request.Uri.AppendPath(subscriptionId.ToString()!, true);
request.Uri.AppendPath(subscriptionId, true);
request.Uri.AppendPath("/", false);
request.Uri.AppendPath(keyName.ToString()!, true);
request.Uri.AppendPath(keyName, true);
if (keyVersion != null)
{
request.Uri.AppendQuery("keyVersion", keyVersion.ToString()!, true);
request.Uri.AppendQuery("keyVersion", keyVersion, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();

Просмотреть файл

@ -22,19 +22,19 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", true);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath.ToString()!, true);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
request.Uri.AppendPath(localStringPath.ToString()!, true);
request.Uri.AppendPath(localStringPath, true);
request.Uri.AppendPath("/globalStringQuery/pathItemStringQuery/localStringQuery", false);
if (pathItemStringQuery != null)
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery.ToString()!, true);
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery.ToString()!, true);
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -56,19 +56,19 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", true);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath.ToString()!, true);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
request.Uri.AppendPath(localStringPath.ToString()!, true);
request.Uri.AppendPath(localStringPath, true);
request.Uri.AppendPath("/null/pathItemStringQuery/localStringQuery", false);
if (pathItemStringQuery != null)
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery.ToString()!, true);
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery.ToString()!, true);
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -90,19 +90,19 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", true);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath.ToString()!, true);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
request.Uri.AppendPath(localStringPath.ToString()!, true);
request.Uri.AppendPath(localStringPath, true);
request.Uri.AppendPath("/null/pathItemStringQuery/null", false);
if (pathItemStringQuery != null)
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery.ToString()!, true);
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery.ToString()!, true);
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -124,19 +124,19 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/pathitem/nullable/globalStringPath/", false);
request.Uri.AppendPath("globalStringPath", true);
request.Uri.AppendPath("globalStringPath", false);
request.Uri.AppendPath("/pathItemStringPath/", false);
request.Uri.AppendPath(pathItemStringPath.ToString()!, true);
request.Uri.AppendPath(pathItemStringPath, true);
request.Uri.AppendPath("/localStringPath/", false);
request.Uri.AppendPath(localStringPath.ToString()!, true);
request.Uri.AppendPath(localStringPath, true);
request.Uri.AppendPath("/globalStringQuery/null/null", false);
if (pathItemStringQuery != null)
{
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery.ToString()!, true);
request.Uri.AppendQuery("pathItemStringQuery", pathItemStringQuery, true);
}
if (localStringQuery != null)
{
request.Uri.AppendQuery("localStringQuery", localStringQuery.ToString()!, true);
request.Uri.AppendQuery("localStringQuery", localStringQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();

Просмотреть файл

@ -24,7 +24,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/bool/true/", false);
request.Uri.AppendPath("true", true);
request.Uri.AppendPath(true, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -45,7 +45,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/bool/false/", false);
request.Uri.AppendPath("false", true);
request.Uri.AppendPath(false, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -66,7 +66,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/int/1000000/", false);
request.Uri.AppendPath("1000000", true);
request.Uri.AppendPath(1000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -87,7 +87,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/int/-1000000/", false);
request.Uri.AppendPath("-1000000", true);
request.Uri.AppendPath(-1000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -108,7 +108,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/long/10000000000/", false);
request.Uri.AppendPath("10000000000", true);
request.Uri.AppendPath(10000000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -129,7 +129,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/long/-10000000000/", false);
request.Uri.AppendPath("-10000000000", true);
request.Uri.AppendPath(-10000000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -150,7 +150,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/float/1.034E+20/", false);
request.Uri.AppendPath("103400000000000000000", true);
request.Uri.AppendPath(1.034E+20, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -171,7 +171,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/float/-1.034E-20/", false);
request.Uri.AppendPath("-1.034e-20", true);
request.Uri.AppendPath(-1.034E-20, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -192,7 +192,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/double/9999999.999/", false);
request.Uri.AppendPath("9999999.999", true);
request.Uri.AppendPath(9999999.999, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -213,7 +213,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/double/-9999999.999/", false);
request.Uri.AppendPath("-9999999.999", true);
request.Uri.AppendPath(-9999999.999, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -297,7 +297,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/string/null/", false);
request.Uri.AppendPath(stringPath.ToString()!, true);
request.Uri.AppendPath(stringPath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -318,7 +318,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/enum/green%20color/", false);
request.Uri.AppendPath(enumPath.ToString()!, true);
request.Uri.AppendPath(enumPath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -339,7 +339,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/string/null/", false);
request.Uri.AppendPath(enumPath.ToString()!, true);
request.Uri.AppendPath(enumPath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -360,7 +360,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/byte/multibyte/", false);
request.Uri.AppendPath(bytePath.ToString()!, true);
request.Uri.AppendPath(bytePath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -402,7 +402,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/byte/null/", false);
request.Uri.AppendPath(bytePath.ToString()!, true);
request.Uri.AppendPath(bytePath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -444,7 +444,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/date/null/", false);
request.Uri.AppendPath(datePath.ToString()!, true);
request.Uri.AppendPath(datePath, "D", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -486,7 +486,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/datetime/null/", false);
request.Uri.AppendPath(dateTimePath.ToString()!, true);
request.Uri.AppendPath(dateTimePath, "S", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -507,7 +507,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/string/bG9yZW0/", false);
request.Uri.AppendPath(base64UrlPath.ToString()!, true);
request.Uri.AppendPath(base64UrlPath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -528,7 +528,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/array/ArrayPath1%2cbegin%21%2A%27%28%29%3B%3A%40%20%26%3D%2B%24%2C%2F%3F%23%5B%5Dend%2c%2c/", false);
request.Uri.AppendPath(arrayPath.ToString()!, true);
request.Uri.AppendPath(arrayPath, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -549,7 +549,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/paths/int/1460505600/", false);
request.Uri.AppendPath(unixTimeUrlPath.ToString()!, true);
request.Uri.AppendPath(unixTimeUrlPath, "U", true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;

Просмотреть файл

@ -24,7 +24,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/bool/true", false);
request.Uri.AppendQuery("boolQuery", "true", true);
request.Uri.AppendQuery("boolQuery", true, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -45,7 +45,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/bool/false", false);
request.Uri.AppendQuery("boolQuery", "false", true);
request.Uri.AppendQuery("boolQuery", false, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -68,7 +68,7 @@ namespace url
request.Uri.AppendPath("/queries/bool/null", false);
if (boolQuery != null)
{
request.Uri.AppendQuery("boolQuery", boolQuery.ToString()!, true);
request.Uri.AppendQuery("boolQuery", boolQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -90,7 +90,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/int/1000000", false);
request.Uri.AppendQuery("intQuery", "1000000", true);
request.Uri.AppendQuery("intQuery", 1000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -111,7 +111,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/int/-1000000", false);
request.Uri.AppendQuery("intQuery", "-1000000", true);
request.Uri.AppendQuery("intQuery", -1000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -134,7 +134,7 @@ namespace url
request.Uri.AppendPath("/queries/int/null", false);
if (intQuery != null)
{
request.Uri.AppendQuery("intQuery", intQuery.ToString()!, true);
request.Uri.AppendQuery("intQuery", intQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -156,7 +156,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/long/10000000000", false);
request.Uri.AppendQuery("longQuery", "10000000000", true);
request.Uri.AppendQuery("longQuery", 10000000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -177,7 +177,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/long/-10000000000", false);
request.Uri.AppendQuery("longQuery", "-10000000000", true);
request.Uri.AppendQuery("longQuery", -10000000000, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -200,7 +200,7 @@ namespace url
request.Uri.AppendPath("/queries/long/null", false);
if (longQuery != null)
{
request.Uri.AppendQuery("longQuery", longQuery.ToString()!, true);
request.Uri.AppendQuery("longQuery", longQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -222,7 +222,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/float/1.034E+20", false);
request.Uri.AppendQuery("floatQuery", "103400000000000000000", true);
request.Uri.AppendQuery("floatQuery", 1.034E+20, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -243,7 +243,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/float/-1.034E-20", false);
request.Uri.AppendQuery("floatQuery", "-1.034e-20", true);
request.Uri.AppendQuery("floatQuery", -1.034E-20, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -266,7 +266,7 @@ namespace url
request.Uri.AppendPath("/queries/float/null", false);
if (floatQuery != null)
{
request.Uri.AppendQuery("floatQuery", floatQuery.ToString()!, true);
request.Uri.AppendQuery("floatQuery", floatQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -288,7 +288,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/double/9999999.999", false);
request.Uri.AppendQuery("doubleQuery", "9999999.999", true);
request.Uri.AppendQuery("doubleQuery", 9999999.999, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -309,7 +309,7 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/double/-9999999.999", false);
request.Uri.AppendQuery("doubleQuery", "-9999999.999", true);
request.Uri.AppendQuery("doubleQuery", -9999999.999, true);
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -332,7 +332,7 @@ namespace url
request.Uri.AppendPath("/queries/double/null", false);
if (doubleQuery != null)
{
request.Uri.AppendQuery("doubleQuery", doubleQuery.ToString()!, true);
request.Uri.AppendQuery("doubleQuery", doubleQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -419,7 +419,7 @@ namespace url
request.Uri.AppendPath("/queries/string/null", false);
if (stringQuery != null)
{
request.Uri.AppendQuery("stringQuery", stringQuery.ToString()!, true);
request.Uri.AppendQuery("stringQuery", stringQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -443,7 +443,7 @@ namespace url
request.Uri.AppendPath("/queries/enum/green%20color", false);
if (enumQuery != null)
{
request.Uri.AppendQuery("enumQuery", enumQuery.ToString()!, true);
request.Uri.AppendQuery("enumQuery", enumQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -467,7 +467,7 @@ namespace url
request.Uri.AppendPath("/queries/enum/null", false);
if (enumQuery != null)
{
request.Uri.AppendQuery("enumQuery", enumQuery.ToString()!, true);
request.Uri.AppendQuery("enumQuery", enumQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -479,7 +479,7 @@ namespace url
throw;
}
}
public static async ValueTask<Response> ByteMultiByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> ByteMultiByteAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[]? byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.ByteMultiByte");
scope.Start();
@ -489,7 +489,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/byte/multibyte", false);
request.Uri.AppendQuery("byteQuery", byteQuery.ToString()!, true);
if (byteQuery != null)
{
request.Uri.AppendQuery("byteQuery", byteQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -521,7 +524,7 @@ namespace url
throw;
}
}
public static async ValueTask<Response> ByteNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[] byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
public static async ValueTask<Response> ByteNullAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Byte[]? byteQuery, string host = "http://localhost:3000", CancellationToken cancellationToken = default)
{
using var scope = clientDiagnostics.CreateScope("url.ByteNull");
scope.Start();
@ -531,7 +534,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/byte/null", false);
request.Uri.AppendQuery("byteQuery", byteQuery.ToString()!, true);
if (byteQuery != null)
{
request.Uri.AppendQuery("byteQuery", byteQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -575,7 +581,7 @@ namespace url
request.Uri.AppendPath("/queries/date/null", false);
if (dateQuery != null)
{
request.Uri.AppendQuery("dateQuery", dateQuery.ToString()!, true);
request.Uri.AppendQuery("dateQuery", dateQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -620,7 +626,7 @@ namespace url
request.Uri.AppendPath("/queries/datetime/null", false);
if (dateTimeQuery != null)
{
request.Uri.AppendQuery("dateTimeQuery", dateTimeQuery.ToString()!, true);
request.Uri.AppendQuery("dateTimeQuery", dateTimeQuery.Value, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
@ -642,7 +648,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/csv/string/valid", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -663,7 +672,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/csv/string/null", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -684,7 +696,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/csv/string/empty", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -705,7 +720,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/ssv/string/valid", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -726,7 +744,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/tsv/string/valid", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;
@ -747,7 +768,10 @@ namespace url
request.Method = RequestMethod.Get;
request.Uri.Reset(new Uri($"{host}"));
request.Uri.AppendPath("/queries/array/pipes/string/valid", false);
request.Uri.AppendQuery("arrayQuery", arrayQuery.ToString()!, true);
if (arrayQuery != null)
{
request.Uri.AppendQuery("arrayQuery", arrayQuery, true);
}
var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
return response;