-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopt http\type\property\nullable from cadl ranch (#4249)
fixes: #4008
- Loading branch information
1 parent
23d0015
commit 4196cd3
Showing
36 changed files
with
3,926 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
261 changes: 261 additions & 0 deletions
261
...harp/generator/TestProjects/CadlRanch.Tests/Http/_Type/Property/Nullable/NullableTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using _Type.Property.Nullable; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
using AutoRest.TestServer.Tests.Infrastructure; | ||
using System; | ||
using System.Xml; | ||
using System.ClientModel; | ||
using System.Linq; | ||
|
||
namespace TestProjects.CadlRanch.Tests.Http._Type.Property.Nullable | ||
{ | ||
internal class NullableTests : CadlRanchTestBase | ||
{ | ||
[CadlRanchTest] | ||
public Task StringGetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetStringClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.AreEqual("hello", response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task StringGetNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetStringClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task StringPatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
nullableProperty = "hello" | ||
}; | ||
var response = await new NullableClient(host, null).GetStringClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task StringPatchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetStringClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task BytesGetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetBytesClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
BinaryDataAssert.AreEqual(BinaryData.FromString("hello, world!"), response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task BytesGetNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetBytesClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task BytesPatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
// cspell: disable-next-line | ||
nullableProperty = "aGVsbG8sIHdvcmxkIQ==" | ||
}; | ||
var response = await new NullableClient(host, null).GetBytesClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task BytesPatchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetBytesClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DatetimeTetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetDatetimeClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DatetimeGetNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetDatetimeClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DatetimePatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
nullableProperty = DateTimeOffset.Parse("2022-08-26T18:38:00Z") | ||
}; | ||
var response = await new NullableClient(host, null).GetDatetimeClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task Datetime_patchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetDatetimeClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DurationGetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetDurationClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task Type_Property_Nullable_Duration_getNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetDurationClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DurationPatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
nullableProperty = "P123DT22H14M12.011S" | ||
}; | ||
var response = await new NullableClient(host, null).GetDurationClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task DurationPatchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetDurationClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsByteGetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetCollectionsByteClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.AreEqual(2, response.Value.NullableProperty.Count); | ||
BinaryDataAssert.AreEqual(BinaryData.FromString("hello, world!"), response.Value.NullableProperty.First()); | ||
BinaryDataAssert.AreEqual(BinaryData.FromString("hello, world!"), response.Value.NullableProperty.Last()); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsByteGetNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetCollectionsByteClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNotNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsBytePatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
// cspell: disable-next-line | ||
nullableProperty = new[] { "aGVsbG8sIHdvcmxkIQ==", "aGVsbG8sIHdvcmxkIQ==" } | ||
}; | ||
var response = await new NullableClient(host, null).GetCollectionsByteClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsBytePatchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetCollectionsByteClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsModelGetNonNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetCollectionsModelClient().GetNonNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.AreEqual(2, response.Value.NullableProperty.Count); | ||
Assert.AreEqual("hello", response.Value.NullableProperty.First().Property); | ||
Assert.AreEqual("world", response.Value.NullableProperty.Last().Property); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsModelGetNull() => Test(async (host) => | ||
{ | ||
var response = await new NullableClient(host, null).GetCollectionsModelClient().GetNullAsync(); | ||
Assert.AreEqual(200, response.GetRawResponse().Status); | ||
Assert.AreEqual("foo", response.Value.RequiredProperty); | ||
Assert.IsNotNull(response.Value.NullableProperty); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsModelPatchNonNull() => Test(async (host) => | ||
{ | ||
var value = new | ||
{ | ||
requiredProperty = "foo", | ||
nullableProperty = new[] | ||
{ | ||
new | ||
{ | ||
property = "hello" | ||
}, | ||
new | ||
{ | ||
property = "world" | ||
} | ||
} | ||
}; | ||
var response = await new NullableClient(host, null).GetCollectionsModelClient().PatchNonNullAsync(BinaryContent.Create(BinaryData.FromObjectAsJson(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
|
||
[CadlRanchTest] | ||
public Task CollectionsModelPatchNull() => Test(async (host) => | ||
{ | ||
string value = "{ \"requiredProperty\": \"foo\", \"nullableProperty\": null }"; | ||
var response = await new NullableClient(host, null).GetCollectionsModelClient().PatchNullAsync(BinaryContent.Create(BinaryData.FromString(value)), null); | ||
Assert.AreEqual(204, response.GetRawResponse().Status); | ||
}); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...nt-csharp/generator/TestProjects/CadlRanch/http/type/property/nullable/Configuration.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"output-folder": ".", | ||
"namespace": "Type.Property.Nullable", | ||
"library-name": "Type.Property.Nullable", | ||
"use-model-reader-writer": true | ||
} |
48 changes: 48 additions & 0 deletions
48
.../generator/TestProjects/CadlRanch/http/type/property/nullable/_Type.Property.Nullable.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29709.97 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Type.Property.Nullable", "src\_Type.Property.Nullable.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} | ||
EndGlobalSection | ||
EndGlobal |
Oops, something went wrong.