Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
154579f
fix utf8jsonbinarycontent in non-azure packages
ArcturusZhang Apr 15, 2024
935e398
update the version
ArcturusZhang Apr 15, 2024
12cdacb
Merge remote-tracking branch 'origin/feature/v3' into introduce-helpe…
ArcturusZhang Apr 15, 2024
6f05c96
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 15, 2024
79d0f61
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 15, 2024
ba37741
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 16, 2024
467032f
regen
ArcturusZhang Apr 16, 2024
254f58e
revert the changes in test project and add cadl-ranch cases
ArcturusZhang Apr 17, 2024
b839380
fix existing issues
ArcturusZhang Apr 17, 2024
fa4837f
fix cadl-ranch case
ArcturusZhang Apr 17, 2024
a3b6e77
try to fix the xml doc issue
ArcturusZhang Apr 17, 2024
214d766
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 17, 2024
f0b8277
Revert "try to fix the xml doc issue"
ArcturusZhang Apr 17, 2024
2fa55e2
include type/dictionary case
ArcturusZhang Apr 17, 2024
5c64edf
move the test cases from azure.core here
ArcturusZhang Apr 17, 2024
4ce83a4
Merge remote-tracking branch 'origin/feature/v3' into introduce-helpe…
ArcturusZhang Apr 18, 2024
8973c0b
refine test cases
ArcturusZhang Apr 18, 2024
c29c5ea
more refinement for test cases
ArcturusZhang Apr 18, 2024
f0bdb26
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 18, 2024
f96fdcf
fix namespace issue
ArcturusZhang Apr 18, 2024
2b1beb8
revert a undesired change and add test cases for type/dictionary
ArcturusZhang Apr 19, 2024
df24d4a
regen after merge
ArcturusZhang Apr 19, 2024
ccd50a7
update namespace according to our pattern
ArcturusZhang Apr 19, 2024
bc8dfb1
regen
ArcturusZhang Apr 19, 2024
8d8e073
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 19, 2024
b9a1437
regen type/array and fix test cases
ArcturusZhang Apr 19, 2024
cdadb74
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 19, 2024
233e91d
Merge branch 'feature/v3' into introduce-helpers-back
ArcturusZhang Apr 22, 2024
ecab648
regen
ArcturusZhang Apr 22, 2024
181653f
Merge remote-tracking branch 'origin/feature/v3' into introduce-helpe…
ArcturusZhang Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<!-- All csproj dependencies. -->
<ItemGroup>
<PackageReference Update="NUnit" Version="3.13.2" />
<PackageReference Update="System.ClientModel" Version="1.1.0-beta.2" />
<PackageReference Update="System.ClientModel" Version="1.1.0-beta.3" />
<PackageReference Update="Azure.Core" Version="1.39.0" />
<PackageReference Update="Azure.Core.Experimental" Version="0.1.0-preview.18" />
<PackageReference Update="Azure.ResourceManager" Version="1.11.0" />
Expand Down
2 changes: 2 additions & 0 deletions eng/testProjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"client/structure/two-operation-group"
],
"CadlRanchProjectsNonAzure":[
"type/array",
"type/dictionary",
"authentication/http/custom"
],
"TestServerProjects": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private string GetUnbrandedSrcCSProj()
};
private static readonly IReadOnlyList<CSProjWriter.CSProjDependencyPackage> _unbrandedDependencyPackages = new CSProjWriter.CSProjDependencyPackage[]
{
new("System.ClientModel", "1.1.0-beta.2"),
new("System.ClientModel", "1.1.0-beta.3"),
new("System.Text.Json", "4.7.2")
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

using System.Text.Json;
using AutoRest.CSharp.Common.Input;
using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
using AutoRest.CSharp.Common.Output.Models;
using AutoRest.CSharp.Output.Models.Shared;
Expand All @@ -21,7 +22,8 @@ public static JsonDocumentExpression Parse(StreamExpression stream, bool async)
{
// Sync and async methods have different set of parameters
return async
? new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.ParseAsync), new[] { stream, Snippets.Default, KnownParameters.CancellationTokenParameter }, true))
// non-azure libraries do not have cancellationToken parameter
? new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.ParseAsync), new[] { stream, Snippets.Default, Configuration.IsBranded ? KnownParameters.CancellationTokenParameter : Snippets.Default }, true))
: new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.Parse), stream));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ internal static IEnumerable<ExpressionTypeProvider> GetHelperProviders()
yield return ClientPipelineExtensionsProvider.Instance;
yield return ClientUriBuilderProvider.Instance;
}
if (Configuration.IsBranded)
{
yield return RequestContentHelperProvider.Instance;
yield return Utf8JsonRequestContentProvider.Instance;
}
yield return RequestContentHelperProvider.Instance;
yield return Utf8JsonRequestContentProvider.Instance;
if (Configuration.EnableBicepSerialization)
{
yield return BicepSerializationTypeProvider.Instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ internal class RequestContentHelperProvider : ExpressionTypeProvider
private readonly MethodSignatureModifiers _methodModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static;
private RequestContentHelperProvider() : base(Configuration.HelperNamespace, null)
{
// non-azure libraries do not need this type
Debug.Assert(Configuration.IsBranded);

DefaultName = $"{Configuration.ApiTypes.RequestContentType.Name}Helper";
DeclarationModifiers = TypeSignatureModifiers.Internal | TypeSignatureModifiers.Static;
_requestBodyType = Configuration.ApiTypes.RequestContentType;
_utf8JsonRequestBodyType = Utf8JsonRequestContentProvider.Instance.Type;
}

protected override string DefaultName => "RequestContentHelper";
protected override string DefaultName { get; }

protected override IEnumerable<Method> BuildMethods()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ internal class Utf8JsonRequestContentProvider : ExpressionTypeProvider

private Utf8JsonRequestContentProvider() : base(Configuration.HelperNamespace, null)
{
// non-azure libraries do not need this type
Debug.Assert(Configuration.IsBranded);

DeclarationModifiers = TypeSignatureModifiers.Internal;
DefaultName = Configuration.IsBranded ? "Utf8JsonRequestContent" : "Utf8JsonRequestBody";
DefaultName = $"Utf8Json{Configuration.ApiTypes.RequestContentType.Name}";
Inherits = Configuration.ApiTypes.RequestContentType;

_streamField = new FieldDeclaration(
Expand Down
2 changes: 1 addition & 1 deletion src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public IEnumerable<MethodBodyStatement> GetConvertStatements(LowLevelClientMetho

yield return new[]
{
new DeclareVariableStatement(value.Type, value.Declaration, Default),
Declare(value, Default),
JsonSerializationMethodsBuilder.BuildDeserializationForMethods(serialization, async, value, Extensible.RestOperations.GetContentStream(response), false, null),
Return(Extensible.RestOperations.GetTypedResponseFromValue(value, response))
};
Expand Down
8 changes: 8 additions & 0 deletions src/AutoRest.CSharp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,14 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\http\\custom\\src\\Generated -n"
},
"typespec-nonAzure-type/array": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\type\\array\\src\\Generated -n"
},
"typespec-nonAzure-type/dictionary": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\type\\dictionary\\src\\Generated -n"
},
"typespec-parameters/body-optionality": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\parameters\\body-optionality\\src\\Generated -n"
Expand Down
8 changes: 4 additions & 4 deletions test/AutoRest.Shared.Tests/RequestContentHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static IEnumerable<TestCaseData> GetDateTimeData()
[TestCase(1, 2)]
[TestCase("a", "b")]
[TestCase(true, false)]
[TestCaseSource("GetTimeSpanData")]
[TestCaseSource("GetDateTimeData")]
[TestCaseSource(nameof(GetTimeSpanData))]
[TestCaseSource(nameof(GetDateTimeData))]
public void TestGenericFromEnumerable<T>(T expectedValue1, T expectedValue2)
{
var expectedList = new List<T> { expectedValue1, expectedValue2 };
Expand Down Expand Up @@ -81,8 +81,8 @@ public void TestBinaryDataFromEnumerable()
[TestCase(1, 2)]
[TestCase("a", "b")]
[TestCase(true, false)]
[TestCaseSource("GetTimeSpanData")]
[TestCaseSource("GetDateTimeData")]
[TestCaseSource(nameof(GetTimeSpanData))]
[TestCaseSource(nameof(GetDateTimeData))]
public void TestGenericFromDictionary<T>(T expectedValue1, T expectedValue2)
{
var expectedDictionary = new Dictionary<string, T>()
Expand Down
34 changes: 15 additions & 19 deletions test/CadlRanchProjects.Tests/type-array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@ public class TypeArrayTests : CadlRanchTestBase
public Task Type_Array_Int32Value_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetInt32ValueClient().GetInt32ValueAsync();
Assert.AreEqual(1, response.Value.First());
Assert.AreEqual(2, response.Value.Last());
CollectionAssert.AreEqual(new[] { 1, 2 }, response.Value);
});

[Test]
public Task Type_Array_Int32Value_put() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetInt32ValueClient().PutAsync(new List<int> { 1, 2});
var response = await new ArrayClient(host, null).GetInt32ValueClient().PutAsync(new List<int> { 1, 2 });
Assert.AreEqual(204, response.Status);
});

