From 22992df3f718d90e963e7b72d1448099dcd78bf4 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Thu, 26 Sep 2024 10:33:02 +0800 Subject: [PATCH] remove all those related with mock (#5080) * remove all those related with mock * clean up the mock test generation * fix compilation issues * refactor * clean up * fix swagger mpg generation issue * remove invalid test cases * revert the generated code change --- .../Common/AutoRest/Plugins/CSharpGen.cs | 25 +- .../AutoRest/DataPlaneOutputLibrary.cs | 6 +- .../DataPlane/AutoRest/DataPlaneTarget.cs | 6 +- .../Output/Samples/DpgClientSampleProvider.cs | 2 - .../Mgmt/AutoRest/MgmtConfiguration.cs | 7 - .../AutoRest/MgmtTestConfiguration.cs | 7 - .../AutoRest/MgmtTestOutputLibrary.cs | 50 +-- .../MgmtTest/AutoRest/MgmtTestTarget.cs | 34 -- .../Mock/ExtensionMockTestWriter.cs | 36 -- .../Mock/ExtensionWrapMockTestWriter.cs | 32 -- .../Generation/Mock/MgmtMockTestBaseWriter.cs | 143 ------- .../Mock/ResourceCollectionMockTestWriter.cs | 78 ---- .../Generation/Mock/ResourceMockTestWriter.cs | 27 -- .../Generation/Samples/MgmtSampleWriter.cs | 2 +- .../MgmtTest/Models/MockTestCase.cs | 176 -------- .../MgmtTest/Models/OperationExample.cs | 6 +- src/AutoRest.CSharp/MgmtTest/Models/Sample.cs | 145 ++++++- .../Output/Mock/MgmtMockTestProvider.cs | 49 --- .../Output/Samples/MgmtSampleProvider.cs | 3 - .../TestProjects/MgmtMockAndSampleTests.cs | 79 ---- .../src/Generated/Configuration.json | 1 - .../DeletedManagedHsmCollectionMockTests.cs | 60 --- .../DeletedManagedHsmResourceMockTests.cs | 47 --- .../Mock/DeletedVaultResourceMockTests.cs | 37 -- .../DiskEncryptionSetCollectionMockTests.cs | 168 -------- .../DiskEncryptionSetResourceMockTests.cs | 126 ------ .../Mock/FirewallPolicyCollectionMockTests.cs | 299 ------------- .../Mock/FirewallPolicyResourceMockTests.cs | 283 ------------- ...yRuleCollectionGroupCollectionMockTests.cs | 398 ------------------ ...icyRuleCollectionGroupResourceMockTests.cs | 272 ------------ ...figurationAssignmentCollectionMockTests.cs | 88 ---- ...onfigurationAssignmentResourceMockTests.cs | 66 --- .../Mock/ManagedHsmCollectionMockTests.cs | 130 ------ .../Mock/ManagedHsmResourceMockTests.cs | 90 ---- .../MgmtMockAndSampleExtensionsMockTests.cs | 107 ----- ...teEndpointConnectionCollectionMockTests.cs | 93 ---- ...vateEndpointConnectionResourceMockTests.cs | 66 --- ...teEndpointConnectionCollectionMockTests.cs | 92 ---- ...vateEndpointConnectionResourceMockTests.cs | 65 --- .../Mock/RoleAssignmentCollectionMockTests.cs | 85 ---- .../Mock/RoleAssignmentResourceMockTests.cs | 74 ---- .../Mock/VaultCollectionMockTests.cs | 185 -------- .../Generated/Mock/VaultResourceMockTests.cs | 142 ------- ...achineExtensionImageCollectionMockTests.cs | 145 ------- ...lMachineExtensionImageResourceMockTests.cs | 46 -- 45 files changed, 162 insertions(+), 3916 deletions(-) delete mode 100644 src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionMockTestWriter.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionWrapMockTestWriter.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Generation/Mock/MgmtMockTestBaseWriter.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceCollectionMockTestWriter.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceMockTestWriter.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Models/MockTestCase.cs delete mode 100644 src/AutoRest.CSharp/MgmtTest/Output/Mock/MgmtMockTestProvider.cs delete mode 100644 test/AutoRest.TestServer.Tests/Mgmt/TestProjects/MgmtMockAndSampleTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedVaultResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSampleExtensionsMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultResourceMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageCollectionMockTests.cs delete mode 100644 test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageResourceMockTests.cs diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs index 5a006ffa697..0661338ae45 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs @@ -35,26 +35,17 @@ public async Task ExecuteAsync(CodeModel codeModel) if (Configuration.Generation1ConvenienceClient) { CodeModelTransformer.TransformForDataPlane(codeModel); - DataPlaneTarget.Execute(project, codeModel, sourceInputModel, schemaUsageProvider); + var inputNamespace = new CodeModelConverter(codeModel, schemaUsageProvider).CreateNamespace(); + DataPlaneTarget.Execute(project, inputNamespace, sourceInputModel); } else if (Configuration.AzureArm) { - if (Configuration.MgmtConfiguration.MgmtDebug.SkipCodeGen) - { - var inputNamespace = new CodeModelConverter(codeModel, schemaUsageProvider).CreateNamespace(); - await AutoRestLogger.Warning("skip generating sdk code because 'mgmt-debug.skip-codegen' is true."); - if (Configuration.MgmtTestConfiguration is not null) - await MgmtTestTarget.ExecuteAsync(project, inputNamespace, null); - } - else - { - CodeModelTransformer.TransformForMgmt(codeModel); - var inputNamespace = new CodeModelConverter(codeModel, schemaUsageProvider).CreateNamespace(); - MgmtContext.Initialize(new BuildContext(inputNamespace, sourceInputModel)); - await MgmtTarget.ExecuteAsync(project); - if (Configuration.MgmtTestConfiguration is not null && !Configuration.MgmtConfiguration.MgmtDebug.ReportOnly) - await MgmtTestTarget.ExecuteAsync(project, inputNamespace, sourceInputModel); - } + CodeModelTransformer.TransformForMgmt(codeModel); + var inputNamespace = new CodeModelConverter(codeModel, schemaUsageProvider).CreateNamespace(); + MgmtContext.Initialize(new BuildContext(inputNamespace, sourceInputModel)); + await MgmtTarget.ExecuteAsync(project); + if (Configuration.MgmtTestConfiguration is not null && !Configuration.MgmtConfiguration.MgmtDebug.ReportOnly) + await MgmtTestTarget.ExecuteAsync(project, inputNamespace, sourceInputModel); GenerateMgmtReport(project); } else diff --git a/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneOutputLibrary.cs b/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneOutputLibrary.cs index f9424fe8754..4874d5e2e66 100644 --- a/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneOutputLibrary.cs +++ b/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneOutputLibrary.cs @@ -5,12 +5,10 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using AutoRest.CSharp.Common.Decorator; using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Common.Output.Builders; using AutoRest.CSharp.Common.Output.Models; using AutoRest.CSharp.Generation.Types; -using AutoRest.CSharp.Input; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Output.Models.Requests; using AutoRest.CSharp.Output.Models.Responses; @@ -34,12 +32,12 @@ internal class DataPlaneOutputLibrary : OutputLibrary private readonly string _libraryName; private readonly TypeFactory _typeFactory; - public DataPlaneOutputLibrary(CodeModel codeModel, SourceInputModel? sourceInputModel, SchemaUsageProvider schemaUsageProvider) + public DataPlaneOutputLibrary(InputNamespace inputNamespace, SourceInputModel? sourceInputModel) { _typeFactory = new TypeFactory(this, typeof(object)); _sourceInputModel = sourceInputModel; - _input = new CodeModelConverter(codeModel, schemaUsageProvider).CreateNamespace(); + _input = inputNamespace; _libraryName = Configuration.LibraryName; diff --git a/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneTarget.cs b/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneTarget.cs index b87185990ce..78afc45a107 100644 --- a/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneTarget.cs +++ b/src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneTarget.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Input; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Output.Models.Responses; using AutoRest.CSharp.Output.Models.Types; @@ -11,9 +11,9 @@ namespace AutoRest.CSharp.AutoRest.Plugins { internal class DataPlaneTarget { - public static void Execute(GeneratedCodeWorkspace project, CodeModel codeModel, SourceInputModel? sourceInputModel, SchemaUsageProvider schemaUsageProvider) + public static void Execute(GeneratedCodeWorkspace project, InputNamespace inputNamespace, SourceInputModel? sourceInputModel) { - var library = new DataPlaneOutputLibrary(codeModel, sourceInputModel, schemaUsageProvider); + var library = new DataPlaneOutputLibrary(inputNamespace, sourceInputModel); var modelWriter = new ModelWriter(); var clientWriter = new DataPlaneClientWriter(); var restClientWriter = new RestClientWriter(); diff --git a/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgClientSampleProvider.cs b/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgClientSampleProvider.cs index 551097df391..68e32349a9e 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgClientSampleProvider.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/Samples/DpgClientSampleProvider.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Text; using System.Text.Json; @@ -13,7 +12,6 @@ using AutoRest.CSharp.Common.Output.Expressions.Statements; using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions; using AutoRest.CSharp.Common.Output.Models; -using AutoRest.CSharp.Generation.Types; using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Output.Models; using AutoRest.CSharp.Output.Models.Shared; diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs index dc6ab80f24d..e4f8a084dcd 100644 --- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs +++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs @@ -10,7 +10,6 @@ using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Mgmt.Models; using AutoRest.CSharp.Mgmt.Report; -using Microsoft.CodeAnalysis.CSharp; namespace AutoRest.CSharp.Input { @@ -24,8 +23,6 @@ public class MgmtDebugConfiguration public bool ShowSerializedNames { get; } - public bool SkipCodeGen { get; } - public bool GenerateReport { get; } public bool ReportOnly { get; } @@ -43,7 +40,6 @@ public MgmtDebugConfiguration( { SuppressListException = Configuration.DeserializeBoolean(suppressListException, false); ShowSerializedNames = Configuration.DeserializeBoolean(showSerializedNames, false); - SkipCodeGen = Configuration.DeserializeBoolean(skipCodeGen, false); GenerateReport = Configuration.DeserializeBoolean(generateReport, true); ReportOnly = Configuration.DeserializeBoolean(reportOnly, false); ReportFormat = Configuration.IsValidJsonElement(reportFormat) ? reportFormat?.GetString() ?? "yaml" : "yaml"; @@ -56,7 +52,6 @@ internal static MgmtDebugConfiguration LoadConfiguration(JsonElement root) root.TryGetProperty(nameof(SuppressListException), out var suppressListException); root.TryGetProperty(nameof(ShowSerializedNames), out var showSerializedNames); - root.TryGetProperty(nameof(SkipCodeGen), out var skipCodeGen); root.TryGetProperty(nameof(GenerateReport), out var generateReport); root.TryGetProperty(nameof(ReportOnly), out var reportOnly); root.TryGetProperty(nameof(ReportFormat), out var reportFormat); @@ -64,7 +59,6 @@ internal static MgmtDebugConfiguration LoadConfiguration(JsonElement root) return new MgmtDebugConfiguration( suppressListException: suppressListException, showSerializedNames: showSerializedNames, - skipCodeGen: skipCodeGen, generateReport: generateReport, reportOnly: reportOnly, reportFormat: reportFormat @@ -76,7 +70,6 @@ internal static MgmtDebugConfiguration GetConfiguration(IPluginCommunication aut return new MgmtDebugConfiguration( suppressListException: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "suppress-list-exception")).GetAwaiter().GetResult(), showSerializedNames: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "show-serialized-names")).GetAwaiter().GetResult(), - skipCodeGen: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "skip-codegen")).GetAwaiter().GetResult(), generateReport: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "generate-report")).GetAwaiter().GetResult(), reportOnly: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "report-only")).GetAwaiter().GetResult(), reportFormat: autoRest.GetValue(string.Format(MgmtDebugOptionsFormat, "report-format")).GetAwaiter().GetResult() diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs index d6d40972080..b07ad58ccc4 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs @@ -17,7 +17,6 @@ internal class MgmtTestConfiguration public string? SourceCodePath { get; } public string? OutputFolder { get; } - public bool Mock { get; } public bool Sample { get; } public IReadOnlyList SkippedOperations { get; } public bool ClearOutputFolder { get; } @@ -32,7 +31,6 @@ public MgmtTestConfiguration( { SkippedOperations = skippedOperations; SourceCodePath = !Configuration.IsValidJsonElement(sourceCodePath) ? null : sourceCodePath.ToString(); - Mock = Configuration.DeserializeBoolean(mock, false); Sample = Configuration.DeserializeBoolean(sample, true); OutputFolder = !Configuration.IsValidJsonElement(outputFolder) ? null : Configuration.TrimFileSuffix(outputFolder.ToString() ?? ""); ClearOutputFolder = Configuration.DeserializeBoolean(clearOutputFolder, false); @@ -47,7 +45,6 @@ public MgmtTestConfiguration( testGenRoot.TryGetProperty(nameof(SkippedOperations), out var skippedOperationsElement); testGenRoot.TryGetProperty(nameof(SourceCodePath), out var sourceCodePath); - testGenRoot.TryGetProperty(nameof(Mock), out var mock); testGenRoot.TryGetProperty(nameof(Sample), out var sample); testGenRoot.TryGetProperty(nameof(OutputFolder), out var testGenOutputFolder); testGenRoot.TryGetProperty(nameof(ClearOutputFolder), out var testGenClearOutputFolder); @@ -57,7 +54,6 @@ public MgmtTestConfiguration( return new MgmtTestConfiguration( skippedOperations, sourceCodePath: sourceCodePath, - mock: mock, sample: sample, outputFolder: testGenOutputFolder, clearOutputFolder: testGenClearOutputFolder); @@ -86,9 +82,6 @@ internal void SaveConfiguration(Utf8JsonWriter writer) if (SourceCodePath is not null) writer.WriteString(nameof(SourceCodePath), SourceCodePath); - if (Mock) - writer.WriteBoolean(nameof(Mock), Mock); - if (Sample) writer.WriteBoolean(nameof(Sample), Sample); diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs index f7d6cf52cc2..f07f79a2d0b 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs @@ -8,7 +8,6 @@ using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.Mgmt.Output; using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; using AutoRest.CSharp.MgmtTest.Output.Samples; using AutoRest.CSharp.Utilities; @@ -16,12 +15,12 @@ namespace AutoRest.CSharp.MgmtTest.AutoRest { internal class MgmtTestOutputLibrary { - private readonly InputNamespace _inputNamespace; + private readonly InputNamespace _input; private readonly HashSet _skippedOperations; public MgmtTestOutputLibrary(InputNamespace inputNamespace) { - _inputNamespace = inputNamespace; + _input = inputNamespace; _skippedOperations = new HashSet(Configuration.MgmtTestConfiguration?.SkippedOperations ?? []); } @@ -30,19 +29,8 @@ public MgmtTestOutputLibrary(InputNamespace inputNamespace) private IEnumerable EnsureSamples() { - foreach ((var owner, var cases) in MockTestCases) - { - yield return new MgmtSampleProvider(owner, cases.Select(testCase => new Sample(testCase))); - } - } - - private Dictionary>? _mockTestCases; - internal Dictionary> MockTestCases => _mockTestCases ??= EnsureMockTestCases(); - - private Dictionary> EnsureMockTestCases() - { - var result = new Dictionary>(); - foreach (var client in _inputNamespace.Clients) + var result = new Dictionary>(); + foreach (var client in _input.Clients) { foreach (var inputOperation in client.Operations) { @@ -62,14 +50,17 @@ private Dictionary> EnsureMockTestCases() // the source code generator will never write them if it is not in arm core if (providerForExample.Carrier is ArmClientExtension) continue; - var mockTestCase = new MockTestCase(operationId, providerForExample.Carrier, providerForExample.Operation, inputOperation, example); - result.AddInList(mockTestCase.Owner, mockTestCase); + var sample = new Sample(operationId, providerForExample.Carrier, providerForExample.Operation, inputOperation, example); + result.AddInList(sample.Owner, sample); } } } } - return result; + foreach ((var owner, var cases) in result) + { + yield return new MgmtSampleProvider(owner, cases); + } } private IEnumerable FindCarriersFromOperationId(string operationId) @@ -107,26 +98,5 @@ private Dictionary> EnsureOperationId return _operationNameToProviders; } - - private MgmtMockTestProvider? _extensionWrapperMockTest; - public MgmtMockTestProvider ExtensionWrapperMockTest => _extensionWrapperMockTest ??= new MgmtMockTestProvider(MgmtContext.Library.ExtensionWrapper, Enumerable.Empty()); - - private IEnumerable>? _extensionMockTests; - public IEnumerable> ExtensionMockTests => _extensionMockTests ??= EnsureMockTestProviders(); - - private IEnumerable>? _resourceCollectionMockTests; - public IEnumerable> ResourceCollectionMockTests => _resourceCollectionMockTests ??= EnsureMockTestProviders(); - - private IEnumerable>? _resourceMockTests; - public IEnumerable> ResourceMockTests => _resourceMockTests ??= EnsureMockTestProviders(); - - private IEnumerable> EnsureMockTestProviders() where TProvider : MgmtTypeProvider - { - foreach ((var owner, var testCases) in MockTestCases) - { - if (owner.GetType() == typeof(TProvider)) - yield return new MgmtMockTestProvider((TProvider)owner, testCases); - } - } } } diff --git a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs index 689ae0bcd22..5ce74a1760e 100644 --- a/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs +++ b/src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs @@ -10,7 +10,6 @@ using AutoRest.CSharp.Input.Source; using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.MgmtTest.AutoRest; -using AutoRest.CSharp.MgmtTest.Generation.Mock; using AutoRest.CSharp.MgmtTest.Generation.Samples; using AutoRest.CSharp.Output.Models.Types; @@ -41,11 +40,6 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project, InputNames library = new MgmtTestOutputLibrary(inputNamespace); } - if (Configuration.MgmtTestConfiguration?.Mock ?? false) - { - WriteMockTests(project, library); - } - if (Configuration.MgmtTestConfiguration?.Sample ?? Configuration.GenerateSampleProject) { WriteSamples(project, library); @@ -70,34 +64,6 @@ private static void InitializeMgmtContext(InputNamespace inputNamespace, SourceI } } - private static void WriteMockTests(GeneratedCodeWorkspace project, MgmtTestOutputLibrary library) - { - string outputFolder = GetOutputFolder(MOCK_TEST_DEFAULT_OUTPUT_PATH); - - // write the collection mock tests - foreach (var collectionTest in library.ResourceCollectionMockTests) - { - var collectionTestWriter = new ResourceCollectionMockTestWriter(collectionTest); - collectionTestWriter.Write(); - - AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{collectionTest.Type.Name}.cs"), collectionTestWriter.ToString()); - } - - foreach (var resourceTest in library.ResourceMockTests) - { - var resourceTestWriter = new ResourceMockTestWriter(resourceTest); - resourceTestWriter.Write(); - - AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{resourceTest.Type.Name}.cs"), resourceTestWriter.ToString()); - } - - var extensionWrapperTest = library.ExtensionWrapperMockTest; - var extensionWrapperTestWriter = new ExtensionWrapMockTestWriter(extensionWrapperTest, library.ExtensionMockTests); - extensionWrapperTestWriter.Write(); - - AddGeneratedFile(project, Path.Combine(outputFolder, $"Mock/{extensionWrapperTest.Type.Name}.cs"), extensionWrapperTestWriter.ToString()); - } - private static void WriteSamples(GeneratedCodeWorkspace project, MgmtTestOutputLibrary library) { string outputFolder = GetOutputFolder(SAMPLE_DEFAULT_OUTPUT_PATH); diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionMockTestWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionMockTestWriter.cs deleted file mode 100644 index 3279e658b8d..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionMockTestWriter.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Text; -using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; - -namespace AutoRest.CSharp.MgmtTest.Generation.Mock -{ - internal class ExtensionMockTestWriter : MgmtMockTestBaseWriter - { - public ExtensionMockTestWriter(CodeWriter writer, MgmtMockTestProvider extensionTest) : base(writer, extensionTest) - { - } - - public override void Write() - { - // this is a sub-writer, we override this so that we no longer write the class declaration - WriteTestMethods(); - } - - protected override void WriteTestMethodBody(MockTestCase testCase) - { - _writer.Line($"// Example: {testCase.Name}"); - - _writer.Line(); - var extensionResourceName = WriteGetExtension(This.Target, testCase, GetArmClientExpression); - - WriteTestOperation(extensionResourceName, testCase); - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionWrapMockTestWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionWrapMockTestWriter.cs deleted file mode 100644 index 57fba32ac4e..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ExtensionWrapMockTestWriter.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Collections.Generic; -using System.Linq; -using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; - -namespace AutoRest.CSharp.MgmtTest.Generation.Mock -{ - internal class ExtensionWrapMockTestWriter : MgmtMockTestBaseWriter - { - private IEnumerable> _extensionTests; - public ExtensionWrapMockTestWriter(MgmtMockTestProvider testWrapper, IEnumerable> extensionTests) : base(testWrapper) - { - _extensionTests = extensionTests; - } - - protected override void WriteTestMethods() - { - foreach (var extensionTest in _extensionTests) - { - var extensionWriter = new ExtensionMockTestWriter(_writer, extensionTest); - extensionWriter.Write(); - } - - _writer.Line(); - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/MgmtMockTestBaseWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Mock/MgmtMockTestBaseWriter.cs deleted file mode 100644 index e7814ec4c84..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/MgmtMockTestBaseWriter.cs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Input; -using AutoRest.CSharp.Mgmt.AutoRest; -using AutoRest.CSharp.Mgmt.Decorator; -using AutoRest.CSharp.Mgmt.Models; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Extensions; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; -using AutoRest.CSharp.Utilities; -using Azure.Core; -using Azure.ResourceManager; -using Azure.ResourceManager.Resources; - -namespace AutoRest.CSharp.MgmtTest.Generation.Mock -{ - internal abstract class MgmtMockTestBaseWriter : MgmtTestWriterBase> where TProvider : MgmtTypeProvider - { - protected MgmtMockTestBaseWriter(MgmtMockTestProvider provider) : base(provider) - { - } - - protected MgmtMockTestBaseWriter(CodeWriter writer, MgmtMockTestProvider provider) : base(writer, provider) - { - } - - protected FormattableString GetArmClientExpression => $"GetArmClient()"; - - public override void Write() - { - using (_writer.Namespace(This.Namespace)) - { - WriteClassDeclaration(); - using (_writer.Scope()) - { - WriteImplementations(); - } - } - } - - protected internal virtual void WriteImplementations() - { - WriteCtors(); - - WriteTestMethods(); - } - - protected virtual void WriteCtors() - { - if (This.Ctor is not null) - { - using (_writer.WriteMethodDeclaration(This.Ctor)) - { - _writer.Line($"{typeof(ServicePointManager)}.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;"); - _writer.Line($"{typeof(Environment)}.SetEnvironmentVariable(\"RESOURCE_MANAGER_URL\", $\"https://localhost:8443\");"); - } - _writer.Line(); - } - } - - protected virtual void WriteTestMethods() - { - var testCaseDict = new Dictionary>(); - foreach (var testCase in This.MockTestCases) - { - testCaseDict.AddInList(testCase.Operation, testCase); - } - - foreach (var testCase in This.MockTestCases.OrderBy(testCase => testCase.Operation.Name)) - { - WriteTestMethod(testCase, testCaseDict[testCase.Operation].Count > 1); - _writer.Line(); - } - } - - protected virtual void WriteTestMethod(MockTestCase testCase, bool hasSuffix) - { - WriteTestAttribute(); - // TODO -- find a way to determine when we need to add the suffix - using (_writer.WriteMethodDeclaration(testCase.GetMethodSignature(hasSuffix))) - { - WriteTestMethodBody(testCase); - } - } - - protected virtual void WriteTestMethodBody(MockTestCase testCase) - { - } - - protected void WriteTestAttribute() - { - _writer.UseNamespace("Azure.Core.TestFramework"); - _writer.Line($"[RecordedTest]"); - } - - protected void WriteTestOperation(CodeWriterDeclaration declaration, MockTestCase testCase) - { - // we will always use the Async version of methods - if (testCase.Operation.IsPagingOperation) - { - _writer.Append($"await foreach (var _ in "); - WriteTestMethodInvocation(declaration, testCase); - using (_writer.Scope($")")) - { } - } - else - { - _writer.Append($"await "); - WriteTestMethodInvocation(declaration, testCase); - _writer.LineRaw(";"); - } - } - - protected void WriteTestMethodInvocation(CodeWriterDeclaration declaration, MockTestCase testCase) - { - var operation = testCase.Operation; - var methodName = CreateMethodName(operation.Name); - _writer.Append($"{declaration}.{methodName}("); - foreach (var parameter in operation.MethodParameters) - { - if (testCase.ParameterValueMapping.TryGetValue(parameter.Name, out var parameterValue)) - { - _writer.AppendExampleParameterValue(parameter, parameterValue); - _writer.AppendRaw(","); - } - else if (parameter.IsPropertyBag) - { - _writer.AppendExamplePropertyBagParamValue(parameter, testCase.PropertyBagParamValueMapping); - _writer.AppendRaw(","); - } - } - _writer.RemoveTrailingComma(); - _writer.AppendRaw(")"); - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceCollectionMockTestWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceCollectionMockTestWriter.cs deleted file mode 100644 index fa47bd3163d..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceCollectionMockTestWriter.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Diagnostics; -using System.Linq; -using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Mgmt.Decorator; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Extensions; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; -using Azure.ResourceManager; - -namespace AutoRest.CSharp.MgmtTest.Generation.Mock -{ - internal class ResourceCollectionMockTestWriter : MgmtMockTestBaseWriter - { - public ResourceCollectionMockTestWriter(MgmtMockTestProvider resourceCollectionTest) : base(resourceCollectionTest) - { - } - - protected override void WriteTestMethodBody(MockTestCase testCase) - { - _writer.Line($"// Example: {testCase.Name}"); - - _writer.Line(); - var collectionName = WriteGetCollection(testCase); - - WriteTestOperation(collectionName, testCase); - } - - private CodeWriterDeclaration? WriteGetParentResource(MgmtTypeProvider parent, MockTestCase testCase) - { - if (parent is MgmtExtension extension && extension.ArmCoreType == typeof(ArmResource)) - return null; - - return WriteGetResource(parent, testCase, GetArmClientExpression); - } - - protected CodeWriterDeclaration WriteGetCollection(MockTestCase testCase) - { - var parent = testCase.Parent; - Debug.Assert(parent is not null); - var parentVar = WriteGetParentResource(parent, testCase); - - var getResourceCollectionMethodName = $"Get{This.Target.Resource.ResourceName.ResourceNameToPlural()}"; - var collectionName = new CodeWriterDeclaration("collection"); - if (parentVar == null) - { - // this case will happen only when the resource is a scope resource - var idVar = new CodeWriterDeclaration("scope"); - WriteCreateScopeResourceIdentifier(testCase, idVar, testCase.RequestPath.GetScopePath()); - _writer.Line($"var {collectionName:D} = {GetArmClientExpression}.{getResourceCollectionMethodName}({idVar}, "); - } - else - { - // now we have the parent resource, get the collection from that resource - // TODO -- we might should look this up inside the code project for correct method name - _writer.Append($"var {collectionName:D} = {parentVar}.{getResourceCollectionMethodName}("); - } - - var parameterValues = testCase.ParameterValueMapping; - // iterate over the ResourceCollection.ExtraConstructorParameters to get extra parameters for the GetCollection method - foreach (var extraParameter in This.Target.ExtraConstructorParameters) - { - if (parameterValues.TryGetValue(extraParameter.Name, out var value)) - { - _writer.AppendExampleParameterValue(extraParameter, value); - _writer.AppendRaw(","); - } - } - _writer.RemoveTrailingComma(); - _writer.LineRaw(");"); - - return collectionName; - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceMockTestWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceMockTestWriter.cs deleted file mode 100644 index 933a717ff25..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Mock/ResourceMockTestWriter.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using AutoRest.CSharp.Generation.Writers; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.MgmtTest.Output.Mock; - -namespace AutoRest.CSharp.MgmtTest.Generation.Mock -{ - internal class ResourceMockTestWriter : MgmtMockTestBaseWriter - { - public ResourceMockTestWriter(MgmtMockTestProvider resourceMockTest) : base(resourceMockTest) - { - } - - protected override void WriteTestMethodBody(MockTestCase testCase) - { - _writer.Line($"// Example: {testCase.Name}"); - - _writer.Line(); - var resourceName = WriteGetResource(testCase.Carrier, testCase, GetArmClientExpression); - - WriteTestOperation(resourceName, testCase); - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Generation/Samples/MgmtSampleWriter.cs b/src/AutoRest.CSharp/MgmtTest/Generation/Samples/MgmtSampleWriter.cs index 11807db89f8..815252414db 100644 --- a/src/AutoRest.CSharp/MgmtTest/Generation/Samples/MgmtSampleWriter.cs +++ b/src/AutoRest.CSharp/MgmtTest/Generation/Samples/MgmtSampleWriter.cs @@ -238,7 +238,7 @@ private CodeWriterVariableDeclaration WriteGetArmClient() return result; } - private CodeWriterDeclaration? WriteGetParentResource(MgmtTypeProvider parent, MockTestCase testCase, FormattableString clientExpression) + private CodeWriterDeclaration? WriteGetParentResource(MgmtTypeProvider parent, Sample testCase, FormattableString clientExpression) { if (parent is MgmtExtension extension && extension.ArmCoreType == typeof(ArmResource)) return null; diff --git a/src/AutoRest.CSharp/MgmtTest/Models/MockTestCase.cs b/src/AutoRest.CSharp/MgmtTest/Models/MockTestCase.cs deleted file mode 100644 index ff02c82c736..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Models/MockTestCase.cs +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using AutoRest.CSharp.Common.Input; -using AutoRest.CSharp.Common.Input.Examples; -using AutoRest.CSharp.Common.Utilities; -using AutoRest.CSharp.Generation.Types; -using AutoRest.CSharp.Input; -using AutoRest.CSharp.Mgmt.Decorator; -using AutoRest.CSharp.Mgmt.Models; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.Output.Models; -using AutoRest.CSharp.Output.Models.Shared; -using AutoRest.CSharp.Utilities; -using Azure; -using MappingObject = System.Collections.Generic.Dictionary; - -namespace AutoRest.CSharp.MgmtTest.Models -{ - internal class MockTestCase : OperationExample - { - public MockTestCase(string operationId, MgmtTypeProvider carrier, MgmtClientOperation operation, InputOperation inputOperation, InputOperationExample example) : base(operationId, carrier, operation, inputOperation, example) - { - } - - protected virtual string GetMethodName(bool hasSuffix) - => hasSuffix ? $"{Operation.Name}_{Name.ToCleanName()}" : Operation.Name; - - public MethodSignature GetMethodSignature(bool hasSuffix) => new MethodSignature( - Name: GetMethodName(hasSuffix), - Description: null, - Summary: null, - Modifiers: MethodSignatureModifiers.Public | MethodSignatureModifiers.Async, - ReturnType: typeof(Task), - ReturnDescription: null, - Parameters: Array.Empty()); - - private MgmtTypeProvider? _parent; - public MgmtTypeProvider? Parent => _parent ??= GetParent(); - - private MgmtTypeProvider? GetParent() - { - if (Carrier is not Resource resource) - return null; - var parents = resource.GetParents(); - // TODO -- find a way to determine which parent to use. Only for prototype, here we use the first - // Only when this resource is a "scope resource", we could have multiple parents - // We could use the value of the scope variable, get the resource type from it to know which resource we should use as a parent here - return parents.FirstOrDefault(); - } - - private MappingObject? _parameterValueMapping; - public MappingObject ParameterValueMapping => _parameterValueMapping ??= EnsureParameterValueMapping().Item1; - - private MappingObject? _propertyBagParamValueMapping; - public MappingObject PropertyBagParamValueMapping => _propertyBagParamValueMapping ??= EnsureParameterValueMapping().Item2; - - private IEnumerable GetAllPossibleParameters() - { - // skip the first parameter if this method is an extension method, since that will be the extension resource - var methodParameters = Operation.MethodSignature.Modifiers.HasFlag(MethodSignatureModifiers.Extension) ? - Operation.MethodParameters.Skip(1) : Operation.MethodParameters; - - // remove the property bag parameter and add the parameter in the property bag - if (Operation.IsPropertyBagOperation) - { - methodParameters = methodParameters.Where(p => !p.IsPropertyBag).Concat(Operation.PropertyBagUnderlyingParameters); - } - - return Carrier.ExtraConstructorParameters.Concat(methodParameters); - } - - private Tuple EnsureParameterValueMapping() - { - var result = new MappingObject(); - var propertyBagMapping = new MappingObject(); - var parameters = GetAllPossibleParameters(); - var propertyBagParamNames = Operation.PropertyBagUnderlyingParameters.Select(p => p.Name).ToList(); - // get the "serialized name" of the parameters based on the raw request path - foreach (var parameter in parameters) - { - if (ProcessKnownParameters(result, parameter)) - continue; - - var exampleParameter = FindExampleParameterBySerializedName(AllParameters, GetParameterSerializedName(parameter.Name)); - // if this parameter is a body parameter, we might have changed it to required, and we cannot tell if we have changed it on the codemodel right now. In this case we just fake an empty body. - if (parameter.DefaultValue == null && parameter.RequestLocation == RequestLocation.Body) - { - exampleParameter ??= new(new InputParameter(), new InputExampleObjectValue(InputPrimitiveType.Boolean, new Dictionary())); - } - if (exampleParameter == null) - { - // if this is a required parameter and we did not find the corresponding parameter in the examples - if (parameter.DefaultValue == null) - { - // this parameter is not from body which means its type should be primary which means "default" keyword should be able to handle - // the default value (also string because we disabled nullable in generated code) - var warning = $"No value is provided for {parameter.Name} in example '{this.Name}'. Please consider adding a proper example value for it in swagger"; - AutoRestLogger.Warning(warning).Wait(); - var pv = new ExampleParameterValue(parameter, $"default /* Warning: {warning}*/"); - if (Operation.IsPropertyBagOperation && propertyBagParamNames.Contains(parameter.Name)) - { - propertyBagMapping.Add(parameter.Name, pv); - } - else - { - result.Add(parameter.Name, pv); - } - } - // if it is optional, we just do not put it in the map indicates that in the invocation we could omit it - } - else - { - if (Operation.IsPropertyBagOperation && propertyBagParamNames.Contains(parameter.Name)) - { - propertyBagMapping.Add(parameter.Name, new ExampleParameterValue(parameter, exampleParameter.ExampleValue)); - } - else - { - result.Add(parameter.Name, new ExampleParameterValue(parameter, exampleParameter.ExampleValue)); - } - } - } - - return Tuple.Create(result, propertyBagMapping); - } - - private static bool ProcessKnownParameters(MappingObject result, Parameter parameter) - { - if (parameter == KnownParameters.WaitForCompletion) - { - result.Add(parameter.Name, new ExampleParameterValue(parameter, $"{typeof(WaitUntil)}.Completed")); - return true; - } - if (parameter == KnownParameters.CancellationTokenParameter) - { - // we usually do not set this parameter in generated test cases - return true; - } - - return false; - } - - public bool IsConvenientOperation => Operation.IsConvenientOperation; - - public bool IsLro => Operation.IsLongRunningOperation; - - public bool IsPageable => Operation.IsPagingOperation; - - protected override InputExampleValue ReplacePathParameterValue(string serializedName, CSharpType type, InputExampleValue value) - { - if (serializedName == "subscriptionId") - { - return new InputExampleRawValue(value.Type, ReplaceValueForSubscriptionId((string)(value as InputExampleRawValue)?.RawValue!)); - } - - return value; - } - - private readonly static Regex _regexForGuid = new Regex("^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$"); - private const string _fallbackSubscriptionId = "00000000-0000-0000-0000-000000000000"; - - private string ReplaceValueForSubscriptionId(string rawValue) - { - if (_regexForGuid.IsMatch(rawValue)) - return rawValue; - - return _fallbackSubscriptionId; - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Models/OperationExample.cs b/src/AutoRest.CSharp/MgmtTest/Models/OperationExample.cs index f01fe1a6b17..62ba772ffd9 100644 --- a/src/AutoRest.CSharp/MgmtTest/Models/OperationExample.cs +++ b/src/AutoRest.CSharp/MgmtTest/Models/OperationExample.cs @@ -127,14 +127,10 @@ private ExampleParameterValue FindExampleParameterValueFromReference(Reference r // find a path parameter in our path parameters for one with same name var serializedName = GetParameterSerializedName(reference.Name); var parameter = FindPathExampleParameterBySerializedName(serializedName); - var exampleValue = ReplacePathParameterValue(serializedName, reference.Type, parameter.ExampleValue); - return new ExampleParameterValue(reference, exampleValue); + return new ExampleParameterValue(reference, parameter.ExampleValue); } - protected virtual InputExampleValue ReplacePathParameterValue(string serializedName, CSharpType type, InputExampleValue value) - => value; - private Dictionary EnsureParameterSerializedNames() { var result = new Dictionary(StringComparer.OrdinalIgnoreCase); diff --git a/src/AutoRest.CSharp/MgmtTest/Models/Sample.cs b/src/AutoRest.CSharp/MgmtTest/Models/Sample.cs index 536b7b52571..8556279d7b7 100644 --- a/src/AutoRest.CSharp/MgmtTest/Models/Sample.cs +++ b/src/AutoRest.CSharp/MgmtTest/Models/Sample.cs @@ -1,26 +1,155 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Common.Input.Examples; +using AutoRest.CSharp.Common.Utilities; using AutoRest.CSharp.Generation.Types; +using AutoRest.CSharp.Mgmt.Decorator; +using AutoRest.CSharp.Mgmt.Models; +using AutoRest.CSharp.Mgmt.Output; +using AutoRest.CSharp.Output.Models; +using AutoRest.CSharp.Output.Models.Shared; +using AutoRest.CSharp.Utilities; +using Azure; +using MappingObject = System.Collections.Generic.Dictionary; namespace AutoRest.CSharp.MgmtTest.Models { - internal class Sample : MockTestCase + internal class Sample : OperationExample { - public Sample(MockTestCase testCase) : base(testCase.OperationId, testCase.Carrier, testCase.Operation, testCase._inputOperation, testCase._example) + public Sample(string operationId, MgmtTypeProvider carrier, MgmtClientOperation operation, InputOperation inputOperation, InputOperationExample example) : base(operationId, carrier, operation, inputOperation, example) { + _methodName = $"{Operation.Name}_{Name.ToCleanName()}"; } - protected override string GetMethodName(bool hasSuffix) - => base.GetMethodName(true); // sample will always use a full name + private readonly string _methodName; - protected override InputExampleValue ReplacePathParameterValue(string serializedName, CSharpType type, InputExampleValue value) + public string ExampleFilepath => _example.FilePath; + public MethodSignature GetMethodSignature(bool hasSuffix) => new MethodSignature( + Name: _methodName, + Description: null, + Summary: null, + Modifiers: MethodSignatureModifiers.Public | MethodSignatureModifiers.Async, + ReturnType: typeof(Task), + ReturnDescription: null, + Parameters: Array.Empty()); + + private MgmtTypeProvider? _parent; + public MgmtTypeProvider? Parent => _parent ??= GetParent(); + + private MgmtTypeProvider? GetParent() { - // the samples do not override anything - return value; + if (Carrier is not Resource resource) + return null; + var parents = resource.GetParents(); + // TODO -- find a way to determine which parent to use. Only for prototype, here we use the first + // Only when this resource is a "scope resource", we could have multiple parents + // We could use the value of the scope variable, get the resource type from it to know which resource we should use as a parent here + return parents.FirstOrDefault(); } - public string ExampleFilepath => _example.FilePath; + private MappingObject? _parameterValueMapping; + public MappingObject ParameterValueMapping => _parameterValueMapping ??= EnsureParameterValueMapping().Item1; + + private MappingObject? _propertyBagParamValueMapping; + public MappingObject PropertyBagParamValueMapping => _propertyBagParamValueMapping ??= EnsureParameterValueMapping().Item2; + + private IEnumerable GetAllPossibleParameters() + { + // skip the first parameter if this method is an extension method, since that will be the extension resource + var methodParameters = Operation.MethodSignature.Modifiers.HasFlag(MethodSignatureModifiers.Extension) ? + Operation.MethodParameters.Skip(1) : Operation.MethodParameters; + + // remove the property bag parameter and add the parameter in the property bag + if (Operation.IsPropertyBagOperation) + { + methodParameters = methodParameters.Where(p => !p.IsPropertyBag).Concat(Operation.PropertyBagUnderlyingParameters); + } + + return Carrier.ExtraConstructorParameters.Concat(methodParameters); + } + + private Tuple EnsureParameterValueMapping() + { + var result = new MappingObject(); + var propertyBagMapping = new MappingObject(); + var parameters = GetAllPossibleParameters(); + var propertyBagParamNames = Operation.PropertyBagUnderlyingParameters.Select(p => p.Name).ToList(); + // get the "serialized name" of the parameters based on the raw request path + foreach (var parameter in parameters) + { + if (ProcessKnownParameters(result, parameter)) + continue; + + var exampleParameter = FindExampleParameterBySerializedName(AllParameters, GetParameterSerializedName(parameter.Name)); + // if this parameter is a body parameter, we might have changed it to required, and we cannot tell if we have changed it on the codemodel right now. In this case we just fake an empty body. + if (parameter.DefaultValue == null && parameter.RequestLocation == RequestLocation.Body) + { + exampleParameter ??= new(new InputParameter(), new InputExampleObjectValue(InputPrimitiveType.Boolean, new Dictionary())); + } + if (exampleParameter == null) + { + // if this is a required parameter and we did not find the corresponding parameter in the examples + if (parameter.DefaultValue == null) + { + // this parameter is not from body which means its type should be primary which means "default" keyword should be able to handle + // the default value (also string because we disabled nullable in generated code) + var warning = $"No value is provided for {parameter.Name} in example '{this.Name}'. Please consider adding a proper example value for it in swagger"; + AutoRestLogger.Warning(warning).Wait(); + var pv = new ExampleParameterValue(parameter, $"default /* Warning: {warning}*/"); + if (Operation.IsPropertyBagOperation && propertyBagParamNames.Contains(parameter.Name)) + { + propertyBagMapping.Add(parameter.Name, pv); + } + else + { + result.Add(parameter.Name, pv); + } + } + // if it is optional, we just do not put it in the map indicates that in the invocation we could omit it + } + else + { + if (Operation.IsPropertyBagOperation && propertyBagParamNames.Contains(parameter.Name)) + { + propertyBagMapping.Add(parameter.Name, new ExampleParameterValue(parameter, exampleParameter.ExampleValue)); + } + else + { + result.Add(parameter.Name, new ExampleParameterValue(parameter, exampleParameter.ExampleValue)); + } + } + } + + return Tuple.Create(result, propertyBagMapping); + } + + private static bool ProcessKnownParameters(MappingObject result, Parameter parameter) + { + if (parameter == KnownParameters.WaitForCompletion) + { + result.Add(parameter.Name, new ExampleParameterValue(parameter, $"{typeof(WaitUntil)}.Completed")); + return true; + } + if (parameter == KnownParameters.CancellationTokenParameter) + { + // we usually do not set this parameter in generated test cases + return true; + } + + return false; + } + + public bool IsConvenientOperation => Operation.IsConvenientOperation; + + public bool IsLro => Operation.IsLongRunningOperation; + + public bool IsPageable => Operation.IsPagingOperation; } } diff --git a/src/AutoRest.CSharp/MgmtTest/Output/Mock/MgmtMockTestProvider.cs b/src/AutoRest.CSharp/MgmtTest/Output/Mock/MgmtMockTestProvider.cs deleted file mode 100644 index fa8c318bdea..00000000000 --- a/src/AutoRest.CSharp/MgmtTest/Output/Mock/MgmtMockTestProvider.cs +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions; -using AutoRest.CSharp.Generation.Types; -using AutoRest.CSharp.Mgmt.Output; -using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.Output.Models; -using AutoRest.CSharp.Output.Models.Shared; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; - -namespace AutoRest.CSharp.MgmtTest.Output.Mock -{ - internal class MgmtMockTestProvider : MgmtTestProvider where T : MgmtTypeProvider - { - protected Parameter IsAsyncParameter => new(Name: "isAsync", Description: null, Type: typeof(bool), DefaultValue: null, ValidationType.None, null); - - public T Target { get; } - public MgmtMockTestProvider(T provider, IEnumerable testCases) : base() - { - Target = provider; - MockTestCases = testCases; - } - - public IEnumerable MockTestCases { get; } - public override FormattableString Description => $"Test for {Target.Type.Name}"; - protected override string DefaultName => $"{Target.Type.Name}MockTests"; - protected override string DefaultNamespace => $"{Target.Type.Namespace}.Tests.Mock"; - public override CSharpType? BaseType => typeof(MockTestBase); - - private ConstructorSignature? _ctor; - public ConstructorSignature? Ctor => _ctor ??= EnsureCtor(); - protected virtual ConstructorSignature? EnsureCtor() - { - return new ConstructorSignature( - Type, - null, - Description: $"Initializes a new instance of the class for mocking.", - Modifiers: MethodSignatureModifiers.Public, - Parameters: new[] { IsAsyncParameter }, - Initializer: new ConstructorInitializer( - true, - new ValueExpression[] { IsAsyncParameter, new TypeReference(typeof(RecordedTestMode)).Property(nameof(RecordedTestMode.Record)) })); - } - } -} diff --git a/src/AutoRest.CSharp/MgmtTest/Output/Samples/MgmtSampleProvider.cs b/src/AutoRest.CSharp/MgmtTest/Output/Samples/MgmtSampleProvider.cs index 58c7f0133d6..ac0c46b1407 100644 --- a/src/AutoRest.CSharp/MgmtTest/Output/Samples/MgmtSampleProvider.cs +++ b/src/AutoRest.CSharp/MgmtTest/Output/Samples/MgmtSampleProvider.cs @@ -3,11 +3,8 @@ using System; using System.Collections.Generic; -using AutoRest.CSharp.Mgmt.AutoRest; using AutoRest.CSharp.Mgmt.Output; using AutoRest.CSharp.MgmtTest.Models; -using AutoRest.CSharp.Output.Models.Types; -using AutoRest.CSharp.Utilities; namespace AutoRest.CSharp.MgmtTest.Output.Samples { diff --git a/test/AutoRest.TestServer.Tests/Mgmt/TestProjects/MgmtMockAndSampleTests.cs b/test/AutoRest.TestServer.Tests/Mgmt/TestProjects/MgmtMockAndSampleTests.cs deleted file mode 100644 index cd894f930a3..00000000000 --- a/test/AutoRest.TestServer.Tests/Mgmt/TestProjects/MgmtMockAndSampleTests.cs +++ /dev/null @@ -1,79 +0,0 @@ -using System; -using System.Collections.Generic; -using NUnit.Framework; -using MgmtMockAndSample; - -namespace AutoRest.TestServer.Tests.Mgmt.TestProjects -{ - public class MgmtMockAndSampleTests : TestProjectTests - { - public MgmtMockAndSampleTests() : base("MgmtMockAndSample", "tests") { } - - protected override HashSet ListExceptionCollections { get; } = new HashSet() { typeof(DeletedManagedHsmCollection), typeof(DeletedVaultCollection) }; - - [TestCase("CreateOrUpdate")] - [TestCase("Get")] - [TestCase("GetAll")] - public void ValidateMhsmPrivateEndpointConnectionCollectionMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.MhsmPrivateEndpointConnectionCollectionMockTests", methodName, argTypes); - } - - [TestCase("CreateOrUpdate")] - [TestCase("Get")] - [TestCase("GetAll")] - public void ValidateManagedHsmCollectionMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.ManagedHsmCollectionMockTests", methodName, argTypes); - } - - [TestCase("CreateOrUpdate")] - [TestCase("Get")] - [TestCase("GetAll")] - public void ValidatePrivateEndpointConnectionCollectionMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests", methodName, argTypes); - } - - [TestCase("CreateOrUpdate_CreateANewVaultOrUpdateAnExistingVault")] - [TestCase("CreateOrUpdate_CreateOrUpdateAVaultWithNetworkAcls")] - [TestCase("Get")] - [TestCase("GetAll")] - public void ValidateVaultCollectionMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.VaultCollectionMockTests", methodName, argTypes); - } - - [TestCase("Get")] - [TestCase("Delete")] - [TestCase("Update")] - [TestCase("GetMHSMPrivateLinkResourcesByMhsmResource")] - public void ValidateManagedHsmResourceMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.ManagedHsmResourceMockTests", methodName, argTypes); - } - - [TestCase("Get")] - [TestCase("Delete")] - public void ValidateMhsmPrivateEndpointConnectionResourceMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.MhsmPrivateEndpointConnectionResourceMockTests", methodName, argTypes); - } - - [TestCase("Get")] - [TestCase("Delete")] - public void ValidatePrivateEndpointConnectionResourceMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests", methodName, argTypes); - } - - [TestCase("Get")] - [TestCase("Delete")] - //[TestCase("Update")] // comment this because this corresponding generated test case is removed in order to test a new configuration - [TestCase("GetPrivateLinkResources")] - public void ValidateVaultResourceMockTests(string methodName, params string[] argTypes) - { - ValidateMethodExist("MgmtMockAndSample.Tests.Mock.VaultResourceMockTests", methodName, argTypes); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/src/Generated/Configuration.json b/test/TestProjects/MgmtMockAndSample/src/Generated/Configuration.json index 856690532da..b2e2ad84339 100644 --- a/test/TestProjects/MgmtMockAndSample/src/Generated/Configuration.json +++ b/test/TestProjects/MgmtMockAndSample/src/Generated/Configuration.json @@ -50,7 +50,6 @@ "Vaults_GetDeleted", "Vaults_Update" ], - "Mock": true, "Sample": true }, "flavor": "azure", diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmCollectionMockTests.cs deleted file mode 100644 index 324e0cf7530..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmCollectionMockTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for DeletedManagedHsmCollection. - public partial class DeletedManagedHsmCollectionMockTests : MockTestBase - { - public DeletedManagedHsmCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Retrieve a deleted managed HSM - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetDeletedManagedHsms(); - await collection.ExistsAsync(new AzureLocation("westus"), "hsm1"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a deleted managed HSM - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetDeletedManagedHsms(); - await collection.GetAsync(new AzureLocation("westus"), "hsm1"); - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Retrieve a deleted managed HSM - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetDeletedManagedHsms(); - await collection.GetIfExistsAsync(new AzureLocation("westus"), "hsm1"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmResourceMockTests.cs deleted file mode 100644 index 3054cd2548e..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedManagedHsmResourceMockTests.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for DeletedManagedHsmResource. - public partial class DeletedManagedHsmResourceMockTests : MockTestBase - { - public DeletedManagedHsmResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a deleted managed HSM - - ResourceIdentifier deletedManagedHsmResourceId = DeletedManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", new AzureLocation("westus"), "hsm1"); - DeletedManagedHsmResource deletedManagedHsm = GetArmClient().GetDeletedManagedHsmResource(deletedManagedHsmResourceId); - await deletedManagedHsm.GetAsync(); - } - - [RecordedTest] - public async Task PurgeDeleted() - { - // Example: Purge a managed HSM Pool - - ResourceIdentifier deletedManagedHsmResourceId = DeletedManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", new AzureLocation("westus"), "hsm1"); - DeletedManagedHsmResource deletedManagedHsm = GetArmClient().GetDeletedManagedHsmResource(deletedManagedHsmResourceId); - await deletedManagedHsm.PurgeDeletedAsync(WaitUntil.Completed); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedVaultResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedVaultResourceMockTests.cs deleted file mode 100644 index b17e14db036..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DeletedVaultResourceMockTests.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for DeletedVaultResource. - public partial class DeletedVaultResourceMockTests : MockTestBase - { - public DeletedVaultResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task PurgeDeleted() - { - // Example: Purge a deleted vault - - ResourceIdentifier deletedVaultResourceId = DeletedVaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", new AzureLocation("westus"), "sample-vault"); - DeletedVaultResource deletedVault = GetArmClient().GetDeletedVaultResource(deletedVaultResourceId); - await deletedVault.PurgeDeletedAsync(WaitUntil.Completed); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetCollectionMockTests.cs deleted file mode 100644 index 49e80981bfe..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetCollectionMockTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Models; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for DiskEncryptionSetCollection. - public partial class DiskEncryptionSetCollectionMockTests : MockTestBase - { - public DiskEncryptionSetCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateADiskEncryptionSetWithKeyVaultFromADifferentSubscription() - { - // Example: Create a disk encryption set with key vault from a different subscription. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "myDiskEncryptionSet", new DiskEncryptionSetData() - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvaultdifferentsub.vault-int.azure-int.net/keys/{key}")), - MinimumTlsVersion = MinimumTlsVersion.Tls1_1, - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateADiskEncryptionSetWithKeyVaultFromADifferentTenant() - { - // Example: Create a disk encryption set with key vault from a different tenant. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "myDiskEncryptionSet", new DiskEncryptionSetData() - { - Identity = new ManagedServiceIdentity("UserAssigned") - { - UserAssignedIdentities = -{ -[new ResourceIdentifier("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}")] = new UserAssignedIdentity(), -}, - }, - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvaultdifferenttenant.vault-int.azure-int.net/keys/{key}")), - FederatedClientId = "00000000-0000-0000-0000-000000000000", - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateADiskEncryptionSet() - { - // Example: Create a disk encryption set. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "myDiskEncryptionSet", new DiskEncryptionSetData() - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvmvault.vault-int.azure-int.net/keys/{key}")) - { - SourceVaultId = new ResourceIdentifier("/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault"), - }, - }); - } - - [RecordedTest] - public async Task Exists_GetInformationAboutADiskEncryptionSetWhenAutoKeyRotationFailed() - { - // Example: Get information about a disk encryption set when auto-key rotation failed. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.ExistsAsync("myDiskEncryptionSet"); - } - - [RecordedTest] - public async Task Exists_GetInformationAboutADiskEncryptionSet() - { - // Example: Get information about a disk encryption set. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.ExistsAsync("myDiskEncryptionSet"); - } - - [RecordedTest] - public async Task Get_GetInformationAboutADiskEncryptionSetWhenAutoKeyRotationFailed() - { - // Example: Get information about a disk encryption set when auto-key rotation failed. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.GetAsync("myDiskEncryptionSet"); - } - - [RecordedTest] - public async Task Get_GetInformationAboutADiskEncryptionSet() - { - // Example: Get information about a disk encryption set. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.GetAsync("myDiskEncryptionSet"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List all disk encryption sets in a resource group. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists_GetInformationAboutADiskEncryptionSetWhenAutoKeyRotationFailed() - { - // Example: Get information about a disk encryption set when auto-key rotation failed. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.GetIfExistsAsync("myDiskEncryptionSet"); - } - - [RecordedTest] - public async Task GetIfExists_GetInformationAboutADiskEncryptionSet() - { - // Example: Get information about a disk encryption set. - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetDiskEncryptionSets(); - await collection.GetIfExistsAsync("myDiskEncryptionSet"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetResourceMockTests.cs deleted file mode 100644 index 24a835db832..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/DiskEncryptionSetResourceMockTests.cs +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Models; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for DiskEncryptionSetResource. - public partial class DiskEncryptionSetResourceMockTests : MockTestBase - { - public DiskEncryptionSetResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete a disk encryption set. - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get_GetInformationAboutADiskEncryptionSetWhenAutoKeyRotationFailed() - { - // Example: Get information about a disk encryption set when auto-key rotation failed. - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.GetAsync(); - } - - [RecordedTest] - public async Task Get_GetInformationAboutADiskEncryptionSet() - { - // Example: Get information about a disk encryption set. - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.GetAsync(); - } - - [RecordedTest] - public async Task GetDiskEncryptionSets() - { - // Example: List all disk encryption sets in a subscription. - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetDiskEncryptionSetsAsync()) - { - } - } - - [RecordedTest] - public async Task Update_UpdateADiskEncryptionSetWithRotationToLatestKeyVersionEnabledSetToTrueSucceeded() - { - // Example: Update a disk encryption set with rotationToLatestKeyVersionEnabled set to true - Succeeded - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.UpdateAsync(WaitUntil.Completed, new DiskEncryptionSetPatch() - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvaultdifferentsub.vault-int.azure-int.net/keys/keyName/keyVersion1")), - RotationToLatestKeyVersionEnabled = true, - }); - } - - [RecordedTest] - public async Task Update_UpdateADiskEncryptionSetWithRotationToLatestKeyVersionEnabledSetToTrueUpdating() - { - // Example: Update a disk encryption set with rotationToLatestKeyVersionEnabled set to true - Updating - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.UpdateAsync(WaitUntil.Completed, new DiskEncryptionSetPatch() - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvaultdifferentsub.vault-int.azure-int.net/keys/keyName/keyVersion1")), - RotationToLatestKeyVersionEnabled = true, - }); - } - - [RecordedTest] - public async Task Update_UpdateADiskEncryptionSet() - { - // Example: Update a disk encryption set. - - ResourceIdentifier diskEncryptionSetResourceId = DiskEncryptionSetResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroup", "myDiskEncryptionSet"); - DiskEncryptionSetResource diskEncryptionSet = GetArmClient().GetDiskEncryptionSetResource(diskEncryptionSetResourceId); - await diskEncryptionSet.UpdateAsync(WaitUntil.Completed, new DiskEncryptionSetPatch() - { - Tags = -{ -["department"] = "Development", -["project"] = "Encryption", -}, - EncryptionType = DiskEncryptionSetType.EncryptionAtRestWithCustomerKey, - ActiveKey = new KeyForDiskEncryptionSet(new Uri("https://myvmvault.vault-int.azure-int.net/keys/keyName/keyVersion")) - { - SourceVaultId = new ResourceIdentifier("/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault"), - }, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyCollectionMockTests.cs deleted file mode 100644 index 3a3e8307d6e..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyCollectionMockTests.cs +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for FirewallPolicyCollection. - public partial class FirewallPolicyCollectionMockTests : MockTestBase - { - public FirewallPolicyCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicy() - { - // Example: Create FirewallPolicy - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "firewallPolicy", new FirewallPolicyData(new AzureLocation("West US")) - { - StartupProbe = null, - ReadinessProbe = new Probe(false) - { - InitialDelaySeconds = 30, - PeriodSeconds = 10, - FailureThreshold = 3, - }, - DesiredStatusCode = DesiredStatusCode.TwoHundredTwo, - ThreatIntelWhitelist = new FirewallPolicyThreatIntelWhitelist() - { - IpAddresses = -{ -IPAddress.Parse("20.3.4.5") -}, - Fqdns = -{ -"*.microsoft.com" -}, - }, - Insights = new FirewallPolicyInsights() - { - IsEnabled = true, - RetentionDays = 100, - LogAnalyticsResources = new FirewallPolicyLogAnalyticsResources() - { - Workspaces = -{ -new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "westus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace1"), -},new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "eastus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace2"), -} -}, - DefaultWorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/defaultWorkspace"), - }, - }, - SnatPrivateRanges = -{ -"IANAPrivateRanges" -}, - DnsSettings = new DnsSettings() - { - Servers = -{ -"30.3.4.5" -}, - EnableProxy = true, - RequireProxyForNetworkRules = false, - }, - IntrusionDetection = new FirewallPolicyIntrusionDetection() - { - Mode = FirewallPolicyIntrusionDetectionStateType.Alert, - Configuration = new FirewallPolicyIntrusionDetectionConfiguration() - { - SignatureOverrides = -{ -new FirewallPolicyIntrusionDetectionSignatureSpecification() -{ -Id = "2525004", -Mode = FirewallPolicyIntrusionDetectionStateType.Deny, -} -}, - BypassTrafficSettings = -{ -new FirewallPolicyIntrusionDetectionBypassTrafficSpecifications() -{ -Name = "bypassRule1", -Description = "Rule 1", -Protocol = FirewallPolicyIntrusionDetectionProtocol.TCP, -SourceAddresses = -{ -"1.2.3.4" -}, -DestinationAddresses = -{ -"5.6.7.8" -}, -DestinationPorts = -{ -"*" -}, -} -}, - }, - }, - TransportSecurityCertificateAuthority = new FirewallPolicyCertificateAuthority() - { - KeyVaultSecretId = "https://kv/secret", - Name = "clientcert", - }, - SkuTier = FirewallPolicySkuTier.Premium, - Tags = -{ -["key1"] = "value1", -}, - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyWithDifferentValues() - { - // Example: Create FirewallPolicy with different values - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "firewallPolicy", new FirewallPolicyData(new AzureLocation("West US")) - { - StartupProbe = null, - ReadinessProbe = new Probe(false) - { - InitialDelaySeconds = 30, - PeriodSeconds = 10, - FailureThreshold = 3, - }, - DesiredStatusCode = new DesiredStatusCode(600), - ThreatIntelWhitelist = new FirewallPolicyThreatIntelWhitelist() - { - IpAddresses = -{ -IPAddress.Parse("20.3.4.5") -}, - Fqdns = -{ -"*.microsoft.com" -}, - }, - Insights = new FirewallPolicyInsights() - { - IsEnabled = true, - RetentionDays = 100, - LogAnalyticsResources = new FirewallPolicyLogAnalyticsResources() - { - Workspaces = -{ -new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "westus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace1"), -},new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "eastus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace2"), -} -}, - DefaultWorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/defaultWorkspace"), - }, - }, - SnatPrivateRanges = -{ -"IANAPrivateRanges" -}, - DnsSettings = new DnsSettings() - { - Servers = -{ -"30.3.4.5" -}, - EnableProxy = true, - RequireProxyForNetworkRules = false, - }, - IntrusionDetection = new FirewallPolicyIntrusionDetection() - { - Mode = FirewallPolicyIntrusionDetectionStateType.Alert, - Configuration = new FirewallPolicyIntrusionDetectionConfiguration() - { - SignatureOverrides = -{ -new FirewallPolicyIntrusionDetectionSignatureSpecification() -{ -Id = "2525004", -Mode = FirewallPolicyIntrusionDetectionStateType.Deny, -} -}, - BypassTrafficSettings = -{ -new FirewallPolicyIntrusionDetectionBypassTrafficSpecifications() -{ -Name = "bypassRule1", -Description = "Rule 1", -Protocol = FirewallPolicyIntrusionDetectionProtocol.TCP, -SourceAddresses = -{ -"1.2.3.4" -}, -DestinationAddresses = -{ -"5.6.7.8" -}, -DestinationPorts = -{ -"*" -}, -} -}, - }, - }, - TransportSecurityCertificateAuthority = new FirewallPolicyCertificateAuthority() - { - KeyVaultSecretId = "https://kv/secret", - Name = "clientcert", - }, - SkuTier = FirewallPolicySkuTier.Premium, - Tags = -{ -["key1"] = "value1", -}, - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Get FirewallPolicy - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await collection.ExistsAsync("firewallPolicy"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get FirewallPolicy - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await collection.GetAsync("firewallPolicy"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List all Firewall Policies for a given resource group - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Get FirewallPolicy - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetFirewallPolicies(); - await collection.GetIfExistsAsync("firewallPolicy"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyResourceMockTests.cs deleted file mode 100644 index 0464d283323..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyResourceMockTests.cs +++ /dev/null @@ -1,283 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for FirewallPolicyResource. - public partial class FirewallPolicyResourceMockTests : MockTestBase - { - public FirewallPolicyResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete Firewall Policy - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - await firewallPolicy.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get FirewallPolicy - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - await firewallPolicy.GetAsync(); - } - - [RecordedTest] - public async Task GetFirewallPolicies() - { - // Example: List all Firewall Policies for a given subscription - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetFirewallPoliciesAsync()) - { - } - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicy() - { - // Example: Create FirewallPolicy - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - await firewallPolicy.UpdateAsync(WaitUntil.Completed, new FirewallPolicyData(new AzureLocation("West US")) - { - StartupProbe = null, - ReadinessProbe = new Probe(false) - { - InitialDelaySeconds = 30, - PeriodSeconds = 10, - FailureThreshold = 3, - }, - DesiredStatusCode = DesiredStatusCode.TwoHundredTwo, - ThreatIntelWhitelist = new FirewallPolicyThreatIntelWhitelist() - { - IpAddresses = -{ -IPAddress.Parse("20.3.4.5") -}, - Fqdns = -{ -"*.microsoft.com" -}, - }, - Insights = new FirewallPolicyInsights() - { - IsEnabled = true, - RetentionDays = 100, - LogAnalyticsResources = new FirewallPolicyLogAnalyticsResources() - { - Workspaces = -{ -new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "westus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace1"), -},new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "eastus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace2"), -} -}, - DefaultWorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/defaultWorkspace"), - }, - }, - SnatPrivateRanges = -{ -"IANAPrivateRanges" -}, - DnsSettings = new DnsSettings() - { - Servers = -{ -"30.3.4.5" -}, - EnableProxy = true, - RequireProxyForNetworkRules = false, - }, - IntrusionDetection = new FirewallPolicyIntrusionDetection() - { - Mode = FirewallPolicyIntrusionDetectionStateType.Alert, - Configuration = new FirewallPolicyIntrusionDetectionConfiguration() - { - SignatureOverrides = -{ -new FirewallPolicyIntrusionDetectionSignatureSpecification() -{ -Id = "2525004", -Mode = FirewallPolicyIntrusionDetectionStateType.Deny, -} -}, - BypassTrafficSettings = -{ -new FirewallPolicyIntrusionDetectionBypassTrafficSpecifications() -{ -Name = "bypassRule1", -Description = "Rule 1", -Protocol = FirewallPolicyIntrusionDetectionProtocol.TCP, -SourceAddresses = -{ -"1.2.3.4" -}, -DestinationAddresses = -{ -"5.6.7.8" -}, -DestinationPorts = -{ -"*" -}, -} -}, - }, - }, - TransportSecurityCertificateAuthority = new FirewallPolicyCertificateAuthority() - { - KeyVaultSecretId = "https://kv/secret", - Name = "clientcert", - }, - SkuTier = FirewallPolicySkuTier.Premium, - Tags = -{ -["key1"] = "value1", -}, - }); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyWithDifferentValues() - { - // Example: Create FirewallPolicy with different values - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - await firewallPolicy.UpdateAsync(WaitUntil.Completed, new FirewallPolicyData(new AzureLocation("West US")) - { - StartupProbe = null, - ReadinessProbe = new Probe(false) - { - InitialDelaySeconds = 30, - PeriodSeconds = 10, - FailureThreshold = 3, - }, - DesiredStatusCode = new DesiredStatusCode(600), - ThreatIntelWhitelist = new FirewallPolicyThreatIntelWhitelist() - { - IpAddresses = -{ -IPAddress.Parse("20.3.4.5") -}, - Fqdns = -{ -"*.microsoft.com" -}, - }, - Insights = new FirewallPolicyInsights() - { - IsEnabled = true, - RetentionDays = 100, - LogAnalyticsResources = new FirewallPolicyLogAnalyticsResources() - { - Workspaces = -{ -new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "westus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace1"), -},new FirewallPolicyLogAnalyticsWorkspace() -{ -Region = "eastus", -WorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/workspace2"), -} -}, - DefaultWorkspaceIdId = new ResourceIdentifier("/subscriptions/subid/resourcegroups/rg1/providers/microsoft.operationalinsights/workspaces/defaultWorkspace"), - }, - }, - SnatPrivateRanges = -{ -"IANAPrivateRanges" -}, - DnsSettings = new DnsSettings() - { - Servers = -{ -"30.3.4.5" -}, - EnableProxy = true, - RequireProxyForNetworkRules = false, - }, - IntrusionDetection = new FirewallPolicyIntrusionDetection() - { - Mode = FirewallPolicyIntrusionDetectionStateType.Alert, - Configuration = new FirewallPolicyIntrusionDetectionConfiguration() - { - SignatureOverrides = -{ -new FirewallPolicyIntrusionDetectionSignatureSpecification() -{ -Id = "2525004", -Mode = FirewallPolicyIntrusionDetectionStateType.Deny, -} -}, - BypassTrafficSettings = -{ -new FirewallPolicyIntrusionDetectionBypassTrafficSpecifications() -{ -Name = "bypassRule1", -Description = "Rule 1", -Protocol = FirewallPolicyIntrusionDetectionProtocol.TCP, -SourceAddresses = -{ -"1.2.3.4" -}, -DestinationAddresses = -{ -"5.6.7.8" -}, -DestinationPorts = -{ -"*" -}, -} -}, - }, - }, - TransportSecurityCertificateAuthority = new FirewallPolicyCertificateAuthority() - { - KeyVaultSecretId = "https://kv/secret", - Name = "clientcert", - }, - SkuTier = FirewallPolicySkuTier.Premium, - Tags = -{ -["key1"] = "value1", -}, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupCollectionMockTests.cs deleted file mode 100644 index f6806d2c917..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupCollectionMockTests.cs +++ /dev/null @@ -1,398 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for FirewallPolicyRuleCollectionGroupCollection. - public partial class FirewallPolicyRuleCollectionGroupCollectionMockTests : MockTestBase - { - public FirewallPolicyRuleCollectionGroupCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyNatRuleCollectionGroup() - { - // Example: Create FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "ruleCollectionGroup1", new FirewallPolicyRuleCollectionGroupData() - { - Priority = 100, - RuleCollections = -{ -new FirewallPolicyNatRuleCollection() -{ -ActionType = FirewallPolicyNatRuleCollectionActionType.Dnat, -Rules = -{ -new NatRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP,FirewallPolicyRuleNetworkProtocol.UDP -}, -SourceAddresses = -{ -"2.2.2.2" -}, -DestinationAddresses = -{ -"152.23.32.23" -}, -DestinationPorts = -{ -"8080" -}, -TranslatedPort = "8080", -SourceIpGroups = -{ -}, -TranslatedFqdn = "internalhttp.server.net", -Name = "nat-rule1", -} -}, -Name = "Example-Nat-Rule-Collection", -Priority = 100, -} -}, - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyRuleCollectionGroup() - { - // Example: Create FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "ruleCollectionGroup1", new FirewallPolicyRuleCollectionGroupData() - { - Priority = 100, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new NetworkRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP -}, -SourceAddresses = -{ -"10.1.25.0/24" -}, -DestinationAddresses = -{ -"*" -}, -DestinationPorts = -{ -"*" -}, -Name = "network-rule1", -} -}, -Name = "Example-Filter-Rule-Collection", -Priority = 100, -} -}, - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyRuleCollectionGroupWithAllDefaultValues() - { - // Example: Create FirewallPolicyRuleCollectionGroup With All Default Values - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "ruleCollectionGroup1", new FirewallPolicyRuleCollectionGroupData()); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Create FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "ruleCollectionGroup1", new FirewallPolicyRuleCollectionGroupData() - { - Priority = 110, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new NetworkRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP -}, -DestinationPorts = -{ -"*" -}, -SourceIpGroups = -{ -"/subscriptions/subid/providers/Microsoft.Network/resourceGroup/rg1/ipGroups/ipGroups1" -}, -DestinationIpGroups = -{ -"/subscriptions/subid/providers/Microsoft.Network/resourceGroup/rg1/ipGroups/ipGroups2" -}, -Name = "network-1", -} -}, -Name = "Example-Filter-Rule-Collection", -} -}, - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Create FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "ruleCollectionGroup1", new FirewallPolicyRuleCollectionGroupData() - { - Priority = 110, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new ApplicationRule() -{ -SourceAddresses = -{ -"216.58.216.164","10.0.0.0/24" -}, -Protocols = -{ -new FirewallPolicyRuleApplicationProtocol() -{ -ProtocolType = FirewallPolicyRuleApplicationProtocolType.Https, -Port = 443, -} -}, -WebCategories = -{ -"Hacking" -}, -Name = "rule1", -Description = "Deny inbound rule", -} -}, -Name = "Example-Filter-Rule-Collection", -} -}, - }); - } - - [RecordedTest] - public async Task Exists_GetFirewallPolicyNatRuleCollectionGroup() - { - // Example: Get FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.ExistsAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task Exists_GetFirewallPolicyRuleCollectionGroup() - { - // Example: Get FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.ExistsAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task Exists_GetFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Get FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.ExistsAsync("ruleGroup1"); - } - - [RecordedTest] - public async Task Exists_GetFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Get FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.ExistsAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyNatRuleCollectionGroup() - { - // Example: Get FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroup() - { - // Example: Get FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Get FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetAsync("ruleGroup1"); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Get FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task GetAll_ListAllFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: List all FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetAll_ListAllFirewallPolicyRuleCollectionGroupsForAGivenFirewallPolicy() - { - // Example: List all FirewallPolicyRuleCollectionGroups for a given FirewallPolicy - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetAll_ListAllFirewallPolicyRuleCollectionGroupsWithIpGroupsForAGivenFirewallPolicy() - { - // Example: List all FirewallPolicyRuleCollectionGroups with IpGroups for a given FirewallPolicy - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists_GetFirewallPolicyNatRuleCollectionGroup() - { - // Example: Get FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetIfExistsAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task GetIfExists_GetFirewallPolicyRuleCollectionGroup() - { - // Example: Get FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetIfExistsAsync("ruleCollectionGroup1"); - } - - [RecordedTest] - public async Task GetIfExists_GetFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Get FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetIfExistsAsync("ruleGroup1"); - } - - [RecordedTest] - public async Task GetIfExists_GetFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Get FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyResourceId = FirewallPolicyResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy"); - FirewallPolicyResource firewallPolicy = GetArmClient().GetFirewallPolicyResource(firewallPolicyResourceId); - var collection = firewallPolicy.GetFirewallPolicyRuleCollectionGroups(); - await collection.GetIfExistsAsync("ruleCollectionGroup1"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupResourceMockTests.cs deleted file mode 100644 index fd186e955ee..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/FirewallPolicyRuleCollectionGroupResourceMockTests.cs +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for FirewallPolicyRuleCollectionGroupResource. - public partial class FirewallPolicyRuleCollectionGroupResourceMockTests : MockTestBase - { - public FirewallPolicyRuleCollectionGroupResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyNatRuleCollectionGroup() - { - // Example: Get FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.GetAsync(); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroup() - { - // Example: Get FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.GetAsync(); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Get FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.GetAsync(); - } - - [RecordedTest] - public async Task Get_GetFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Get FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.GetAsync(); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyNatRuleCollectionGroup() - { - // Example: Create FirewallPolicyNatRuleCollectionGroup - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.UpdateAsync(WaitUntil.Completed, new FirewallPolicyRuleCollectionGroupData() - { - Priority = 100, - RuleCollections = -{ -new FirewallPolicyNatRuleCollection() -{ -ActionType = FirewallPolicyNatRuleCollectionActionType.Dnat, -Rules = -{ -new NatRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP,FirewallPolicyRuleNetworkProtocol.UDP -}, -SourceAddresses = -{ -"2.2.2.2" -}, -DestinationAddresses = -{ -"152.23.32.23" -}, -DestinationPorts = -{ -"8080" -}, -TranslatedPort = "8080", -SourceIpGroups = -{ -}, -TranslatedFqdn = "internalhttp.server.net", -Name = "nat-rule1", -} -}, -Name = "Example-Nat-Rule-Collection", -Priority = 100, -} -}, - }); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyRuleCollectionGroup() - { - // Example: Create FirewallPolicyRuleCollectionGroup - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.UpdateAsync(WaitUntil.Completed, new FirewallPolicyRuleCollectionGroupData() - { - Priority = 100, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new NetworkRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP -}, -SourceAddresses = -{ -"10.1.25.0/24" -}, -DestinationAddresses = -{ -"*" -}, -DestinationPorts = -{ -"*" -}, -Name = "network-rule1", -} -}, -Name = "Example-Filter-Rule-Collection", -Priority = 100, -} -}, - }); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyRuleCollectionGroupWithAllDefaultValues() - { - // Example: Create FirewallPolicyRuleCollectionGroup With All Default Values - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.UpdateAsync(WaitUntil.Completed, new FirewallPolicyRuleCollectionGroupData()); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyRuleCollectionGroupWithIpGroups() - { - // Example: Create FirewallPolicyRuleCollectionGroup With IpGroups - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.UpdateAsync(WaitUntil.Completed, new FirewallPolicyRuleCollectionGroupData() - { - Priority = 110, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new NetworkRule() -{ -IpProtocols = -{ -FirewallPolicyRuleNetworkProtocol.TCP -}, -DestinationPorts = -{ -"*" -}, -SourceIpGroups = -{ -"/subscriptions/subid/providers/Microsoft.Network/resourceGroup/rg1/ipGroups/ipGroups1" -}, -DestinationIpGroups = -{ -"/subscriptions/subid/providers/Microsoft.Network/resourceGroup/rg1/ipGroups/ipGroups2" -}, -Name = "network-1", -} -}, -Name = "Example-Filter-Rule-Collection", -} -}, - }); - } - - [RecordedTest] - public async Task Update_CreateFirewallPolicyRuleCollectionGroupWithWebCategories() - { - // Example: Create FirewallPolicyRuleCollectionGroup With Web Categories - - ResourceIdentifier firewallPolicyRuleCollectionGroupResourceId = FirewallPolicyRuleCollectionGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "rg1", "firewallPolicy", "ruleCollectionGroup1"); - FirewallPolicyRuleCollectionGroupResource firewallPolicyRuleCollectionGroup = GetArmClient().GetFirewallPolicyRuleCollectionGroupResource(firewallPolicyRuleCollectionGroupResourceId); - await firewallPolicyRuleCollectionGroup.UpdateAsync(WaitUntil.Completed, new FirewallPolicyRuleCollectionGroupData() - { - Priority = 110, - RuleCollections = -{ -new FirewallPolicyFilterRuleCollection() -{ -ActionType = FirewallPolicyFilterRuleCollectionActionType.Deny, -Rules = -{ -new ApplicationRule() -{ -SourceAddresses = -{ -"216.58.216.164","10.0.0.0/24" -}, -Protocols = -{ -new FirewallPolicyRuleApplicationProtocol() -{ -ProtocolType = FirewallPolicyRuleApplicationProtocolType.Https, -Port = 443, -} -}, -WebCategories = -{ -"Hacking" -}, -Name = "rule1", -Description = "Deny inbound rule", -} -}, -Name = "Example-Filter-Rule-Collection", -} -}, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentCollectionMockTests.cs deleted file mode 100644 index aa534fa501e..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentCollectionMockTests.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for GuestConfigurationAssignmentCollection. - public partial class GuestConfigurationAssignmentCollectionMockTests : MockTestBase - { - public GuestConfigurationAssignmentCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate() - { - // Example: Create or update guest configuration assignment - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}", "00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName")); - var collection = GetArmClient().GetGuestConfigurationAssignments(scope); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "NotInstalledApplicationForWindows", new GuestConfigurationAssignmentData() - { - Properties = new GuestConfigurationAssignmentProperties() - { - Context = "Azure policy", - }, - Name = "NotInstalledApplicationForWindows", - Location = new AzureLocation("westcentralus"), - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Get a guest configuration assignment - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}", "00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName")); - var collection = GetArmClient().GetGuestConfigurationAssignments(scope); - await collection.ExistsAsync("SecureProtocol"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get a guest configuration assignment - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}", "00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName")); - var collection = GetArmClient().GetGuestConfigurationAssignments(scope); - await collection.GetAsync("SecureProtocol"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List all guest configuration assignments for a virtual machine - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}", "00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName")); - var collection = GetArmClient().GetGuestConfigurationAssignments(scope); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Get a guest configuration assignment - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}", "00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName")); - var collection = GetArmClient().GetGuestConfigurationAssignments(scope); - await collection.GetIfExistsAsync("SecureProtocol"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentResourceMockTests.cs deleted file mode 100644 index cb3a7f31846..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/GuestConfigurationAssignmentResourceMockTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for GuestConfigurationAssignmentResource. - public partial class GuestConfigurationAssignmentResourceMockTests : MockTestBase - { - public GuestConfigurationAssignmentResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete an guest configuration assignment - - ResourceIdentifier guestConfigurationAssignmentResourceId = GuestConfigurationAssignmentResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName", "SecureProtocol"); - GuestConfigurationAssignmentResource guestConfigurationAssignment = GetArmClient().GetGuestConfigurationAssignmentResource(guestConfigurationAssignmentResourceId); - await guestConfigurationAssignment.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get a guest configuration assignment - - ResourceIdentifier guestConfigurationAssignmentResourceId = GuestConfigurationAssignmentResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName", "SecureProtocol"); - GuestConfigurationAssignmentResource guestConfigurationAssignment = GetArmClient().GetGuestConfigurationAssignmentResource(guestConfigurationAssignmentResourceId); - await guestConfigurationAssignment.GetAsync(); - } - - [RecordedTest] - public async Task Update() - { - // Example: Create or update guest configuration assignment - - ResourceIdentifier guestConfigurationAssignmentResourceId = GuestConfigurationAssignmentResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "myResourceGroupName", "myVMName", "NotInstalledApplicationForWindows"); - GuestConfigurationAssignmentResource guestConfigurationAssignment = GetArmClient().GetGuestConfigurationAssignmentResource(guestConfigurationAssignmentResourceId); - await guestConfigurationAssignment.UpdateAsync(WaitUntil.Completed, new GuestConfigurationAssignmentData() - { - Properties = new GuestConfigurationAssignmentProperties() - { - Context = "Azure policy", - }, - Name = "NotInstalledApplicationForWindows", - Location = new AzureLocation("westcentralus"), - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmCollectionMockTests.cs deleted file mode 100644 index 6aab7cc42e0..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmCollectionMockTests.cs +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.Resources.Models; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for ManagedHsmCollection. - public partial class ManagedHsmCollectionMockTests : MockTestBase - { - public ManagedHsmCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate() - { - // Example: Create a new managed HSM Pool or update an existing managed HSM Pool - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetManagedHsms(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "hsm1", new ManagedHsmData(new AzureLocation("westus")) - { - Properties = new ManagedHsmProperties() - { - Settings = BinaryData.FromString("\"{\"config1\":\"value1\",\"config2\":8427,\"config3\":false,\"config4\":[\"1\",\"2\"],\"config5\":{\"inner\":\"something\"}}\""), - ProtectedSettings = BinaryData.FromObjectAsJson(new Dictionary() - { - ["protected1"] = "value2", - ["protected2"] = "10", - ["protected3"] = "false", - ["protected4"] = new object[] { "1", "2", "3" }, - ["protected5"] = new Dictionary() - { - ["protectedInner"] = "something else" - } - }), - RawMessage = Convert.FromBase64String("PFX-or-PEM-blob"), - TenantId = Guid.Parse("00000000-0000-0000-0000-000000000000"), - InitialAdminObjectIds = -{ -"00000000-0000-0000-0000-000000000000" -}, - EnableSoftDelete = true, - SoftDeleteRetentionInDays = 90, - EnablePurgeProtection = true, - NetworkAcls = new MhsmNetworkRuleSet() - { - VirtualNetworkRules = -{ -new WritableSubResource() -{ -Id = new ResourceIdentifier("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/hsm-group/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/default"), -} -}, - }, - }, - Sku = new ManagedHsmSku(ManagedHsmSkuFamily.B, ManagedHsmSkuName.StandardB1), - Tags = -{ -["Dept"] = "hsm", -["Environment"] = "dogfood", -}, - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Retrieve a managed HSM Pool - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetManagedHsms(); - await collection.ExistsAsync("hsm1"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a managed HSM Pool - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetManagedHsms(); - await collection.GetAsync("hsm1"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List managed HSM Pools in a resource group - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetManagedHsms(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Retrieve a managed HSM Pool - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetManagedHsms(); - await collection.GetIfExistsAsync("hsm1"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmResourceMockTests.cs deleted file mode 100644 index 7ad12425dcc..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/ManagedHsmResourceMockTests.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for ManagedHsmResource. - public partial class ManagedHsmResourceMockTests : MockTestBase - { - public ManagedHsmResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete a managed HSM Pool - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group", "hsm1"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - await managedHsm.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a managed HSM Pool - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group", "hsm1"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - await managedHsm.GetAsync(); - } - - [RecordedTest] - public async Task GetManagedHsms() - { - // Example: List managed HSM Pools in a subscription - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetManagedHsmsAsync()) - { - } - } - - [RecordedTest] - public async Task GetMHSMPrivateLinkResourcesByMhsmResource() - { - // Example: KeyVaultListPrivateLinkResources - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - await foreach (var _ in managedHsm.GetMHSMPrivateLinkResourcesByMhsmResourceAsync()) - { - } - } - - [RecordedTest] - public async Task Update() - { - // Example: Update an existing managed HSM Pool - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "hsm-group", "hsm1"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - await managedHsm.UpdateAsync(WaitUntil.Completed, new ManagedHsmData(new AzureLocation("placeholder")) - { - Tags = -{ -["Dept"] = "hsm", -["Environment"] = "dogfood", -["Slice"] = "A", -}, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSampleExtensionsMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSampleExtensionsMockTests.cs deleted file mode 100644 index 4a269df208e..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSampleExtensionsMockTests.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Collections.Generic; -using System.Net; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for MgmtMockAndSampleExtensions. - public partial class MgmtMockAndSampleExtensionsMockTests : MockTestBase - { - public MgmtMockAndSampleExtensionsMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task GetDeletedManagedHsms() - { - // Example: List deleted managed HSMs in the specified subscription - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetDeletedManagedHsmsAsync()) - { - } - } - - [RecordedTest] - public async Task GetDeletedVaults() - { - // Example: List deleted vaults in the specified subscription - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetDeletedVaultsAsync()) - { - } - } - - [RecordedTest] - public async Task CalculateTemplateHashDeployment() - { - // Example: Calculate template hash - - var tenantResource = GetArmClient().GetTenants().GetAllAsync().GetAsyncEnumerator().Current; - await tenantResource.CalculateTemplateHashDeploymentAsync(BinaryData.FromObjectAsJson(new Dictionary() - { - ["$schema"] = "http://schemas.management.azure.com/deploymentTemplate?api-version=2014-04-01-preview", - ["contentVersion"] = "1.0.0.0", - ["outputs"] = new Dictionary() - { - ["string"] = new Dictionary() - { - ["type"] = "string", - ["value"] = "myvalue" - } - }, - ["parameters"] = new Dictionary() - { - ["string"] = new Dictionary() - { - ["type"] = "string" - } - }, - ["resources"] = new object[] { }, - ["variables"] = new Dictionary() - { - ["array"] = new object[] { "1", "2", "3", "4" }, - ["bool"] = "true", - ["int"] = "42", - ["object"] = new Dictionary() - { - ["object"] = new Dictionary() - { - ["location"] = "West US", - ["vmSize"] = "Large" - } - }, - ["string"] = "string" - } - })); - } - - [RecordedTest] - public async Task GetTenantActivityLogs() - { - // Example: Get Tenant Activity Logs without filter or select - - var tenantResource = GetArmClient().GetTenants().GetAllAsync().GetAsyncEnumerator().Current; - await foreach (var _ in tenantResource.GetTenantActivityLogsAsync()) - { - } - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests.cs deleted file mode 100644 index 99909f2314a..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests.cs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for MgmtMockAndSamplePrivateEndpointConnectionCollection. - public partial class MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests : MockTestBase - { - public MgmtMockAndSamplePrivateEndpointConnectionCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate() - { - // Example: KeyVaultPutPrivateEndpointConnection - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - var collection = vault.GetMgmtMockAndSamplePrivateEndpointConnections(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "sample-pec", new MgmtMockAndSamplePrivateEndpointConnectionData() - { - Etag = "", - ConnectionState = new MgmtMockAndSamplePrivateLinkServiceConnectionState() - { - Status = MgmtMockAndSamplePrivateEndpointServiceConnectionStatus.Approved, - Description = "My name is Joe and I'm approving this.", - }, - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: KeyVaultGetPrivateEndpointConnection - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - var collection = vault.GetMgmtMockAndSamplePrivateEndpointConnections(); - await collection.ExistsAsync("sample-pec"); - } - - [RecordedTest] - public async Task Get() - { - // Example: KeyVaultGetPrivateEndpointConnection - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - var collection = vault.GetMgmtMockAndSamplePrivateEndpointConnections(); - await collection.GetAsync("sample-pec"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: KeyVaultListPrivateEndpointConnection - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - var collection = vault.GetMgmtMockAndSamplePrivateEndpointConnections(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: KeyVaultGetPrivateEndpointConnection - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - var collection = vault.GetMgmtMockAndSamplePrivateEndpointConnections(); - await collection.GetIfExistsAsync("sample-pec"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests.cs deleted file mode 100644 index b11da08eb01..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for MgmtMockAndSamplePrivateEndpointConnectionResource. - public partial class MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests : MockTestBase - { - public MgmtMockAndSamplePrivateEndpointConnectionResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: KeyVaultDeletePrivateEndpointConnection - - ResourceIdentifier mgmtMockAndSamplePrivateEndpointConnectionResourceId = MgmtMockAndSamplePrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault", "sample-pec"); - MgmtMockAndSamplePrivateEndpointConnectionResource mgmtMockAndSamplePrivateEndpointConnection = GetArmClient().GetMgmtMockAndSamplePrivateEndpointConnectionResource(mgmtMockAndSamplePrivateEndpointConnectionResourceId); - await mgmtMockAndSamplePrivateEndpointConnection.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: KeyVaultGetPrivateEndpointConnection - - ResourceIdentifier mgmtMockAndSamplePrivateEndpointConnectionResourceId = MgmtMockAndSamplePrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault", "sample-pec"); - MgmtMockAndSamplePrivateEndpointConnectionResource mgmtMockAndSamplePrivateEndpointConnection = GetArmClient().GetMgmtMockAndSamplePrivateEndpointConnectionResource(mgmtMockAndSamplePrivateEndpointConnectionResourceId); - await mgmtMockAndSamplePrivateEndpointConnection.GetAsync(); - } - - [RecordedTest] - public async Task Update() - { - // Example: KeyVaultPutPrivateEndpointConnection - - ResourceIdentifier mgmtMockAndSamplePrivateEndpointConnectionResourceId = MgmtMockAndSamplePrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault", "sample-pec"); - MgmtMockAndSamplePrivateEndpointConnectionResource mgmtMockAndSamplePrivateEndpointConnection = GetArmClient().GetMgmtMockAndSamplePrivateEndpointConnectionResource(mgmtMockAndSamplePrivateEndpointConnectionResourceId); - await mgmtMockAndSamplePrivateEndpointConnection.UpdateAsync(WaitUntil.Completed, new MgmtMockAndSamplePrivateEndpointConnectionData() - { - Etag = "", - ConnectionState = new MgmtMockAndSamplePrivateLinkServiceConnectionState() - { - Status = MgmtMockAndSamplePrivateEndpointServiceConnectionStatus.Approved, - Description = "My name is Joe and I'm approving this.", - }, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionCollectionMockTests.cs deleted file mode 100644 index df34da464ad..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionCollectionMockTests.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for MhsmPrivateEndpointConnectionCollection. - public partial class MhsmPrivateEndpointConnectionCollectionMockTests : MockTestBase - { - public MhsmPrivateEndpointConnectionCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate() - { - // Example: ManagedHsmPutPrivateEndpointConnection - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - var collection = managedHsm.GetMhsmPrivateEndpointConnections(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "sample-pec", new MhsmPrivateEndpointConnectionData(new AzureLocation("placeholder")) - { - PrivateLinkServiceConnectionState = new MhsmPrivateLinkServiceConnectionState() - { - Status = MgmtMockAndSamplePrivateEndpointServiceConnectionStatus.Approved, - Description = "My name is Joe and I'm approving this.", - }, - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: ManagedHsmGetPrivateEndpointConnection - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - var collection = managedHsm.GetMhsmPrivateEndpointConnections(); - await collection.ExistsAsync("sample-pec"); - } - - [RecordedTest] - public async Task Get() - { - // Example: ManagedHsmGetPrivateEndpointConnection - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - var collection = managedHsm.GetMhsmPrivateEndpointConnections(); - await collection.GetAsync("sample-pec"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List managed HSM Pools in a subscription - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - var collection = managedHsm.GetMhsmPrivateEndpointConnections(); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: ManagedHsmGetPrivateEndpointConnection - - ResourceIdentifier managedHsmResourceId = ManagedHsmResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm"); - ManagedHsmResource managedHsm = GetArmClient().GetManagedHsmResource(managedHsmResourceId); - var collection = managedHsm.GetMhsmPrivateEndpointConnections(); - await collection.GetIfExistsAsync("sample-pec"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionResourceMockTests.cs deleted file mode 100644 index 721a27b51be..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/MhsmPrivateEndpointConnectionResourceMockTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for MhsmPrivateEndpointConnectionResource. - public partial class MhsmPrivateEndpointConnectionResourceMockTests : MockTestBase - { - public MhsmPrivateEndpointConnectionResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: ManagedHsmDeletePrivateEndpointConnection - - ResourceIdentifier mhsmPrivateEndpointConnectionResourceId = MhsmPrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm", "sample-pec"); - MhsmPrivateEndpointConnectionResource mhsmPrivateEndpointConnection = GetArmClient().GetMhsmPrivateEndpointConnectionResource(mhsmPrivateEndpointConnectionResourceId); - await mhsmPrivateEndpointConnection.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: ManagedHsmGetPrivateEndpointConnection - - ResourceIdentifier mhsmPrivateEndpointConnectionResourceId = MhsmPrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm", "sample-pec"); - MhsmPrivateEndpointConnectionResource mhsmPrivateEndpointConnection = GetArmClient().GetMhsmPrivateEndpointConnectionResource(mhsmPrivateEndpointConnectionResourceId); - await mhsmPrivateEndpointConnection.GetAsync(); - } - - [RecordedTest] - public async Task Update() - { - // Example: ManagedHsmPutPrivateEndpointConnection - - ResourceIdentifier mhsmPrivateEndpointConnectionResourceId = MhsmPrivateEndpointConnectionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-mhsm", "sample-pec"); - MhsmPrivateEndpointConnectionResource mhsmPrivateEndpointConnection = GetArmClient().GetMhsmPrivateEndpointConnectionResource(mhsmPrivateEndpointConnectionResourceId); - await mhsmPrivateEndpointConnection.UpdateAsync(WaitUntil.Completed, new MhsmPrivateEndpointConnectionData(new AzureLocation("placeholder")) - { - PrivateLinkServiceConnectionState = new MhsmPrivateLinkServiceConnectionState() - { - Status = MgmtMockAndSamplePrivateEndpointServiceConnectionStatus.Approved, - Description = "My name is Joe and I'm approving this.", - }, - }); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentCollectionMockTests.cs deleted file mode 100644 index e4b660d5eed..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentCollectionMockTests.cs +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for RoleAssignmentCollection. - public partial class RoleAssignmentCollectionMockTests : MockTestBase - { - public RoleAssignmentCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate() - { - // Example: Create role assignment - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/{0}", "scope")); - var collection = GetArmClient().GetRoleAssignments(scope); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "roleAssignmentName", new RoleAssignmentCreateOrUpdateContent() - { - RoleDefinitionId = "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772", - PrincipalId = "d93a38bc-d029-4160-bfb0-fbda779ac214", - CanDelegate = false, - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Get role assignment by name - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/{0}", "scope")); - var collection = GetArmClient().GetRoleAssignments(scope); - await collection.ExistsAsync("roleAssignmentName"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get role assignment by name - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/{0}", "scope")); - var collection = GetArmClient().GetRoleAssignments(scope); - await collection.GetAsync("roleAssignmentName"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List role assignments for scope - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/{0}", "scope")); - var collection = GetArmClient().GetRoleAssignments(scope); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Get role assignment by name - - ResourceIdentifier scope = new ResourceIdentifier(string.Format("/{0}", "scope")); - var collection = GetArmClient().GetRoleAssignments(scope); - await collection.GetIfExistsAsync("roleAssignmentName"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentResourceMockTests.cs deleted file mode 100644 index 1dad6ee8768..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/RoleAssignmentResourceMockTests.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for RoleAssignmentResource. - public partial class RoleAssignmentResourceMockTests : MockTestBase - { - public RoleAssignmentResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete role assignment by name - - ResourceIdentifier roleAssignmentResourceId = RoleAssignmentResource.CreateResourceIdentifier("scope", "roleAssignmentName"); - RoleAssignmentResource roleAssignment = GetArmClient().GetRoleAssignmentResource(roleAssignmentResourceId); - await roleAssignment.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Get() - { - // Example: Get role assignment by name - - ResourceIdentifier roleAssignmentResourceId = RoleAssignmentResource.CreateResourceIdentifier("scope", "roleAssignmentName"); - RoleAssignmentResource roleAssignment = GetArmClient().GetRoleAssignmentResource(roleAssignmentResourceId); - await roleAssignment.GetAsync(); - } - - [RecordedTest] - public async Task Update() - { - // Example: Create role assignment - - ResourceIdentifier roleAssignmentResourceId = RoleAssignmentResource.CreateResourceIdentifier("scope", "roleAssignmentName"); - RoleAssignmentResource roleAssignment = GetArmClient().GetRoleAssignmentResource(roleAssignmentResourceId); - await roleAssignment.UpdateAsync(WaitUntil.Completed, new RoleAssignmentCreateOrUpdateContent() - { - RoleDefinitionId = "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/providers/Microsoft.Authorization/roleDefinitions/de139f84-1756-47ae-9be6-808fbbe84772", - PrincipalId = "d93a38bc-d029-4160-bfb0-fbda779ac214", - CanDelegate = false, - }); - } - - [RecordedTest] - public async Task Validate() - { - // Example: Validate role assignments for subscription - - string subscriptionId = "00000000-0000-0000-0000-000000000000"; - ResourceIdentifier roleAssignmentResourceId = RoleAssignmentResource.CreateResourceIdentifier($"/subscriptions/{subscriptionId}", "roleAssignmentId"); - RoleAssignmentResource roleAssignment = GetArmClient().GetRoleAssignmentResource(roleAssignmentResourceId); - await roleAssignment.ValidateAsync(); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultCollectionMockTests.cs deleted file mode 100644 index 6bc37eb9692..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultCollectionMockTests.cs +++ /dev/null @@ -1,185 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using System.Xml; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Models; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for VaultCollection. - public partial class VaultCollectionMockTests : MockTestBase - { - public VaultCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateANewVaultOrUpdateAnExistingVault() - { - // Example: Create a new vault or update an existing vault - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "sample-vault", new VaultCreateOrUpdateContent(new AzureLocation("westus"), new VaultProperties(Guid.Parse("00000000-0000-0000-0000-000000000000"), new MgmtMockAndSampleSku(MgmtMockAndSampleSkuFamily.A, MgmtMockAndSampleSkuName.Standard)) - { - Duration = XmlConvert.ToTimeSpan("P7D"), - CreateOn = DateTimeOffset.Parse("2017-05-04T07:12:28.191Z"), - AccessPolicies = -{ -new AccessPolicyEntry(Guid.Parse("00000000-0000-0000-0000-000000000000"),"00000000-0000-0000-0000-000000000000",new Permissions() -{ -Keys = -{ -KeyPermission.Encrypt,KeyPermission.Decrypt,KeyPermission.WrapKey,KeyPermission.UnwrapKey,KeyPermission.Sign,KeyPermission.Verify,KeyPermission.Get,KeyPermission.List,KeyPermission.Create,KeyPermission.Update,KeyPermission.Import,KeyPermission.Delete,KeyPermission.Backup,KeyPermission.Restore,KeyPermission.Recover,KeyPermission.Purge -}, -Secrets = -{ -SecretPermission.Get,SecretPermission.List,SecretPermission.Set,SecretPermission.Delete,SecretPermission.Backup,SecretPermission.Restore,SecretPermission.Recover,SecretPermission.Purge -}, -Certificates = -{ -CertificatePermission.Get,CertificatePermission.List,CertificatePermission.Delete,CertificatePermission.Create,CertificatePermission.Import,CertificatePermission.Update,CertificatePermission.Managecontacts,CertificatePermission.Getissuers,CertificatePermission.Listissuers,CertificatePermission.Setissuers,CertificatePermission.Deleteissuers,CertificatePermission.Manageissuers,CertificatePermission.Recover,CertificatePermission.Purge -}, -}) -}, - EnabledForDiskEncryption = true, - EnabledForTemplateDeployment = true, - PublicNetworkAccess = "Enabled", - }) - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - }); - } - - [RecordedTest] - public async Task CreateOrUpdate_CreateOrUpdateAVaultWithNetworkAcls() - { - // Example: Create or update a vault with network acls - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, "sample-vault", new VaultCreateOrUpdateContent(new AzureLocation("westus"), new VaultProperties(Guid.Parse("00000000-0000-0000-0000-000000000000"), new MgmtMockAndSampleSku(MgmtMockAndSampleSkuFamily.A, MgmtMockAndSampleSkuName.Standard)) - { - EnabledForDiskEncryption = true, - EnabledForTemplateDeployment = true, - NetworkAcls = new NetworkRuleSet() - { - Bypass = NetworkRuleBypassOption.AzureServices, - DefaultAction = NetworkRuleAction.Deny, - IpRules = -{ -new IPRule("124.56.78.91"),new IPRule("'10.91.4.0/24'") -}, - VirtualNetworkRules = -{ -new VirtualNetworkRule("/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/subnet1") -}, - }, - ReadWriteSingleStringPropertySomething = "test", - DeepSomething = "deep-value", - })); - } - - [RecordedTest] - public async Task CreateOrUpdate_VerifySampleGenCanHandleExamplesWithSomeParameterMissing() - { - // Example: Verify Sample-gen can handle examples with some parameter missing - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.CreateOrUpdateAsync(WaitUntil.Completed, default /* Warning: No value is provided for vaultName in example 'Verify Sample-gen can handle examples with some parameter missing'. Please consider adding a proper example value for it in swagger*/, new VaultCreateOrUpdateContent(new AzureLocation("westus"), new VaultProperties(Guid.Parse("00000000-0000-0000-0000-000000000000"), new MgmtMockAndSampleSku(MgmtMockAndSampleSkuFamily.A, MgmtMockAndSampleSkuName.Standard)) - { - Duration = XmlConvert.ToTimeSpan("P7D"), - CreateOn = DateTimeOffset.Parse("2017-05-04T07:12:28.191Z"), - AccessPolicies = -{ -new AccessPolicyEntry(Guid.Parse("00000000-0000-0000-0000-000000000000"),"00000000-0000-0000-0000-000000000000",new Permissions() -{ -Keys = -{ -KeyPermission.Encrypt,KeyPermission.Decrypt,KeyPermission.WrapKey,KeyPermission.UnwrapKey,KeyPermission.Sign,KeyPermission.Verify,KeyPermission.Get,KeyPermission.List,KeyPermission.Create,KeyPermission.Update,KeyPermission.Import,KeyPermission.Delete,KeyPermission.Backup,KeyPermission.Restore,KeyPermission.Recover,KeyPermission.Purge -}, -Secrets = -{ -SecretPermission.Get,SecretPermission.List,SecretPermission.Set,SecretPermission.Delete,SecretPermission.Backup,SecretPermission.Restore,SecretPermission.Recover,SecretPermission.Purge -}, -Certificates = -{ -CertificatePermission.Get,CertificatePermission.List,CertificatePermission.Delete,CertificatePermission.Create,CertificatePermission.Import,CertificatePermission.Update,CertificatePermission.Managecontacts,CertificatePermission.Getissuers,CertificatePermission.Listissuers,CertificatePermission.Setissuers,CertificatePermission.Deleteissuers,CertificatePermission.Manageissuers,CertificatePermission.Recover,CertificatePermission.Purge -}, -}) -}, - EnabledForDiskEncryption = true, - EnabledForTemplateDeployment = true, - PublicNetworkAccess = "Enabled", - }) - { - Identity = new ManagedServiceIdentity("SystemAssigned"), - }); - } - - [RecordedTest] - public async Task Exists() - { - // Example: Retrieve a vault - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.ExistsAsync("sample-vault"); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a vault - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.GetAsync("sample-vault"); - } - - [RecordedTest] - public async Task GetAll() - { - // Example: List vaults in the specified resource group - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await foreach (var _ in collection.GetAllAsync(top: 1)) - { - } - } - - [RecordedTest] - public async Task GetIfExists() - { - // Example: Retrieve a vault - - ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group"); - ResourceGroupResource resourceGroupResource = GetArmClient().GetResourceGroupResource(resourceGroupResourceId); - var collection = resourceGroupResource.GetVaults(); - await collection.GetIfExistsAsync("sample-vault"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultResourceMockTests.cs deleted file mode 100644 index 8a6dd6fdfef..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VaultResourceMockTests.cs +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; -using MgmtMockAndSample.Models; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for VaultResource. - public partial class VaultResourceMockTests : MockTestBase - { - public VaultResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task CheckNameAvailabilityVault() - { - // Example: Validate a vault name - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await subscriptionResource.CheckNameAvailabilityVaultAsync(new VaultCheckNameAvailabilityContent("sample-vault")); - } - - [RecordedTest] - public async Task Delete() - { - // Example: Delete a vault - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await vault.DeleteAsync(WaitUntil.Completed); - } - - [RecordedTest] - public async Task Disable() - { - // Example: Disable a vault - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await vault.DisableAsync(); - } - - [RecordedTest] - public async Task Get() - { - // Example: Retrieve a vault - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await vault.GetAsync(); - } - - [RecordedTest] - public async Task GetKeys() - { - // Example: List keys on an existing vault - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await foreach (var _ in vault.GetKeysAsync()) - { - } - } - - [RecordedTest] - public async Task GetPrivateLinkResources() - { - // Example: KeyVaultListPrivateLinkResources - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await foreach (var _ in vault.GetPrivateLinkResourcesAsync()) - { - } - } - - [RecordedTest] - public async Task GetVaults() - { - // Example: List vaults in the specified subscription - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - await foreach (var _ in subscriptionResource.GetVaultsAsync(top: 1)) - { - } - } - - [RecordedTest] - public async Task UpdateAccessPolicy() - { - // Example: Add an access policy, or update an access policy with new permissions - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await vault.UpdateAccessPolicyAsync(AccessPolicyUpdateKind.Add, new VaultAccessPolicyParameters(new VaultAccessPolicyProperties(new AccessPolicyEntry[] - { -new AccessPolicyEntry(Guid.Parse("00000000-0000-0000-0000-000000000000"),"00000000-0000-0000-0000-000000000000",new Permissions() -{ -Keys = -{ -KeyPermission.Encrypt -}, -Secrets = -{ -SecretPermission.Get -}, -Certificates = -{ -CertificatePermission.Get -}, -}) - }))); - } - - [RecordedTest] - public async Task Validate() - { - // Example: Validate an existing vault - - ResourceIdentifier vaultResourceId = VaultResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", "sample-resource-group", "sample-vault"); - VaultResource vault = GetArmClient().GetVaultResource(vaultResourceId); - await vault.ValidateAsync(); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageCollectionMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageCollectionMockTests.cs deleted file mode 100644 index c6d07b929fa..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageCollectionMockTests.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.Resources; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for VirtualMachineExtensionImageCollection. - public partial class VirtualMachineExtensionImageCollectionMockTests : MockTestBase - { - public VirtualMachineExtensionImageCollectionMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Exists_VirtualMachineExtensionImagesGetMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MaximumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaa"); - await collection.ExistsAsync("aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaa"); - } - - [RecordedTest] - public async Task Exists_VirtualMachineExtensionImagesGetMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MinimumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaa"); - await collection.ExistsAsync("aa", "aaa"); - } - - [RecordedTest] - public async Task Get_VirtualMachineExtensionImagesGetMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MaximumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaa"); - await collection.GetAsync("aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaa"); - } - - [RecordedTest] - public async Task Get_VirtualMachineExtensionImagesGetMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MinimumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaa"); - await collection.GetAsync("aa", "aaa"); - } - - [RecordedTest] - public async Task GetAll_VirtualMachineExtensionImagesListTypesMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_ListTypes_MaximumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaaaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetAll_VirtualMachineExtensionImagesListTypesMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_ListTypes_MinimumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaa"), "aa"); - await foreach (var _ in collection.GetAllAsync()) - { - } - } - - [RecordedTest] - public async Task GetAll_VirtualMachineExtensionImagesListVersionsMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_ListVersions_MaximumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaaaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaa"); - await foreach (var _ in collection.GetAllAsync("aaaaaaaaaaaaaaaaaa", filter: "aaaaaaaaaaaaaaaaaaaaaaaaa", top: 22, orderby: "a")) - { - } - } - - [RecordedTest] - public async Task GetAll_VirtualMachineExtensionImagesListVersionsMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_ListVersions_MinimumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); - await foreach (var _ in collection.GetAllAsync("aaaa")) - { - } - } - - [RecordedTest] - public async Task GetIfExists_VirtualMachineExtensionImagesGetMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MaximumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaa"); - await collection.GetIfExistsAsync("aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaa"); - } - - [RecordedTest] - public async Task GetIfExists_VirtualMachineExtensionImagesGetMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MinimumSet_Gen - - ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000"); - SubscriptionResource subscriptionResource = GetArmClient().GetSubscriptionResource(subscriptionResourceId); - var collection = subscriptionResource.GetVirtualMachineExtensionImages(new AzureLocation("aaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaa"); - await collection.GetIfExistsAsync("aa", "aaa"); - } - } -} diff --git a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageResourceMockTests.cs b/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageResourceMockTests.cs deleted file mode 100644 index 49adedd0423..00000000000 --- a/test/TestProjects/MgmtMockAndSample/tests/Generated/Mock/VirtualMachineExtensionImageResourceMockTests.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// - -#nullable disable - -using System; -using System.Net; -using System.Threading.Tasks; -using Azure.Core; -using Azure.Core.TestFramework; -using Azure.ResourceManager.TestFramework; - -namespace MgmtMockAndSample.Tests.Mock -{ - /// Test for VirtualMachineExtensionImageResource. - public partial class VirtualMachineExtensionImageResourceMockTests : MockTestBase - { - public VirtualMachineExtensionImageResourceMockTests(bool isAsync) : base(isAsync, RecordedTestMode.Record) - { - ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; - Environment.SetEnvironmentVariable("RESOURCE_MANAGER_URL", $"https://localhost:8443"); - } - - [RecordedTest] - public async Task Get_VirtualMachineExtensionImagesGetMaximumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MaximumSet_Gen - - ResourceIdentifier virtualMachineExtensionImageResourceId = VirtualMachineExtensionImageResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", new AzureLocation("aaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaa"); - VirtualMachineExtensionImageResource virtualMachineExtensionImage = GetArmClient().GetVirtualMachineExtensionImageResource(virtualMachineExtensionImageResourceId); - await virtualMachineExtensionImage.GetAsync(); - } - - [RecordedTest] - public async Task Get_VirtualMachineExtensionImagesGetMinimumSetGen() - { - // Example: VirtualMachineExtensionImages_Get_MinimumSet_Gen - - ResourceIdentifier virtualMachineExtensionImageResourceId = VirtualMachineExtensionImageResource.CreateResourceIdentifier("00000000-0000-0000-0000-000000000000", new AzureLocation("aaaaaaaaaaaaaa"), "aaaaaaaaaaaaaaaaaaaaaaaaaa", "aa", "aaa"); - VirtualMachineExtensionImageResource virtualMachineExtensionImage = GetArmClient().GetVirtualMachineExtensionImageResource(virtualMachineExtensionImageResourceId); - await virtualMachineExtensionImage.GetAsync(); - } - } -}