-
Notifications
You must be signed in to change notification settings - Fork 1
V9.0.0/host consistency and httpcontext improvement #15
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
Changes from all commits
45a5477
aa29240
533a21a
69a0a0e
f120842
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||
| using System; | ||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||
| using Microsoft.Extensions.Configuration; | ||||||||||||||||||||
| using Microsoft.Extensions.DependencyInjection; | ||||||||||||||||||||
| using Microsoft.Extensions.Hosting; | ||||||||||||||||||||
|
|
@@ -12,6 +13,8 @@ namespace Codebelt.Extensions.Xunit.Hosting | |||||||||||||||||||
| /// <seealso cref="IHostFixture" /> | ||||||||||||||||||||
| public class HostFixture : IDisposable, IHostFixture | ||||||||||||||||||||
| { | ||||||||||||||||||||
| private readonly object _lock = new(); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||
| /// Initializes a new instance of the <see cref="HostFixture"/> class. | ||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||
|
|
@@ -54,13 +57,22 @@ public virtual void ConfigureHost(Test hostTest) | |||||||||||||||||||
| ConfigureServicesCallback(services); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ConfigureHostCallback(hb); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| #if NET9_0_OR_GREATER | ||||||||||||||||||||
| hb.UseDefaultServiceProvider(o => o.ValidateScopes = false); // this is by intent | ||||||||||||||||||||
| hb.UseDefaultServiceProvider(o => | ||||||||||||||||||||
| { | ||||||||||||||||||||
| o.ValidateOnBuild = true; | ||||||||||||||||||||
| o.ValidateScopes = true; | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| #endif | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Host = hb.Build(); | ||||||||||||||||||||
| ConfigureHostCallback(hb); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| var host = hb.Build(); | ||||||||||||||||||||
| Task.Run(() => host.StartAsync().ConfigureAwait(false)) | ||||||||||||||||||||
| .ConfigureAwait(false) | ||||||||||||||||||||
| .GetAwaiter() | ||||||||||||||||||||
| .GetResult(); | ||||||||||||||||||||
| Host = host; | ||||||||||||||||||||
|
Comment on lines
+70
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify host startup to avoid unnecessary The current implementation wraps Apply this diff to simplify the host startup: var host = hb.Build();
-Task.Run(() => host.StartAsync().ConfigureAwait(false))
- .ConfigureAwait(false)
- .GetAwaiter()
- .GetResult();
+host.StartAsync().GetAwaiter().GetResult();
Host = host;📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||
|
|
@@ -185,12 +197,16 @@ public void Dispose() | |||||||||||||||||||
| protected void Dispose(bool disposing) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| if (Disposed) { return; } | ||||||||||||||||||||
| if (disposing) | ||||||||||||||||||||
| lock (_lock) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| OnDisposeManagedResources(); | ||||||||||||||||||||
| if (Disposed) { return; } | ||||||||||||||||||||
| if (disposing) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| OnDisposeManagedResources(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| OnDisposeUnmanagedResources(); | ||||||||||||||||||||
| Disposed = true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| OnDisposeUnmanagedResources(); | ||||||||||||||||||||
| Disposed = true; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| using System.Linq; | ||||||||||||||||||||||||||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Codebelt.Extensions.Xunit.Hosting.AspNetCore.Assets; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Codebelt.Extensions.Xunit.Hosting.AspNetCore.Http; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Cuemon.Extensions.IO; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Cuemon.Messaging; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Builder; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.AspNetCore.Http; | ||||||||||||||||||||||||||||||||||||||||||||||
| using Microsoft.Extensions.DependencyInjection; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,8 +35,8 @@ public async Task ShouldHaveResultOfBoolMiddlewareInBody() | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal("Hello awesome developers!", context!.Response.Body.ToEncodedString(o => o.LeaveOpen = true)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| var logger = _pipeline.ApplicationServices.GetRequiredService<ILogger<AspNetCoreHostTestTest>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| logger.LogInformation("Hello from {0}", nameof(ShouldHaveResultOfBoolMiddlewareInBody)); | ||||||||||||||||||||||||||||||||||||||||||||||
| var logger = _pipeline.ApplicationServices.GetRequiredService<ILogger<AspNetCoreHostTestTest>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| logger.LogInformation("Hello from {0}", nameof(ShouldHaveResultOfBoolMiddlewareInBody)); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| await pipeline(context); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -50,14 +50,77 @@ public async Task ShouldHaveResultOfBoolMiddlewareInBody() | |||||||||||||||||||||||||||||||||||||||||||||
| Assert.False(options.Value.F); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| #if NET9_0_OR_GREATER | ||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||
| public void ShouldThrowInvalidOperationException_BecauseOneOfTheServicesIsScoped() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| var ex = Assert.Throws<InvalidOperationException>(() => _provider.GetServices<ICorrelationToken>()); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLine(ex.Message); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Contains("from root provider because it requires scoped service", ex.Message); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve Exception Message Assertion for Robustness When asserting on exception messages, consider that they may vary between .NET versions or due to localization. To make the test more robust, use culture-invariant checks or assert on exception properties if available. Consider modifying the assertion as follows: -Assert.Contains("from root provider because it requires scoped service", ex.Message);
+Assert.Contains("requires scoped service", ex.Message, StringComparison.OrdinalIgnoreCase);Alternatively, if the exception provides specific properties or error codes, assert on those to avoid dependency on message text. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||
| public void ShouldHaveAccessToCorrelationTokens_UsingScopedProvider() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| using var scope = _provider.CreateScope(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| var firstRequest = scope.ServiceProvider.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||
| var secondRequest = scope.ServiceProvider.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLine("----"); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLines(firstRequest); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLine("----"); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLines(secondRequest); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(3, firstRequest.Count); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(3, secondRequest.Count); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Same(firstRequest[0], secondRequest[0]); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.NotSame(firstRequest[1], secondRequest[1]); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Same(firstRequest[2], secondRequest[2]); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(firstRequest[0].CorrelationId, secondRequest[0].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.NotEqual(firstRequest[1].CorrelationId, secondRequest[1].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(firstRequest[2].CorrelationId, secondRequest[2].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||
| public void ShouldHaveAccessToCorrelationTokens_UsingRequestServices() // reference: https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http/src/Features/RequestServicesFeature.cs | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| var context = _provider.GetRequiredService<IHttpContextAccessor>().HttpContext!; | ||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid Using the Null-Forgiving Operator Using the null-forgiving operator Consider modifying the code: -var context = _provider.GetRequiredService<IHttpContextAccessor>().HttpContext!;
+var httpContextAccessor = _provider.GetRequiredService<IHttpContextAccessor>();
+Assert.NotNull(httpContextAccessor.HttpContext);
+var context = httpContextAccessor.HttpContext!;This way, the test will explicitly assert that 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| var firstRequest = context.RequestServices.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||
| var secondRequest = context.RequestServices.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLine("----"); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLines(firstRequest); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLine("----"); | ||||||||||||||||||||||||||||||||||||||||||||||
| TestOutput.WriteLines(secondRequest); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(3, firstRequest.Count); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(3, secondRequest.Count); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Same(firstRequest[0], secondRequest[0]); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.NotSame(firstRequest[1], secondRequest[1]); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Same(firstRequest[2], secondRequest[2]); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(firstRequest[0].CorrelationId, secondRequest[0].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.NotEqual(firstRequest[1].CorrelationId, secondRequest[1].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal(firstRequest[2].CorrelationId, secondRequest[2].CorrelationId); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||
| public void ShouldLogToXunitTestLogging() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| var context = _provider.GetRequiredService<IHttpContextAccessor>().HttpContext; | ||||||||||||||||||||||||||||||||||||||||||||||
| var logger = _pipeline.ApplicationServices.GetRequiredService<ILogger<AspNetCoreHostTestTest>>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| logger.LogInformation("Hello from {0}", nameof(ShouldLogToXunitTestLogging)); | ||||||||||||||||||||||||||||||||||||||||||||||
| var store = _pipeline.ApplicationServices.GetRequiredService<ILogger<AspNetCoreHostTestTest>>().GetTestStore(); | ||||||||||||||||||||||||||||||||||||||||||||||
| var entry = store.Query(entry => entry.Message.Contains("Hello from", StringComparison.OrdinalIgnoreCase)).SingleOrDefault(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Assert.NotNull(entry); | ||||||||||||||||||||||||||||||||||||||||||||||
| Assert.Equal("Information: Hello from ShouldLogToXunitTestLogging", entry.Message); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -70,7 +133,7 @@ public override void ConfigureApplication(IApplicationBuilder app) | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public override void ConfigureServices(IServiceCollection services) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddTransient<IHttpContextAccessor, FakeHttpContextAccessor>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddFakeHttpContextAccessor(); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.Configure<BoolOptions>(o => | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| o.A = true; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -79,6 +142,10 @@ public override void ConfigureServices(IServiceCollection services) | |||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddXunitTestLoggingOutputHelperAccessor(); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddXunitTestLogging(TestOutput); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| services.AddSingleton<ICorrelationToken, SingletonCorrelation>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddTransient<ICorrelationToken, TransientCorrelation>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| services.AddScoped<ICorrelationToken, ScopedCorrelation>(); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Cuemon.Messaging; | ||
|
|
||
| namespace Codebelt.Extensions.Xunit.Hosting.AspNetCore.Assets | ||
| { | ||
| public sealed record ScopedCorrelation : CorrelationToken | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Cuemon.Messaging; | ||
|
|
||
| namespace Codebelt.Extensions.Xunit.Hosting.AspNetCore.Assets | ||
| { | ||
| public sealed record SingletonCorrelation : CorrelationToken | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Cuemon.Messaging; | ||
|
|
||
| namespace Codebelt.Extensions.Xunit.Hosting.AspNetCore.Assets | ||
| { | ||
| public sealed record TransientCorrelation : CorrelationToken | ||
| { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,16 +14,18 @@ namespace Codebelt.Extensions.Xunit.Hosting | |||||||||||||||||||
| [TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)] | ||||||||||||||||||||
| public class HostTestTest : HostTest<HostFixture> | ||||||||||||||||||||
| { | ||||||||||||||||||||
| private readonly IServiceScope _scope; | ||||||||||||||||||||
| private readonly Func<IList<ICorrelationToken>> _correlationsFactory; | ||||||||||||||||||||
| private static readonly ConcurrentBag<ICorrelationToken> ScopedCorrelations = new ConcurrentBag<ICorrelationToken>(); | ||||||||||||||||||||
| private static readonly ConcurrentBag<ICorrelationToken> ScopedCorrelations = new(); | ||||||||||||||||||||
|
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using static fields in test classes to prevent shared state across tests The field Consider making -private static readonly ConcurrentBag<ICorrelationToken> ScopedCorrelations = new();
+private readonly ConcurrentBag<ICorrelationToken> ScopedCorrelations = new();📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| public HostTestTest(HostFixture hostFixture, ITestOutputHelper output) : base(hostFixture, output) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| _correlationsFactory = () => hostFixture.ServiceProvider.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||
| _scope = hostFixture.ServiceProvider.CreateScope(); | ||||||||||||||||||||
| _correlationsFactory = () => _scope.ServiceProvider.GetServices<ICorrelationToken>().ToList(); | ||||||||||||||||||||
|
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reusing the same Creating a single Consider creating a new |
||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact, Priority(1)] | ||||||||||||||||||||
| public void Test_SingletonShouldBeSame() | ||||||||||||||||||||
| public void Test_SingletonShouldBeSame() // simulate a request | ||||||||||||||||||||
| { | ||||||||||||||||||||
| ScopedCorrelations.Add(_correlationsFactory().Single(c => c is ScopedCorrelation)); | ||||||||||||||||||||
| var c1 = _correlationsFactory().Single(c => c is SingletonCorrelation); | ||||||||||||||||||||
|
|
@@ -32,7 +34,7 @@ public void Test_SingletonShouldBeSame() | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact, Priority(2)] | ||||||||||||||||||||
| public void Test_TransientShouldBeDifferent() | ||||||||||||||||||||
| public void Test_TransientShouldBeDifferent() // simulate a request | ||||||||||||||||||||
| { | ||||||||||||||||||||
| ScopedCorrelations.Add(_correlationsFactory().Single(c => c is ScopedCorrelation)); | ||||||||||||||||||||
| var c1 = _correlationsFactory().Single(c => c is TransientCorrelation); | ||||||||||||||||||||
|
|
@@ -41,23 +43,14 @@ public void Test_TransientShouldBeDifferent() | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact, Priority(3)] | ||||||||||||||||||||
| public void Test_ScopedShouldBeSame() | ||||||||||||||||||||
| public void Test_ScopedShouldBeSame() // simulate a request | ||||||||||||||||||||
| { | ||||||||||||||||||||
| ScopedCorrelations.Add(_correlationsFactory().Single(c => c is ScopedCorrelation)); | ||||||||||||||||||||
| var c1 = _correlationsFactory().Single(c => c is ScopedCorrelation); | ||||||||||||||||||||
| var c2 = _correlationsFactory().Single(c => c is ScopedCorrelation); | ||||||||||||||||||||
| Assert.Equal(c1.CorrelationId, c2.CorrelationId); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact] | ||||||||||||||||||||
| public void Test_ScopedShouldBeSameInLastTestRun() | ||||||||||||||||||||
| { | ||||||||||||||||||||
| var c1 = _correlationsFactory().Single(c => c is ScopedCorrelation); | ||||||||||||||||||||
| if (ScopedCorrelations.IsEmpty) { return; } | ||||||||||||||||||||
| Assert.Equal(3, ScopedCorrelations.Count); | ||||||||||||||||||||
| Assert.All(ScopedCorrelations, c => Assert.Equal(c1.CorrelationId, c.CorrelationId)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| [Fact] | ||||||||||||||||||||
| public void Test_ShouldHaveConfigurationEntry() | ||||||||||||||||||||
| { | ||||||||||||||||||||
|
|
@@ -70,11 +63,16 @@ public void Test_ShouldHaveEnvironmentOfDevelopment() | |||||||||||||||||||
| Assert.Equal("Development", HostingEnvironment.EnvironmentName); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| protected override void OnDisposeManagedResources() | ||||||||||||||||||||
| { | ||||||||||||||||||||
| _scope?.Dispose(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+66
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Override When overriding Apply this diff to call the base class method: protected override void OnDisposeManagedResources()
{
+ base.OnDisposeManagedResources();
_scope?.Dispose();
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| public override void ConfigureServices(IServiceCollection services) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| services.AddSingleton<ICorrelationToken, SingletonCorrelation>(); | ||||||||||||||||||||
| services.AddTransient<ICorrelationToken, TransientCorrelation>(); | ||||||||||||||||||||
| services.AddScoped<ICorrelationToken, ScopedCorrelation>(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update XML documentation to reflect constructor changes.
The constructor now accepts an optional
IServiceScopeFactory, but the XML documentation has not been updated to describe this parameter. Please update the comments to maintain accurate documentation.Apply this diff to update the XML documentation:
📝 Committable suggestion