Skip to content

Commit

Permalink
fb
Browse files Browse the repository at this point in the history
  • Loading branch information
YunchuWang committed Jan 15, 2025
1 parent e0bd4e2 commit 5b4f648
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 38 deletions.
8 changes: 1 addition & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'# Remove the line below if you want to inherit .editorconfig settings from higher directories
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# XML project files
Expand Down Expand Up @@ -232,9 +232,3 @@ dotnet_diagnostic.SA1400.severity = none # Access modifier must be declared
dotnet_diagnostic.SA1402.severity = none # File may only contain a single type
dotnet_diagnostic.SA1633.severity = warning # File must have header -- TODO: replace with IDE0073 eventually
dotnet_diagnostic.SA1649.severity = none # File name must match type name

# Enforce explicit types instead of `var`
dotnet_style_prefer_var_for_built_in_types = false:error
dotnet_style_prefer_var_for_simple_types = false:error
dotnet_style_prefer_var_when_type_is_apparent = false:error
dotnet_style_prefer_var_when_type_is_not_apparent = false:error
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static DurableTaskSchedulerClientOptions FromConnectionString(string conn
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
/// <returns>A configured <see cref="GrpcChannel"/> instance that can be used to make gRPC calls.</returns>
public GrpcChannel CreateChannel()
internal GrpcChannel CreateChannel()
{
Verify.NotNull(this.EndpointAddress, nameof(this.EndpointAddress));
Verify.NotNull(this.TaskHubName, nameof(this.TaskHubName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static DurableTaskSchedulerWorkerOptions FromConnectionString(string conn
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
/// <returns>A configured <see cref="GrpcChannel"/> instance that can be used to make gRPC calls.</returns>
public GrpcChannel CreateChannel()
internal GrpcChannel CreateChannel()
{
Verify.NotNull(this.EndpointAddress, nameof(this.EndpointAddress));
Verify.NotNull(this.TaskHubName, nameof(this.TaskHubName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void UseDurableTaskScheduler_WithEndpointAndCredential_ShouldConfigureCor
options.Should().NotBeNull();

// Validate the configured options
var clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
DurableTaskSchedulerClientOptions clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
clientOptions.EndpointAddress.Should().Be(ValidEndpoint);
clientOptions.TaskHubName.Should().Be(ValidTaskHub);
clientOptions.Credential.Should().BeOfType<DefaultAzureCredential>();
Expand All @@ -59,7 +59,7 @@ public void UseDurableTaskScheduler_WithConnectionString_ShouldConfigureCorrectl
options.Should().NotBeNull();

// Validate the configured options
var clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
DurableTaskSchedulerClientOptions clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
clientOptions.EndpointAddress.Should().Be(ValidEndpoint);
clientOptions.TaskHubName.Should().Be(ValidTaskHub);
clientOptions.Credential.Should().BeOfType<DefaultAzureCredential>();
Expand All @@ -68,7 +68,7 @@ public void UseDurableTaskScheduler_WithConnectionString_ShouldConfigureCorrectl
[Theory]
[InlineData(null, "testhub")]
[InlineData("myaccount.westus3.durabletask.io", null)]
public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowArgumentNullException(string endpoint, string taskHub)
public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowOptionsValidationException(string endpoint, string taskHub)
{
// Arrange
ServiceCollection services = new ServiceCollection();
Expand All @@ -77,22 +77,18 @@ public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowArgumentNullEx
DefaultAzureCredential credential = new DefaultAzureCredential();

// Act
Action action = () => mockBuilder.Object.UseDurableTaskScheduler(endpoint, taskHub, credential);
mockBuilder.Object.UseDurableTaskScheduler(endpoint, taskHub, credential);
ServiceProvider provider = services.BuildServiceProvider();

// Assert
action.Should().NotThrow(); // The validation happens when building the service provider

if (endpoint == null || taskHub == null)
{
ServiceProvider provider = services.BuildServiceProvider();
OptionsValidationException ex = Assert.Throws<OptionsValidationException>(() =>
{
DurableTaskSchedulerClientOptions options = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
});
Assert.Contains(endpoint == null ? "EndpointAddress" : "TaskHubName", ex.Message);
}
var action = () => provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
action.Should().Throw<OptionsValidationException>()
.WithMessage(endpoint == null
? "DataAnnotation validation failed for 'DurableTaskSchedulerClientOptions' members: 'EndpointAddress' with the error: 'Endpoint address is required'."
: "DataAnnotation validation failed for 'DurableTaskSchedulerClientOptions' members: 'TaskHubName' with the error: 'Task hub name is required'.");
}


[Fact]
public void UseDurableTaskScheduler_WithNullCredential_ShouldSucceed()
{
Expand All @@ -108,7 +104,7 @@ public void UseDurableTaskScheduler_WithNullCredential_ShouldSucceed()

// Validate the configured options
ServiceProvider provider = services.BuildServiceProvider();
var clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
DurableTaskSchedulerClientOptions clientOptions = provider.GetRequiredService<IOptions<DurableTaskSchedulerClientOptions>>().Value;
clientOptions.EndpointAddress.Should().Be(ValidEndpoint);
clientOptions.TaskHubName.Should().Be(ValidTaskHub);
clientOptions.Credential.Should().BeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void UseDurableTaskScheduler_WithConnectionString_ShouldConfigureCorrectl
[Theory]
[InlineData(null, "testhub")]
[InlineData("myaccount.westus3.durabletask.io", null)]
public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowArgumentNullException(string endpoint, string taskHub)
public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowOptionsValidationException(string endpoint, string taskHub)
{
// Arrange
ServiceCollection services = new ServiceCollection();
Expand All @@ -81,20 +81,15 @@ public void UseDurableTaskScheduler_WithNullParameters_ShouldThrowArgumentNullEx
DefaultAzureCredential credential = new DefaultAzureCredential();

// Act
Action action = () => mockBuilder.Object.UseDurableTaskScheduler(endpoint, taskHub, credential);
mockBuilder.Object.UseDurableTaskScheduler(endpoint, taskHub, credential);
ServiceProvider provider = services.BuildServiceProvider();

// Assert
action.Should().NotThrow(); // The validation happens when building the service provider

if (endpoint == null || taskHub == null)
{
ServiceProvider provider = services.BuildServiceProvider();
OptionsValidationException ex = Assert.Throws<OptionsValidationException>(() =>
{
DurableTaskSchedulerWorkerOptions options = provider.GetRequiredService<IOptions<DurableTaskSchedulerWorkerOptions>>().Value;
});
Assert.Contains(endpoint == null ? "EndpointAddress" : "TaskHubName", ex.Message);
}
var action = () => provider.GetRequiredService<IOptions<DurableTaskSchedulerWorkerOptions>>().Value;
action.Should().Throw<OptionsValidationException>()
.WithMessage(endpoint == null
? "DataAnnotation validation failed for 'DurableTaskSchedulerWorkerOptions' members: 'EndpointAddress' with the error: 'Endpoint address is required'."
: "DataAnnotation validation failed for 'DurableTaskSchedulerWorkerOptions' members: 'TaskHubName' with the error: 'Task hub name is required'.");
}

[Fact]
Expand Down

0 comments on commit 5b4f648

Please sign in to comment.