Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2ca81d9
move mgmt test classes into mgmt
ArcturusZhang Oct 10, 2024
2c3d949
some in progress changes
ArcturusZhang Oct 11, 2024
30fe506
wip, now the new provider could generate those methods
ArcturusZhang Oct 11, 2024
1553bc9
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 11, 2024
066cd2d
follow up
ArcturusZhang Oct 11, 2024
3a03f71
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 14, 2024
6f25ddb
a few progress on creating id for a resource
ArcturusZhang Oct 14, 2024
d0d5df2
a few update
ArcturusZhang Oct 14, 2024
d209e5a
add get resource statement
ArcturusZhang Oct 14, 2024
1ac3fe2
add implementation for normal operations
ArcturusZhang Oct 16, 2024
36685a3
implmeent some bodies
ArcturusZhang Oct 16, 2024
834618d
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 16, 2024
ad43b46
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
403e9ab
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
77d3ebf
some more progress
ArcturusZhang Oct 17, 2024
ce40019
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 21, 2024
64824ce
fix the scope issue
ArcturusZhang Oct 21, 2024
33bfeca
fix another scope path issue
ArcturusZhang Oct 21, 2024
f88e7c1
enable generation for collections
ArcturusZhang Oct 21, 2024
e0efd6e
implement part of the resource collection methods
ArcturusZhang Oct 21, 2024
fdeb1b0
fix inline parameter issue
ArcturusZhang Oct 21, 2024
ee9c3d8
some updates with issues
ArcturusZhang Oct 21, 2024
123c66c
fix the scope issue
ArcturusZhang Oct 22, 2024
12efc8e
fix isuses in mgmttestconfiguration
ArcturusZhang Oct 23, 2024
f1273f0
fix casing and empty lines
ArcturusZhang Oct 23, 2024
4576226
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
9cfffd1
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
48f7f2f
honor the skipped operation config
ArcturusZhang Oct 31, 2024
3894a9b
regen
ArcturusZhang Nov 4, 2024
2cf792d
regen
ArcturusZhang Nov 4, 2024
2931a53
implement the extension operation samples
ArcturusZhang Nov 4, 2024
010f4cf
implement the property bag part 1
ArcturusZhang Nov 5, 2024
8468e13
implement the property bag part 2
ArcturusZhang Nov 5, 2024
600b4d0
remove the configureawait part
ArcturusZhang Nov 5, 2024
d1d9e0d
fix the null value issue in code model converter
ArcturusZhang Nov 5, 2024
e65f290
fix a case in resourcemanager
ArcturusZhang Nov 5, 2024
f5c2441
fix some issues found in real rps
ArcturusZhang Nov 5, 2024
e17b225
find another case that has configureawait
ArcturusZhang Nov 5, 2024
7936159
remove useless code
ArcturusZhang Nov 5, 2024
7461fff
more removals
ArcturusZhang Nov 5, 2024
c032d67
adjust namespaces
ArcturusZhang Nov 5, 2024
441dde0
clean up
ArcturusZhang Nov 5, 2024
c323542
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 6, 2024
c5704f9
refactor
ArcturusZhang Nov 6, 2024
fbf2968
more refactor
ArcturusZhang Nov 6, 2024
bf49918
regen
ArcturusZhang Nov 6, 2024
ad7549e
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 11, 2024
9d7e62c
fix some more issues
ArcturusZhang Nov 11, 2024
97762f3
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 12, 2024
855d575
fix userassignedidentity
ArcturusZhang Nov 12, 2024
8180473
add some notes
ArcturusZhang Nov 12, 2024
5027003
fix the optional parameter issue and regen
ArcturusZhang Nov 13, 2024
f1210ae
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 13, 2024
9ce9211
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 15, 2024
75098c2
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 21, 2024
c36dc84
fix the armclient issue
ArcturusZhang Nov 21, 2024
642a3bd
fix some minor issues in code
ArcturusZhang Nov 21, 2024
0754dde
regen
ArcturusZhang Nov 21, 2024
0e8aac7
resolve comments
ArcturusZhang Nov 22, 2024
f861682
refine
ArcturusZhang Nov 22, 2024
1f13f5b
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 25, 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
Prev Previous commit
Next Next commit
wip, now the new provider could generate those methods
  • Loading branch information