[Test]
public Task Type_Array_Int64Value_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetInt64ValueClient().GetInt64ValueAsync();
Assert.AreEqual(9007199254740991, response.Value.First());
Assert.AreEqual(-9007199254740991, response.Value.Last());
CollectionAssert.AreEqual(new[] { 9007199254740991, -9007199254740991 }, response.Value);
});

[Test]
Expand All @@ -50,8 +48,7 @@ public Task Type_Array_Int64Value_put() => Test(async (host) =>
public Task Type_Array_BooleanValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetBooleanValueClient().GetBooleanValueAsync();
Assert.AreEqual(true, response.Value.First());
Assert.AreEqual(false, response.Value.Last());
CollectionAssert.AreEqual(new[] { true, false }, response.Value);
});

[Test]
Expand All @@ -65,8 +62,7 @@ public Task Type_Array_BooleanValue_put() => Test(async (host) =>
public Task Type_Array_StringValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetStringValueClient().GetStringValueAsync();
Assert.AreEqual("hello", response.Value.First());
Assert.AreEqual("", response.Value.Last());
CollectionAssert.AreEqual(new[] { "hello", "" }, response.Value);
});

[Test]
Expand All @@ -80,7 +76,7 @@ public Task Type_Array_StringValue_put() => Test(async (host) =>
public Task Type_Array_Float32Value_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync();
Assert.AreEqual(43.125f, response.Value.First());
CollectionAssert.AreEqual(new[] { 43.125f }, response.Value);
});

