Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove all those related with mock #5080

Merged
merged 15 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/AutoRest.CSharp/Common/AutoRest/Plugins/CSharpGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,17 @@ public async Task<GeneratedCodeWorkspace> 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<MgmtOutputLibrary>(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<MgmtOutputLibrary>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/AutoRest.CSharp/DataPlane/AutoRest/DataPlaneTarget.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,8 +23,6 @@ public class MgmtDebugConfiguration

public bool ShowSerializedNames { get; }

public bool SkipCodeGen { get; }

public bool GenerateReport { get; }

public bool ReportOnly { get; }
Expand All @@ -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";
Expand All @@ -56,15 +52,13 @@ 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);

return new MgmtDebugConfiguration(
suppressListException: suppressListException,
showSerializedNames: showSerializedNames,
skipCodeGen: skipCodeGen,
generateReport: generateReport,
reportOnly: reportOnly,
reportFormat: reportFormat
Expand All @@ -76,7 +70,6 @@ internal static MgmtDebugConfiguration GetConfiguration(IPluginCommunication aut
return new MgmtDebugConfiguration(
suppressListException: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "suppress-list-exception")).GetAwaiter().GetResult(),
showSerializedNames: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "show-serialized-names")).GetAwaiter().GetResult(),
skipCodeGen: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "skip-codegen")).GetAwaiter().GetResult(),
generateReport: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "generate-report")).GetAwaiter().GetResult(),
reportOnly: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "report-only")).GetAwaiter().GetResult(),
reportFormat: autoRest.GetValue<JsonElement?>(string.Format(MgmtDebugOptionsFormat, "report-format")).GetAwaiter().GetResult()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> SkippedOperations { get; }
public bool ClearOutputFolder { get; }
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -57,7 +54,6 @@ public MgmtTestConfiguration(
return new MgmtTestConfiguration(
skippedOperations,
sourceCodePath: sourceCodePath,
mock: mock,
sample: sample,
outputFolder: testGenOutputFolder,
clearOutputFolder: testGenClearOutputFolder);
Expand Down Expand Up @@ -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);

Expand Down
50 changes: 10 additions & 40 deletions src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestOutputLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
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;

namespace AutoRest.CSharp.MgmtTest.AutoRest
{
internal class MgmtTestOutputLibrary
{
private readonly InputNamespace _inputNamespace;
private readonly InputNamespace _input;
private readonly HashSet<string> _skippedOperations;

public MgmtTestOutputLibrary(InputNamespace inputNamespace)
{
_inputNamespace = inputNamespace;
_input = inputNamespace;
_skippedOperations = new HashSet<string>(Configuration.MgmtTestConfiguration?.SkippedOperations ?? []);
}

Expand All @@ -30,19 +29,8 @@ public MgmtTestOutputLibrary(InputNamespace inputNamespace)

private IEnumerable<MgmtSampleProvider> EnsureSamples()
{
foreach ((var owner, var cases) in MockTestCases)
{
yield return new MgmtSampleProvider(owner, cases.Select(testCase => new Sample(testCase)));
}
}

private Dictionary<MgmtTypeProvider, List<MockTestCase>>? _mockTestCases;
internal Dictionary<MgmtTypeProvider, List<MockTestCase>> MockTestCases => _mockTestCases ??= EnsureMockTestCases();

private Dictionary<MgmtTypeProvider, List<MockTestCase>> EnsureMockTestCases()
{
var result = new Dictionary<MgmtTypeProvider, List<MockTestCase>>();
foreach (var client in _inputNamespace.Clients)
var result = new Dictionary<MgmtTypeProvider, List<Sample>>();
foreach (var client in _input.Clients)
{
foreach (var inputOperation in client.Operations)
{
Expand All @@ -62,14 +50,17 @@ private Dictionary<MgmtTypeProvider, List<MockTestCase>> 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<MgmtTypeProviderAndOperation> FindCarriersFromOperationId(string operationId)
Expand Down Expand Up @@ -107,26 +98,5 @@ private Dictionary<string, List<MgmtTypeProviderAndOperation>> EnsureOperationId

return _operationNameToProviders;
}

private MgmtMockTestProvider<MgmtExtensionWrapper>? _extensionWrapperMockTest;
public MgmtMockTestProvider<MgmtExtensionWrapper> ExtensionWrapperMockTest => _extensionWrapperMockTest ??= new MgmtMockTestProvider<MgmtExtensionWrapper>(MgmtContext.Library.ExtensionWrapper, Enumerable.Empty<MockTestCase>());

private IEnumerable<MgmtMockTestProvider<MgmtExtension>>? _extensionMockTests;
public IEnumerable<MgmtMockTestProvider<MgmtExtension>> ExtensionMockTests => _extensionMockTests ??= EnsureMockTestProviders<MgmtExtension>();

private IEnumerable<MgmtMockTestProvider<ResourceCollection>>? _resourceCollectionMockTests;
public IEnumerable<MgmtMockTestProvider<ResourceCollection>> ResourceCollectionMockTests => _resourceCollectionMockTests ??= EnsureMockTestProviders<ResourceCollection>();

private IEnumerable<MgmtMockTestProvider<Resource>>? _resourceMockTests;
public IEnumerable<MgmtMockTestProvider<Resource>> ResourceMockTests => _resourceMockTests ??= EnsureMockTestProviders<Resource>();

private IEnumerable<MgmtMockTestProvider<TProvider>> EnsureMockTestProviders<TProvider>() where TProvider : MgmtTypeProvider
{
foreach ((var owner, var testCases) in MockTestCases)
{
if (owner.GetType() == typeof(TProvider))
yield return new MgmtMockTestProvider<TProvider>((TProvider)owner, testCases);
}
}
}
}
34 changes: 0 additions & 34 deletions src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

This file was deleted.

Loading