ArcturusZhang committed Oct 11, 2024
commit 30fe506e9b5fabfd5a76b94c20002eae6c3758d4
25 changes: 16 additions & 9 deletions src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project)
AddGeneratedFile(project, $"{modelFactoryProvider.Type.Name}.cs", modelFactoryWriter.ToString());
}

// TODO: fix the overriden
//if (_overriddenProjectFilenames.TryGetValue(project, out var overriddenFilenames))
// throw new InvalidOperationException($"At least one file was overridden during the generation process. Filenames are: {string.Join(", ", overriddenFilenames)}");

var modelsToKeep = Configuration.MgmtConfiguration.KeepOrphanedModels.ToImmutableHashSet();
await project.PostProcessAsync(new MgmtPostProcessor(modelsToKeep, modelFactoryProvider?.FullName));

// write samples if enabled
if (Configuration.MgmtTestConfiguration?.Sample ?? Configuration.GenerateSampleProject)
{
Expand All @@ -239,16 +246,9 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project)
{
var sampleWriter = new CodeWriter();
new ExpressionTypeProviderWriter(sampleWriter, sampleProvider).Write();
AddGeneratedFile(project, Path.Combine(sampleOutputFolder, $"Samples/{sampleProvider.Type.Name}.cs"), sampleWriter.ToString());
project.AddGeneratedTestFile(Path.Combine(sampleOutputFolder, $"Samples/{sampleProvider.Type.Name}.cs"), sampleWriter.ToString());
}
}

// TODO: fix the overriden
//if (_overriddenProjectFilenames.TryGetValue(project, out var overriddenFilenames))
// throw new InvalidOperationException($"At least one file was overridden during the generation process. Filenames are: {string.Join(", ", overriddenFilenames)}");

var modelsToKeep = Configuration.MgmtConfiguration.KeepOrphanedModels.ToImmutableHashSet();
await project.PostProcessAsync(new MgmtPostProcessor(modelsToKeep, modelFactoryProvider?.FullName));
}

private static void WriteExtensions(GeneratedCodeWorkspace project, bool isArmCore, MgmtExtensionWrapper extensionWrapper, IEnumerable<MgmtExtension> extensions, IEnumerable<MgmtMockableExtension> mockableExtensions)
Expand Down Expand Up @@ -324,7 +324,7 @@ private static string GetSampleOutputFolder(string defaultOutputPath)
if (!string.IsNullOrEmpty(Configuration.MgmtTestConfiguration?.OutputFolder))
return Configuration.MgmtTestConfiguration.OutputFolder;

string folder = Configuration.OutputFolder;
string folder = FormatPath(Configuration.OutputFolder);
// if the output folder is not given explicitly, try to figure it out from general output folder if possible according to default folder structure:
// Azure.ResourceManager.XXX \ src \ Generated <- default sdk source output folder
// \ samples(or tests) \ Generated <- default sample output folder defined in msbuild
Expand All @@ -335,5 +335,12 @@ private static string GetSampleOutputFolder(string defaultOutputPath)
else
throw new InvalidOperationException("'sample-gen.output-folder' is not configured and can't figure it out from give general output-folder");
}

private static string FormatPath(string? path)
{
if (string.IsNullOrEmpty(path))
return path ?? "";
return Path.GetFullPath(path.TrimEnd('/', '\\')).Replace("\\", "/");
}
}
}
17 changes: 13 additions & 4 deletions src/AutoRest.CSharp/Mgmt/Output/Samples/NewMgmtSampleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
using System.Linq;
using AutoRest.CSharp.Common.Output.Models;
using AutoRest.CSharp.Input.Source;
using AutoRest.CSharp.MgmtTest.Models;
using AutoRest.CSharp.Output.Models;
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Output.Models.Types;
using NUnit.Framework;
using static AutoRest.CSharp.Common.Output.Models.Snippets;

