Skip to content

Commit

Permalink
Add Cadl Ranch Test In New Version 0.37.2 (#5065)
Browse files Browse the repository at this point in the history
* generate

* update

* Update azure-tcgc-usage.cs

* rpc generate

* Update rpc.cs

* regen

* basic

* regen

* remove

* update

* update

* Update resource-manager-models-resources.cs

* regen

* Numeric Test

* ConditionalRequest Test

* Update package-lock.json

* update

* Update testProjects.json
  • Loading branch information
mcgallan authored Sep 26, 2024
1 parent 22992df commit 83ef6a0
Show file tree
Hide file tree
Showing 31 changed files with 3,509 additions and 0 deletions.
1 change: 1 addition & 0 deletions eng/testProjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"encode/bytes",
"encode/datetime",
"encode/duration",
"encode/numeric",
"payload/content-negotiation",
"payload/media-type",
"payload/multipart",
Expand Down
4 changes: 4 additions & 0 deletions src/AutoRest.CSharp/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\encode\\duration\\src\\Generated -n"
},
"typespec-encode/numeric": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\encode\\numeric\\src\\Generated -n"
},
"typespec-nonAzure-authentication/api-key": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\api-key\\src\\Generated -n"
Expand Down
11 changes: 11 additions & 0 deletions test/CadlRanchProjects.Tests/azure-core-basic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ public Task Azure_Core_Basic_export() => Test(async (host) =>
Assert.AreEqual("Madge", response.Name);
});

[Test]
public Task Azure_Core_Basic_exoportAllUsers() => Test(async (host) =>
{
var response = await new BasicClient(host, null).ExportAllUsersAsync("json");
Assert.AreEqual(1, response.Value.Users.First().Id);
Assert.AreEqual("Madge", response.Value.Users.First().Name);
Assert.AreEqual(2, response.Value.Users.Last().Id);
Assert.AreEqual("John", response.Value.Users.Last().Name);
Assert.AreEqual(2, response.Value.Users.Count());
});

[Test]
public void Azure_Core_basic_RenameGetMethod()
{
Expand Down
6 changes: 6 additions & 0 deletions test/CadlRanchProjects.Tests/azure-tcgc-usage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ public Task Azure_ClientGenerator_Core_Usage_ModelInOperation() => Test(async (h
var response2 = await new UsageClient(host, null).GetModelInOperationClient().OutputToInputOutputAsync();
Assert.AreEqual("Madge", response2.Value.Name);
var response3 = await new UsageClient(host, null).GetModelInOperationClient().ModelInReadOnlyPropertyAsync(new RoundTripModel());
Assert.AreEqual("Madge", response3.Value.Result.Name);
Assert.IsNotNull(typeof(InputModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(InputModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(OutputModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(OutputModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(RoundTripModel).GetMethod("FromResponse", BindingFlags.Static | BindingFlags.NonPublic));
Assert.IsNotNull(typeof(RoundTripModel).GetMethod("ToRequestContent", BindingFlags.Instance | BindingFlags.NonPublic));
});
}
}
43 changes: 43 additions & 0 deletions test/CadlRanchProjects.Tests/encode-numeric.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Text.Json;
using System.Threading.Tasks;
using AutoRest.TestServer.Tests.Infrastructure;
using Azure;
using Azure.Core;
using Encode.Numeric;
using Encode.Numeric.Models;
using NUnit.Framework;


namespace CadlRanchProjects.Tests
{
public class encode_numeric : CadlRanchTestBase
{
[Test]
public Task Encode_Numeric_Property_safeintAsString() => Test(async (host) =>
{
var response = await new NumericClient(host, null).GetPropertyClient().SafeintAsStringAsync(new SafeintAsStringProperty(10000000000));
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(10000000000, response.Value.Value);
});

[Test]
public Task Encode_Numeric_Property_uint32AsStringOptional() => Test(async (host) =>
{
var response = await new NumericClient(host, null).GetPropertyClient().Uint32AsStringOptionalAsync(new Uint32AsStringProperty()
{
Value = "1"
});
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual("1", response.Value.Value);
});

[Test]
public Task Encode_Numeric_Property_uint8AsString() => Test(async (host) =>
{
var response = await new NumericClient(host, null).GetPropertyClient().Uint8AsStringAsync(new Uint8AsStringProperty(255));
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(255, response.Value.Value);
});
}
}
72 changes: 72 additions & 0 deletions test/CadlRanchProjects.Tests/resource-manager-models-resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_get(
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});

[Test]
public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_actionSync() => Test(async (host) =>
{
var id = TopLevelTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg", "top");
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).ActionSyncAsync(new NotificationDetails("Resource action at top level.", true));
Assert.AreEqual(204, response.Status);
});

[Test]
[Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
public Task Azure_ResourceManager_Models_Resources_TopLevelTrackedResources_createOrReplace() => Test(async (host) =>
Expand Down Expand Up @@ -218,5 +226,69 @@ public Task Azure_ResourceManager_Models_Resources_NestedProxyResources_listByTo
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});

[Test]
[Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_createOrUpdate() => Test(async (host) =>
{
var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
var data = new SingletonTrackedResourceData(AzureLocation.EastUS)
{
Properties = new SingletonTrackedResourceProperties()
{
Description = "valid"
}
};
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).CreateOrUpdateAsync(WaitUntil.Completed, data);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(true, response.Value.HasData);
Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", response.Value.Data.ResourceType.ToString());
Assert.AreEqual("valid", response.Value.Data.Properties.Description);
Assert.AreEqual(ProvisioningState.Succeeded, response.Value.Data.Properties.ProvisioningState);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.CreatedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.CreatedByType);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});

