Skip to content

Commit

Permalink
Add Client Example Test And Fix ResourceManager Resource Test (#5153)
Browse files Browse the repository at this point in the history
* generate

* regen

* update

* Update resource-manager-resources.cs

* update
  • Loading branch information
mcgallan authored Nov 11, 2024
1 parent 8f0efb7 commit 8513f93
Show file tree
Hide file tree
Showing 30 changed files with 3,308 additions and 22 deletions.
1 change: 1 addition & 0 deletions eng/testProjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"azure/client-generator-core/access",
"azure/client-generator-core/flatten-property",
"azure/client-generator-core/usage",
"azure/example/basic",
"azure/resource-manager/common-properties",
"azure/special-headers/client-request-id",
"encode/bytes",
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 @@ -652,6 +652,10 @@
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\core\\traits\\src\\Generated -n"
},
"typespec-azure/example/basic": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\example\\basic\\src\\Generated -n"
},
"typespec-azure/resource-manager/common-properties": {
"commandName": "Project",
"commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\azure\\resource-manager\\common-properties\\src\\Generated -n"
Expand Down
38 changes: 38 additions & 0 deletions test/CadlRanchProjects.Tests/azure-example-client-basic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading.Tasks;
using _Specs_.Azure.Core.Page;
using _Specs_.Azure.Example.Basic;
using _Specs_.Azure.Example.Basic.Models;
using AutoRest.TestServer.Tests.Infrastructure;
using NUnit.Framework;

namespace CadlRanchProjects.Tests
{
public class azure_example_client_basic : CadlRanchTestBase
{
[Test]
public Task Azure_Example_Client_BasicAction() => Test(async (host) =>
{
var request = new ActionRequest("text")
{
ModelProperty = new Model()
{
EnumProperty = _Specs_.Azure.Example.Basic.Models.Enum.EnumValue1,
Int32Property = 1,
Float32Property = 1.5f,
},
ArrayProperty =
{
"item"
},
RecordProperty =
{
{ "record", "value" }
}
};
var response = await new AzureExampleClient(host, null).BasicActionAsync("query", "header", request);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual("text", response.Value.StringProperty);
});
}
}
55 changes: 33 additions & 22 deletions test/CadlRanchProjects.Tests/resource-manager-resources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,24 @@ public Task Azure_ResourceManager_Resources_TopLevelTrackedResources_delete() =>
public Task Azure_ResourceManager_Resources_TopLevelTrackedResources_listByResourceGroup() => Test(async (host) =>
{
var id = ResourceGroupResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg");
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetResourceGroupResource(id).GetTopLevelTrackedResourceAsync("top");
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(true, response.Value.HasData);
Assert.AreEqual("top", response.Value.Data.Name);
Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources", response.Value.Data.ResourceType.ToString());
Assert.AreEqual(AzureLocation.EastUS, response.Value.Data.Location);
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);
var resourceGroup = MgmtTestHelper.CreateArmClientWithMockAuth(host).GetResourceGroupResource(id);
var collection = resourceGroup.GetTopLevelTrackedResources();
int count = 0;
await foreach (var resource in collection.GetAllAsync())
{
count++;
Assert.AreEqual(true, resource.HasData);
Assert.AreEqual("top", resource.Data.Name);
Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources", resource.Data.ResourceType.ToString());
Assert.AreEqual(AzureLocation.EastUS, resource.Data.Location);
Assert.AreEqual("valid", resource.Data.Properties.Description);
Assert.AreEqual(ProvisioningState.Succeeded, resource.Data.Properties.ProvisioningState);
Assert.AreEqual("AzureSDK", resource.Data.SystemData.CreatedBy);
Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.CreatedByType);
Assert.AreEqual("AzureSDK", resource.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.LastModifiedByType);
}
Assert.AreEqual(1, count);
});

[Test]
Expand Down Expand Up @@ -213,16 +219,21 @@ public Task Azure_ResourceManager_Resources_NestedProxyResources_delete() => Tes
public Task Azure_ResourceManager_Resources_NestedProxyResources_listByTopLevelTrackedResource() => Test(async (host) =>
{
var id = TopLevelTrackedResource.CreateResourceIdentifier(Guid.Empty.ToString(), "test-rg", "top");
var response = await MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).GetNestedProxyResourceAsync("nested");
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual(true, response.Value.HasData);
Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources", 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);
var collection = MgmtTestHelper.CreateArmClientWithMockAuth(host).GetTopLevelTrackedResource(id).GetNestedProxyResources();
int count = 0;
await foreach (var resource in collection.GetAllAsync())
{
count++;
Assert.AreEqual(true, resource.HasData);
Assert.AreEqual("Azure.ResourceManager.Resources/topLevelTrackedResources/top/nestedProxyResources", resource.Data.ResourceType.ToString());
Assert.AreEqual("valid", resource.Data.Properties.Description);
Assert.AreEqual(ProvisioningState.Succeeded, resource.Data.Properties.ProvisioningState);
Assert.AreEqual("AzureSDK", resource.Data.SystemData.CreatedBy);
Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.CreatedByType);
Assert.AreEqual("AzureSDK", resource.Data.SystemData.LastModifiedBy);
Assert.AreEqual(CreatedByType.User, resource.Data.SystemData.LastModifiedByType);
}
Assert.AreEqual(1, count);
});

[Test]
Expand Down
12 changes: 12 additions & 0 deletions test/CadlRanchProjects/azure/example/basic/Configuration.json

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

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}") = "_Specs_.Azure.Example.Basic", "src\_Specs_.Azure.Example.Basic.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "_Specs_.Azure.Example.Basic.Tests", "tests\_Specs_.Azure.Example.Basic.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
Loading

0 comments on commit 8513f93

Please sign in to comment.