Skip to content

Commit 150058b

Browse files
authored
V5.6.0 (#93)
* v5.6.0 - *Enhancement:* The `RunAsync` methods updated to support `ValueTask` as well as `Task` for the `TypeTester` and `GenericTester` (.NET 9+ only). - *Enhancement:* Added `HttpResultAssertor` for ASP.NET Minimal APIs `Results` (e.g. `Results.Ok()`, `Results.NotFound()`, etc.) to enable assertions via the `ToHttpResponseMessageAssertor`. - *Enhancement:* `TesterBase`, `GenericTester` and `TypeTester` updated to support keyed services. - *Enhancement:* `GenericTester` and `TypeTester` updated to support the test run execution within a DI scope (using `UseRunAsScoped`). - *Fixed:* The `ExpectationsArranger` updated to `Clear` versus `Reset` after an assertion run to ensure no cross-test contamination. * Add `Delay`. * ScopedTypeTester * Clean up tweaks * Update changelog. * Fix pull request errors. * Fix CI vers path.
1 parent d80ff29 commit 150058b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1485
-192
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030

3131
- name: Explicit MSTest test
3232
run: |
33-
cp tests/UnitTestEx.Api/bin/Debug/net6.0/UnitTestEx.Api.deps.json tests/UnitTestEx.MSTest.Test/bin/Debug/net6.0
34-
cd tests/UnitTestEx.MSTest.Test/bin/Debug/net6.0
33+
cp tests/UnitTestEx.Api/bin/Debug/net8.0/UnitTestEx.Api.deps.json tests/UnitTestEx.MSTest.Test/bin/Debug/net8.0
34+
cd tests/UnitTestEx.MSTest.Test/bin/Debug/net8.0
3535
dotnet test UnitTestEx.MSTest.Test.dll --no-build --verbosity normal
3636
3737
- name: Explicit NUnit test

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Represents the **NuGet** versions.
44

5+
## v5.6.0
6+
- *Enhancement:* The `RunAsync` methods updated to support `ValueTask` as well as `Task` for the `TypeTester` and `GenericTester` (.NET 9+ only).
7+
- *Enhancement:* Added `HttpResultAssertor` for ASP.NET Minimal APIs `Results` (e.g. `Results.Ok()`, `Results.NotFound()`, etc.) to enable assertions via the `ToHttpResponseMessageAssertor`.
8+
- *Enhancement:* `TesterBase<TSelf>` updated to support keyed services.
9+
- *Enhancement* `ScopedTypeTester` created to support pre-instantiated scoped service where multiple tests can be run against the same scoped instance. The existing `TypeTester` will continue to directly execute a one-off scoped instance. These now exist on the `TesterBase<TSelf>` enabling broader usage.
10+
- *Enhancement:* Added `TesterBase<TSelf>.Delay` method to enable delays to be added in a test where needed.
11+
- *Fixed:* The `ExpectationsArranger` updated to `Clear` versus `Reset` after an assertion run to ensure no cross-test contamination.
12+
513
## v5.5.0
614
- *Enhancement:* The `GenericTester` where using `.NET8.0` and above will leverage the new `IHostApplicationBuilder` versus existing `IHostBuilder` (see Microsoft [documentation](https://learn.microsoft.com/en-us/dotnet/core/extensions/generic-host) and [recommendation](https://github.com/dotnet/runtime/discussions/81090#discussioncomment-4784551)). Additionally, if a `TEntryPoint` is specified with a method signature of `public void ConfigureApplication(IHostApplicationBuilder builder)` then this will be automatically invoked during host instantiation. This is a non-breaking change as largely internal.
715

Common.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>5.5.0</Version>
3+
<Version>5.6.0</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

UnitTestEx.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2323
ProjectSection(SolutionItems) = preProject
2424
.gitignore = .gitignore
2525
CHANGELOG.md = CHANGELOG.md
26+
.github\workflows\ci.yml = .github\workflows\ci.yml
2627
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
2728
Common.targets = Common.targets
2829
CONTRIBUTING.md = CONTRIBUTING.md

src/UnitTestEx.Azure.Functions/Azure/Functions/FunctionTesterBase.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private IHost GetHost()
139139
var ep2 = ep as FunctionsStartup;
140140
var ep3 = new EntryPoint(ep);
141141

142-
return _host = new HostBuilder()
142+
_host = new HostBuilder()
143143
.UseEnvironment(UnitTestEx.TestSetUp.Environment)
144144
.ConfigureLogging((lb) => { lb.SetMinimumLevel(SetUp.MinimumLogLevel); lb.ClearProviders(); lb.AddProvider(LoggerProvider); })
145145
.ConfigureHostConfiguration(cb =>
@@ -180,6 +180,10 @@ private IHost GetHost()
180180
SetUp.ConfigureServices?.Invoke(sc);
181181
AddConfiguredServices(sc);
182182
}).Build();
183+
184+
OnHostStartUp();
185+
186+
return _host;
183187
}
184188
}
185189