[Test]
[Ignore("https://github.com/Azure/autorest.csharp/issues/4876")]
public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_update() => Test(async (host) =>
{
var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
var data = new SingletonTrackedResourceData(AzureLocation.EastUS2)
{
Properties = new SingletonTrackedResourceProperties()
{
Description = "valid2"
}
};
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).UpdateAsync(data);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(true, response.Value.HasData);
Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", response.Value.Data.ResourceType.ToString());
Assert.AreEqual("valid2", response.Value.Data.Properties.Description);
Assert.AreEqual(ProvisioningState.Succeeded, response.Value.Data.Properties.ProvisioningState);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.CreatedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.CreatedByType);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});

[Test]
public Task Azure_ResourceManager_Models_Resources_SingletonTrackedResource_getByResourceGroup() => Test(async (host) =>
{
var id = SingletonTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetSingletonTrackedResource(id).GetAsync();
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(true, response.Value.HasData);
Assert.AreEqual("Azure.ResourceManager.Models.Resources/singletonTrackedResources", response.Value.Data.ResourceType.ToString());
Assert.AreEqual("valid", response.Value.Data.Properties.Description);
Assert.AreEqual(ProvisioningState.Succeeded, response.Value.Data.Properties.ProvisioningState);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.CreatedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.CreatedByType);
Assert.AreEqual("AzureSDK", response.Value.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, response.Value.Data.SystemData.LastModifiedByType);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using NUnit.Framework;
using System.Threading.Tasks;
using SpecialHeaders.ConditionalRequest;
using System;

namespace CadlRanchProjects.Tests
{
Expand All @@ -22,5 +23,26 @@ public Task Special_Headers_Conditional_Request_PostIfNoneMatch() => Test(async
Response response = await new ConditionalRequestClient(host, null).PostIfNoneMatchAsync(ifNoneMatch);
Assert.AreEqual(204, response.Status);
});

[Test]
public Task Special_Headers_Conditional_Request_HeadIfModifiedSince() => Test(async (host) =>
{
DateTimeOffset ifModifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
Response response = await new ConditionalRequestClient(host, null).HeadIfModifiedSinceAsync(new RequestConditions()
{
IfModifiedSince = ifModifiedSince
});
Assert.AreEqual(204, response.Status);
});
[Test]
public Task Special_Headers_Conditional_Request_PostIfUnmodifiedSince() => Test(async (host) =>
{
DateTimeOffset ifUnmodifiedSince = DateTimeOffset.Parse("Fri, 26 Aug 2022 14:38:00 GMT");
Response response = await new ConditionalRequestClient(host, null).PostIfUnmodifiedSinceAsync(new RequestConditions()
{
IfUnmodifiedSince = ifUnmodifiedSince
});
Assert.AreEqual(204, response.Status);
});
}
}
11 changes: 11 additions & 0 deletions test/CadlRanchProjects/encode/numeric/Configuration.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions test/CadlRanchProjects/encode/numeric/Encode.Numeric.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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}") = "Encode.Numeric", "src\Encode.Numeric.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encode.Numeric.Tests", "tests\Encode.Numeric.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}"
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
19 changes: 19 additions & 0 deletions test/CadlRanchProjects/encode/numeric/src/Encode.Numeric.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Encode.Numeric client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>Azure SDK Code Generation Encode.Numeric for Azure Data Plane</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Encode.Numeric</PackageTags>
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<IncludeOperationsSharedSource>true</IncludeOperationsSharedSource>
</PropertyGroup>

<ItemGroup>
<Compile Include="$(AzureCoreSharedSources)AzureResourceProviderNamespaceAttribute.cs" LinkBase="Shared/Core" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>
</Project>
Loading

0 comments on commit 83ef6a0

Please sign in to comment.