[Test]
Expand All @@ -94,7 +90,8 @@ public Task Type_Array_Float32Value_put() => Test(async (host) =>
public Task Type_Array_DatetimeValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync();
Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value.First());
Assert.AreEqual(1, response.Value.Count);
Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value[0]);
});

[Test]
Expand All @@ -108,13 +105,14 @@ public Task Type_Array_DatetimeValue_put() => Test(async (host) =>
public Task Type_Array_DurationValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetDurationValueClient().GetDurationValueAsync();
Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value.First());
Assert.AreEqual(1, response.Value.Count);
Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value[0]);
});

[Test]
public Task Type_Array_DurationValue_put() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetDurationValueClient().PutAsync(new List<TimeSpan> { XmlConvert.ToTimeSpan("P123DT22H14M12.011S")});
var response = await new ArrayClient(host, null).GetDurationValueClient().PutAsync(new List<TimeSpan> { XmlConvert.ToTimeSpan("P123DT22H14M12.011S") });
Assert.AreEqual(204, response.Status);
});

Expand All @@ -138,8 +136,9 @@ public Task Type_Array_UnknownValue_put() => Test(async (host) =>
public Task Type_Array_ModelValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetModelValueClient().GetModelValueAsync();
Assert.AreEqual("hello", response.Value.First().Property);
Assert.AreEqual("world", response.Value.Last().Property);
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual("hello", response.Value[0].Property);
Assert.AreEqual("world", response.Value[1].Property);
});