namespace AutoRest.CSharp.Mgmt.Output.Samples
{
Expand All @@ -25,14 +29,19 @@ public NewMgmtSampleProvider(string defaultNamespace, MgmtTypeProvider client, S

protected override string DefaultName { get; }

//private Method BuildSampleMethod(MgmtOperationSample sample, bool isAsync)
//{
private Method BuildSampleMethod(MgmtOperationSample sample, bool isAsync)
{
var signature = sample.GetMethodSignature(false);

//}
return new Method(signature, EmptyStatement);
}

protected override IEnumerable<Method> BuildMethods()
{
return base.BuildMethods();
foreach (var sample in _client.AllOperations.SelectMany(o => o.Samples))
{
yield return BuildSampleMethod(sample, true);
}
}
}
}
7 changes: 6 additions & 1 deletion src/AutoRest.CSharp/MgmtTest/Models/MgmtOperationSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Utilities;
using Azure;
using NUnit.Framework;
using MappingObject = System.Collections.Generic.Dictionary<string, AutoRest.CSharp.MgmtTest.Models.ExampleParameterValue>;
using static AutoRest.CSharp.Common.Output.Models.Snippets;

namespace AutoRest.CSharp.MgmtTest.Models
{
Expand All @@ -36,7 +38,10 @@ public MgmtOperationSample(string operationId, MgmtTypeProvider carrier, MgmtCli
Modifiers: MethodSignatureModifiers.Public | MethodSignatureModifiers.Async,
ReturnType: typeof(Task),
ReturnDescription: null,
Parameters: Array.Empty<Parameter>());
Parameters: [],
Attributes: _attributes);

private readonly CSharpAttribute[] _attributes = [new CSharpAttribute(typeof(TestAttribute)), new CSharpAttribute(typeof(IgnoreAttribute), Literal("Only validating compilation of examples"))];

private MgmtTypeProvider? _parent;
public MgmtTypeProvider? Parent => _parent ??= GetParent();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,41 @@

#nullable disable

using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using MgmtTypeSpec.Models;
using NUnit.Framework;

namespace MgmtTypeSpec.Samples
{
public partial class Sample_FooResource
{
// Create a foo
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Update_CreateAFoo()
[Test]
[Ignore("Only validating compilation of examples")]
public async Task Get_GetAFoo()
{
// Generated from example definition: 2024-05-01/Foos_CreateOrUpdate.json
// this example is just showing the usage of "Foos_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);

// this example assumes you already have this FooResource created on azure
// for more information of creating FooResource, please refer to the document of FooResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "myRg";
string fooName = "myFoo";
ResourceIdentifier fooResourceId = FooResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, fooName);
FooResource foo = client.GetFooResource(fooResourceId);

// invoke the operation
FooData data = new FooData(new AzureLocation("placeholder"))
{
Properties = new FooProperties()
{
ServiceUri = new Uri("https://myService.com"),
Something = "for test only",
BoolValue = true,
FloatValue = 1.2F,
DoubleValue = 1.2,
},
};
ArmOperation<FooResource> lro = await foo.UpdateAsync(WaitUntil.Completed, data);
FooResource result = lro.Value;

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
FooData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
}

// Get a foo
[NUnit.Framework.Test]
[NUnit.Framework.Ignore("Only verifying that the sample builds")]
public async Task Get_GetAFoo()
[Test]
[Ignore("Only validating compilation of examples")]
public async Task Update_CreateAFoo()
{
// Generated from example definition: 2024-05-01/Foos_Get.json
// this example is just showing the usage of "Foos_Get" operation, for the dependent resources, they will have to be created separately.

// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
}

// this example assumes you already have this FooResource created on azure
// for more information of creating FooResource, please refer to the document of FooResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "myRg";
string fooName = "myFoo";
ResourceIdentifier fooResourceId = FooResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, fooName);
FooResource foo = client.GetFooResource(fooResourceId);
[Test]
[Ignore("Only validating compilation of examples")]
public async Task AddTag_GetAFoo()
{
}

// invoke the operation
FooResource result = await foo.GetAsync();
[Test]
[Ignore("Only validating compilation of examples")]
public async Task SetTags_GetAFoo()
{
}

// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
FooData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
[Test]
[Ignore("Only validating compilation of examples")]
public async Task RemoveTag_GetAFoo()
{
}
}
}
Loading