@@ -223,13 +227,6 @@ protected override void ResetHost()
223227
/// <returns>The <see cref="HttpTriggerTester{TFunction}"/>.</returns>
224228
public HttpTriggerTester<TFunction> HttpTrigger<TFunction>() where TFunction : class => new(this, HostExecutionWrapper(() => GetHost().Services.CreateScope()));
225229

226-
/// <summary>
227-
/// Specifies the <see cref="Type"/> of <typeparamref name="T"/> that is to be tested.
228-
/// </summary>
229-
/// <typeparam name="T">The <see cref="Type"/> to be tested.</typeparam>
230-
/// <returns>The <see cref="TypeTester{TFunction}"/>.</returns>
231-
public TypeTester<T> Type<T>() where T : class => new(this, HostExecutionWrapper(() => GetHost().Services.CreateScope()));
232-
233230
/// <summary>
234231
/// Specifies the <i>Function</i> <see cref="Type"/> that utilizes the <see cref="ServiceBusTriggerAttribute"/> that is to be tested.
235232
/// </summary>

src/UnitTestEx.Azure.Functions/Azure/Functions/HttpTriggerTester.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace UnitTestEx.Azure.Functions
3636
/// </list>
3737
/// The above checks are generally neccessary to assist in ensuring that the function is being invoked correctly given the parameters have to be explicitly passed in separately.
3838
/// </remarks>
39-
public class HttpTriggerTester<TFunction> : HostTesterBase<TFunction>, IExpectations<HttpTriggerTester<TFunction>> where TFunction : class
39+
public class HttpTriggerTester<TFunction> : HostTesterBase<TFunction, HttpTriggerTester<TFunction>>, IExpectations<HttpTriggerTester<TFunction>> where TFunction : class
4040
{
4141
private bool _methodCheck = true;
4242
private RouteCheckOption _routeCheckOption = RouteCheckOption.PathAndQuery;
@@ -47,7 +47,7 @@ public class HttpTriggerTester<TFunction> : HostTesterBase<TFunction>, IExpectat
4747
/// </summary>
4848
/// <param name="owner">The owning <see cref="TesterBase"/>.</param>
4949
/// <param name="serviceScope">The <see cref="IServiceScope"/>.</param>
50-
public HttpTriggerTester(TesterBase owner, IServiceScope serviceScope) : base(owner, serviceScope)
50+
public HttpTriggerTester(TesterBase owner, IServiceScope serviceScope) : base(owner, serviceScope.ServiceProvider)
5151
{
5252
ExpectationsArranger = new ExpectationsArranger<HttpTriggerTester<TFunction>>(owner, this);
5353
this.SetHttpMethodCheck(owner.SetUp);
@@ -448,9 +448,9 @@ private void LogResponse(IActionResult res, Exception? ex, double ms, IEnumerabl
448448
}
449449
}
450450

451-
Implementor.WriteLine("");
452-
Implementor.WriteLine(new string('=', 80));
453-
Implementor.WriteLine("");
451+
//Implementor.WriteLine("");
452+
//Implementor.WriteLine(new string('=', 80));
453+
//Implementor.WriteLine("");
454454
}
455455
}
456456
}