[Test]
Expand All @@ -153,10 +152,7 @@ public Task Type_Array_ModelValue_put() => Test(async (host) =>
public Task Type_Array_NullableFloatValue_get() => Test(async (host) =>
{
var response = await new ArrayClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync();
var result = response.Value.ToList();
Assert.AreEqual(1.25f, result[0]);
Assert.AreEqual(null, result[1]);
Assert.AreEqual(3.0f, result[2]);
CollectionAssert.AreEqual(new float?[] { 1.25f, null, 3.0f }, response.Value);
});

[Test]
Expand Down
11 changes: 11 additions & 0 deletions test/CadlRanchProjects.Tests/type-dictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class TypeDictionaryTests : CadlRanchTestBase
public Task Dictionary_Int32Value_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetInt32ValueClient().GetInt32ValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual(1, response.Value["k1"]);
Assert.AreEqual(2, response.Value["k2"]);
});
Expand All @@ -35,6 +36,7 @@ public Task Dictionary_Int32Value_put() => Test(async (host) =>
public Task Dictionary_Int64Value_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetInt64ValueClient().GetInt64ValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual(9007199254740991, response.Value["k1"]);
Assert.AreEqual(-9007199254740991, response.Value["k2"]);
});
Expand All @@ -54,6 +56,7 @@ public Task Dictionary_Int64Value_put() => Test(async (host) =>
public Task Dictionary_BooleanValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetBooleanValueClient().GetBooleanValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual(true, response.Value["k1"]);
Assert.AreEqual(false, response.Value["k2"]);
});
Expand All @@ -73,6 +76,7 @@ public Task Dictionary_BooleanValue_put() => Test(async (host) =>
public Task Dictionary_StringValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetStringValueClient().GetStringValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual("hello", response.Value["k1"]);
Assert.AreEqual("", response.Value["k2"]);
});
Expand All @@ -92,6 +96,7 @@ public Task Dictionary_StringValue_put() => Test(async (host) =>
public Task Dictionary_Float32Value_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync();
Assert.AreEqual(1, response.Value.Count);
Assert.AreEqual(43.125f, response.Value["k1"]);
});

Expand All @@ -109,6 +114,7 @@ public Task Dictionary_Float32Value_put() => Test(async (host) =>
public Task Dictionary_DatetimeValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync();
Assert.AreEqual(1, response.Value.Count);
Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value["k1"]);
});

Expand All @@ -126,6 +132,7 @@ public Task Dictionary_DatetimeValue_put() => Test(async (host) =>
public Task Dictionary_DurationValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetDurationValueClient().GetDurationValueAsync();
Assert.AreEqual(1, response.Value.Count);
Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value["k1"]);
});

Expand All @@ -143,6 +150,7 @@ public Task Dictionary_DurationValue_put() => Test(async (host) =>
public Task Dictionary_UnknownValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetUnknownValueClient().GetUnknownValueAsync();
Assert.AreEqual(3, response.Value.Count);
Assert.AreEqual(1, response.Value["k1"].ToObjectFromJson());
Assert.AreEqual("hello", response.Value["k2"].ToObjectFromJson());
Assert.AreEqual(null, response.Value["k3"]);
Expand All @@ -164,6 +172,7 @@ public Task Dictionary_UnknownValue_put() => Test(async (host) =>
public Task Dictionary_ModelValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetModelValueClient().GetModelValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual("hello", response.Value["k1"].Property);
Assert.AreEqual("world", response.Value["k2"].Property);
});
Expand All @@ -183,6 +192,7 @@ public Task Dictionary_ModelValue_put() => Test(async (host) =>
public Task Dictionary_RecursiveModelValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetRecursiveModelValueClient().GetRecursiveModelValueAsync();
Assert.AreEqual(2, response.Value.Count);
Assert.AreEqual("hello", response.Value["k1"].Property);
Assert.AreEqual(0, response.Value["k1"].Children.Count);
Assert.AreEqual("world", response.Value["k2"].Property);
Expand Down Expand Up @@ -212,6 +222,7 @@ public Task Dictionary_RecursiveModelValue_put() => Test(async (host) =>
public Task Type_Dictionary_NullableFloatValue_get() => Test(async (host) =>
{
var response = await new DictionaryClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync();
Assert.AreEqual(3, response.Value.Count);
Assert.AreEqual(1.25f, response.Value["k1"]);
Assert.AreEqual(0.5f, response.Value["k2"]);
Assert.AreEqual(null, response.Value["k3"]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CadlRanchProjectsNonAzure.Tests
{
public class AuthenticationHttpCustomTests: CadlRanchNonAzureTestBase
public class AuthenticationHttpCustomTests : CadlRanchNonAzureTestBase
{
[Test]
public Task Authentication_Http_Custom_valid() => Test(async (host) =>
Expand Down
Loading