Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class InputLibraryVisitorTests
public void Setup()
{
_mockInputLibrary = new Mock<InputLibrary>();
_mockInputLibrary.Setup(l => l.InputNamespace).Returns(InputFactory.Namespace("Sample"));
_mockPlugin = MockHelpers.LoadMockPlugin(
createInputLibrary: () => _mockInputLibrary.Object,
createClientCore: inputClient => new ClientProvider(inputClient),
packageName: "Sample");
createClientCore: inputClient => new ClientProvider(inputClient));
_mockVisitor = new Mock<ScmLibraryVisitor> { CallBase = true };
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public static Mock<ScmCodeModelPlugin> LoadMockPlugin(
ClientResponseApi? clientResponseApi = null,
ClientPipelineApi? clientPipelineApi = null,
HttpMessageApi? httpMessageApi = null,
Func<InputAuth>? auth = null,
string? packageName = null)
Func<InputAuth>? auth = null)
{
IReadOnlyList<string> inputNsApiVersions = apiVersions?.Invoke() ?? [];
IReadOnlyList<InputEnumType> inputNsEnums = inputEnums?.Invoke() ?? [];
Expand Down Expand Up @@ -104,11 +103,6 @@ public static Mock<ScmCodeModelPlugin> LoadMockPlugin(
mockTypeFactory.Protected().Setup<ClientProvider?>("CreateClientCore", ItExpr.IsAny<InputClient>()).Returns(createClientCore);
}

if (packageName is not null)
{
mockTypeFactory.Setup(p => p.PackageName).Returns(packageName);
}

// initialize the mock singleton instance of the plugin
var codeModelInstance = typeof(CodeModelPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
var clientModelInstance = typeof(ScmCodeModelPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected override TypeProvider[] BuildSerializationProviders()
}
protected override string BuildNamespace() => string.IsNullOrEmpty(_inputType.Namespace) ?
// TODO - this should not be necessary as every enum should have a namespace https://github.com/Azure/typespec-azure/issues/2210
CodeModelPlugin.Instance.TypeFactory.PackageName : // we default to this model namespace when the namespace is empty
CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace : // we default to this model namespace when the namespace is empty
CodeModelPlugin.Instance.TypeFactory.GetCleanNameSpace(_inputType.Namespace);

protected override bool GetIsEnum() => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public ModelProvider? BaseModelProvider

protected override string BuildNamespace() => string.IsNullOrEmpty(_inputModel.Namespace) ?
// TODO remove null check once https://github.com/Azure/typespec-azure/issues/2209 is fixed.
CodeModelPlugin.Instance.TypeFactory.PackageName :
CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace :
CodeModelPlugin.Instance.TypeFactory.GetCleanNameSpace(_inputModel.Namespace);

protected override CSharpType? GetBaseType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ this is EnumProvider ||
protected virtual bool GetIsEnum() => false;
public bool IsEnum => GetIsEnum();

protected virtual string BuildNamespace() => CodeModelPlugin.Instance.TypeFactory.PackageName;
protected virtual string BuildNamespace() => CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace;

private TypeSignatureModifiers? _declarationModifiers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private bool TryGetName(ISymbol symbol, [NotNullWhen(true)] out string? name)
private async Task<Compilation?> LoadBaselineContract()
{
string fullPath;
string projectFilePath = Path.GetFullPath(Path.Combine(CodeModelPlugin.Instance.Configuration.ProjectDirectory, $"{CodeModelPlugin.Instance.TypeFactory.PackageName}.csproj"));
string projectFilePath = Path.GetFullPath(Path.Combine(CodeModelPlugin.Instance.Configuration.ProjectDirectory, $"{CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace}.csproj"));
if (!File.Exists(projectFilePath))
return null;

Expand All @@ -106,15 +106,15 @@ private bool TryGetName(ISymbol symbol, [NotNullWhen(true)] out string? name)
if (baselineVersion is not null)
{
var nugetGlobalPackageFolder = SettingsUtility.GetGlobalPackagesFolder(new NullSettings());
var nugetFolder = Path.Combine(nugetGlobalPackageFolder, CodeModelPlugin.Instance.TypeFactory.PackageName.ToLowerInvariant(), baselineVersion, "lib", "netstandard2.0");
fullPath = Path.Combine(nugetFolder, $"{CodeModelPlugin.Instance.TypeFactory.PackageName}.dll");
var nugetFolder = Path.Combine(nugetGlobalPackageFolder, CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace.ToLowerInvariant(), baselineVersion, "lib", "netstandard2.0");
fullPath = Path.Combine(nugetFolder, $"{CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace}.dll");
if (File.Exists(fullPath))
{
return await GeneratedCodeWorkspace.CreatePreviousContractFromDll(Path.Combine(nugetFolder, $"{CodeModelPlugin.Instance.TypeFactory.PackageName}.xml"), fullPath);
return await GeneratedCodeWorkspace.CreatePreviousContractFromDll(Path.Combine(nugetFolder, $"{CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace}.xml"), fullPath);
}
else
{
throw new InvalidOperationException($"Can't find Baseline contract assembly ({CodeModelPlugin.Instance.TypeFactory.PackageName}@{baselineVersion}) from Nuget Global Package Folder at {fullPath}. " +
throw new InvalidOperationException($"Can't find Baseline contract assembly ({CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace}@{baselineVersion}) from Nuget Global Package Folder at {fullPath}. " +
$"Please make sure the baseline nuget package has been installed properly");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ public EnumCacheKey(InputEnumType enumType, TypeProvider? declaringType)
}
}

private string? _packageName;
public virtual string PackageName => _packageName ??= GetCleanNameSpace(CodeModelPlugin.Instance.InputLibrary.InputNamespace.Name);
private string? _primaryNamespace;
public string PrimaryNamespace => _primaryNamespace ??= GetCleanNameSpace(CodeModelPlugin.Instance.InputLibrary.InputNamespace.Name);

public string GetCleanNameSpace(string clientNamespace)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public void TestParseConfig_AdditionalConfigOptions()

bool unknownBoolValue = additionalConfigOptions["unknown-bool-property"].ToObjectFromJson<bool>();
Assert.AreEqual(true, unknownBoolValue);

Assert.AreEqual("libraryName", CodeModelPlugin.Instance.Configuration.PackageName);
Assert.AreEqual("Sample", CodeModelPlugin.Instance.TypeFactory.PrimaryNamespace);
}

[Test]
Expand Down