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 @@ -70,7 +70,7 @@ internal ClientSettingsProvider(InputClient inputClient, ClientProvider clientPr
internal IReadOnlyList<ParameterProvider> OtherRequiredParams { get; }

protected override FormattableString BuildDescription()
=> $"Represents the settings used to configure a <see cref=\"{_clientProvider.Name}\"/> that can be loaded from an <see cref=\"IConfigurationSection\"/>.";
=> $"Represents the settings used to configure a {_clientProvider.Type:C} that can be loaded from an {IConfigurationSectionType:C}.";

protected override string BuildRelativeFilePath() => Path.Combine("src", "Generated", $"{Name}.cs");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1140,5 +1140,42 @@ await MockHelpers.LoadMockGeneratorAsync(
Assert.IsTrue(bodyString.Contains("TenantId"),
"BindCore should bind the non-credential parameter 'TenantId'");
}

[Test]
public async Task TestGeneratedSettings_WithCustomizedBindCore()
{
await MockHelpers.LoadMockGeneratorAsync(
compilation: async () => await Helpers.GetCompilationFromDirectoryAsync(),
configuration: "{\"disable-xml-docs\": false, \"package-name\": \"Sample.Namespace\"}");

var inputParameters = new[]
{
InputFactory.EndpointParameter(
"endpoint",
InputPrimitiveType.Url,
scope: InputParameterScope.Client,
isEndpoint: true)
};
var client = InputFactory.Client("TestClient", clientNamespace: "SampleNamespace", parameters: inputParameters);
var clientProvider = ScmCodeModelGenerator.Instance.TypeFactory.CreateClient(client);
Assert.IsNotNull(clientProvider);

var settingsProvider = clientProvider!.ClientSettings;
Assert.IsNotNull(settingsProvider);

// BindCore is overridden in custom code, so it should not be generated.
var bindCoreMethod = settingsProvider!.Methods.FirstOrDefault(m => m.Signature.Name == "BindCore");
Assert.IsNull(bindCoreMethod, "BindCore should not be generated when it is overridden in custom code");

var writer = new TypeProviderWriter(settingsProvider);
var file = writer.Write();

// Validate the full generated output. Even though BindCore (the only other
// reference to IConfigurationSection) is removed via custom code, the type
// description still references IConfigurationSection, so the
// Microsoft.Extensions.Configuration using must still be emitted.
Assert.AreEqual(Helpers.GetExpectedFromFile(), file.Content);
StringAssert.Contains("using Microsoft.Extensions.Configuration;", file.Content);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel.Primitives;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;

namespace SampleNamespace
{
/// <summary> Represents the settings used to configure a <see cref="global::SampleNamespace.TestClient"/> that can be loaded from an <see cref="global::Microsoft.Extensions.Configuration.IConfigurationSection"/>. </summary>
[global::System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SCME0002")]
public partial class TestClientSettings : global::System.ClientModel.Primitives.ClientSettings
{
/// <summary> Gets or sets the Endpoint. </summary>
public global::System.Uri Endpoint { get; set; }

/// <summary> Gets or sets the Options. </summary>
public global::SampleNamespace.TestClientOptions Options { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#nullable disable

using Microsoft.Extensions.Configuration;

namespace SampleNamespace
{
public partial class TestClientSettings
{
protected override void BindCore(IConfigurationSection section) { }
}
}
Loading