src/UnitTestEx.Azure.Functions/Azure/Functions/ServiceBusTriggerTester.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class ServiceBusTriggerTester<TFunction> : HostTesterBase<TFunction>, IEx
3131
/// </summary>
3232
/// <param name="owner">The owning <see cref="TesterBase"/>.</param>
3333
/// <param name="serviceScope">The <see cref="IServiceScope"/>.</param>
34-
public ServiceBusTriggerTester(TesterBase owner, IServiceScope serviceScope) : base(owner, serviceScope) => ExpectationsArranger = new ExpectationsArranger<ServiceBusTriggerTester<TFunction>>(owner, this);
34+
public ServiceBusTriggerTester(TesterBase owner, IServiceScope serviceScope) : base(owner, serviceScope.ServiceProvider) => ExpectationsArranger = new ExpectationsArranger<ServiceBusTriggerTester<TFunction>>(owner, this);
3535

3636
/// <summary>
3737
/// Gets the <see cref="ExpectationsArranger{TSelf}"/>.
@@ -81,7 +81,7 @@ public async Task<VoidAssertor> RunAsync(Expression<Func<TFunction, Task>> expre
8181

8282
if (validateTriggerProperties && a is not null)
8383
{
84-
var config = ServiceScope.ServiceProvider.GetRequiredService<IConfiguration>();
84+
var config = Services.GetRequiredService<IConfiguration>();
8585
var sbta = a as Microsoft.Azure.WebJobs.ServiceBusTriggerAttribute;
8686
if (sbta is not null)
8787
VerifyServiceBusTriggerProperties(config, sbta);
@@ -261,9 +261,9 @@ private void LogOutput(Exception? ex, double ms, object? value, WebJobsServiceBu
261261
ssba?.LogResult();
262262
wsba?.LogResult();
263263

264-
Implementor.WriteLine("");
265-
Implementor.WriteLine(new string('=', 80));
266-
Implementor.WriteLine("");
264+
//Implementor.WriteLine("");
265+
//Implementor.WriteLine(new string('=', 80));
266+
//Implementor.WriteLine("");
267267
}
268268
}
269269
}

src/UnitTestEx.Azure.ServiceBus/UnitTestEx.Azure.ServiceBus.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.2" />
13+
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.20.1" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

src/UnitTestEx.MSTest/WithApiTester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class WithApiTester<TEntryPoint> : IDisposable where TEntryPoint
1717
private ApiTester<TEntryPoint>? _apiTester = ApiTester.Create<TEntryPoint>();
1818

1919
/// <summary>
20-
/// Gets the shared <see cref="ApiTester{TEntryPoint}"/> for testing.
20+
/// Gets the underlying <see cref="ApiTester{TEntryPoint}"/> for testing.
2121
/// </summary>
2222
public ApiTester<TEntryPoint> Test => _apiTester ?? throw new ObjectDisposedException(nameof(Test));
2323

src/UnitTestEx.NUnit/WithApiTester.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public abstract class WithApiTester<TEntryPoint> : IDisposable where TEntryPoint
1717
private ApiTester<TEntryPoint>? _apiTester = ApiTester.Create<TEntryPoint>();
1818

1919
/// <summary>
20-
/// Gets the shared <see cref="ApiTester{TEntryPoint}"/> for testing.
20+
/// Gets the underlying <see cref="ApiTester{TEntryPoint}"/> for testing.
2121
/// </summary>
2222
public ApiTester<TEntryPoint> Test => _apiTester ?? throw new ObjectDisposedException(nameof(Test));
2323

0 commit comments

Comments
 (0)