Skip to content

Commit 0f72073

Browse files
authored
Issues #9 and #10 (#11)
Co-authored-by: Eric Sibly <eric.sibly@avanade.com>
1 parent c4c0b1e commit 0f72073

27 files changed

+439
-252
lines changed

CHANGELOG.md

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

33
Represents the **NuGet** versions.
44

5+
## v1.0.6
6+
- *[Issue 10](https://github.com/Avanade/UnitTestEx/issues/10)*: **Breaking change.** Changed the `ActionResultAssertor.AssertAccepted` and `ActionResultAssertor.AssertCreated` to assert status only; the existing value check should be performed using the `ActionResultAssertor.Assert`. Pattern now is to check status and value separately (no longer all inclusive).
7+
- *[Issue 10](https://github.com/Avanade/UnitTestEx/issues/10)*: **Breaking change.** Changed the `HttpResponseMessageAssertor.AssertAccepted` and `HttpResponseMessageAssertor.AssertCreated` to assert status only; the existing value check should be performed using the `ActionResultAssertor.Assert`. Pattern now is to check status and value separately (no longer all inclusive).
8+
- *[Issue 10](https://github.com/Avanade/UnitTestEx/issues/10)*: **Breaking change.** Changed `ActionResultAssertor.AssertBadRequest` and `HttpResponseMessageAssertor.AssertBadRequest` to assert status only; added new `AssertErrors` to each for error message asserting.
9+
- *[Issue 9](https://github.com/Avanade/UnitTestEx/issues/9)*: Add `Services` property (`IServicesCollection`) to both `ApiTesterBase` and `FunctionTesterBase`. This allows direct access to the underlying `Services` outside of the more typical `Run`.
10+
511
## v1.0.5
612
- *[Issue 7](https://github.com/Avanade/UnitTestEx/issues/7)*: Added delay (sleep) option so response is not always immediate.
713
- *Enhancement:* **Breaking change.** `Functions.GenericTriggerTester` replaced with `Hosting.TypeTester` as agnostic to any function trigger. `Functions.TriggerTesterBase` replaced with `Hosting.HostTesterBase` for same agnostic reasoning. `FunctionTestBase.GenericTrigger` method renamed to `FunctionTestBase.Type` so as to not imply a _trigger_ requirement (i.e. can be any _Type+Method_ that needs testing).

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ using var test = ApiTester.Create<Startup>();
4040
test.ConfigureServices(sc => mcf.Replace(sc))
4141
.Controller<ProductController>()
4242
.Run(c => c.Get("abc"))
43-
.AssertOK(new { id = "Abc", description = "A blue carrot" });
43+
.AssertOK()
44+
.Assert(new { id = "Abc", description = "A blue carrot" });
4445
```
4546

4647
<br/>
@@ -56,7 +57,8 @@ using var test = FunctionTester.Create<Startup>();
5657
test.ConfigureServices(sc => mcf.Replace(sc))
5758
.HttpTrigger<ProductFunction>()
5859
.Run(f => f.Run(test.CreateHttpRequest(HttpMethod.Get, "person/abc", null), "abc", test.Logger))
59-
.AssertOK(new { id = "Abc", description = "A blue carrot" });
60+
.AssertOK()
61+
.Assert(new { id = "Abc", description = "A blue carrot" });
6062
```
6163

6264
<br/>
@@ -92,7 +94,8 @@ using var test = ApiTester.Create<Startup>();
9294
test.ConfigureServices(sc => mcf.Replace(sc))
9395
.Controller<ProductController>()
9496
.Run(c => c.Get("abc"))
95-
.AssertOK(new { id = "Abc", description = "A blue carrot" });
97+
.AssertOK()
98+
.Assert(new { id = "Abc", description = "A blue carrot" });
9699
```
97100

98101
</br>

src/UnitTestEx.MSTest/UnitTestEx.MSTest.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>UnitTestEx.MSTest</RootNamespace>
6-
<Version>1.0.5</Version>
6+
<Version>1.0.6</Version>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Authors>UnitTestEx Developers</Authors>
99
<Company>Avanade</Company>

src/UnitTestEx.NUnit/UnitTestEx.NUnit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>UnitTestEx.NUnit</RootNamespace>
6-
<Version>1.0.5</Version>
6+
<Version>1.0.6</Version>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Authors>UnitTestEx Developers</Authors>
99
<Company>Avanade</Company>

src/UnitTestEx.XUnit/UnitTestEx.Xunit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<RootNamespace>UnitTestEx.Xunit</RootNamespace>
6-
<Version>1.0.5</Version>
6+
<Version>1.0.6</Version>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
88
<Authors>UnitTestEx Developers</Authors>
99
<Company>Avanade</Company>

src/UnitTestEx/AspNetCore/ApiTesterBase.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.AspNetCore.Mvc;
55
using Microsoft.AspNetCore.Mvc.Testing;
66
using Microsoft.AspNetCore.TestHost;
7+
using Microsoft.Extensions.Configuration;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using Moq;
@@ -20,7 +21,7 @@ namespace UnitTestEx.AspNetCore
2021
public abstract class ApiTesterBase<TEntryPoint, TSelf> : IDisposable where TEntryPoint : class where TSelf : ApiTesterBase<TEntryPoint, TSelf>
2122
{
2223
private bool _disposed;
23-
private WebApplicationFactory<TEntryPoint>? _waf;
24+
private WebApplicationFactory<TEntryPoint> _waf;
2425

2526
/// <summary>
2627
/// Initializes a new instance of the <see cref="ApiTesterBase{TEntryPoint, TSelf}"/> class.
@@ -55,6 +56,18 @@ public TSelf ConfigureServices(Action<IServiceCollection> configureServices)
5556
return (TSelf)this;
5657
}
5758

59+
/// <summary>
60+
/// Gets the <see cref="IServiceProvider"/> from the underlying host.
61+
/// </summary>
62+
/// <returns>The <see cref="IServiceProvider"/>.</returns>
63+
public IServiceProvider Services => _waf.Services;
64+
65+
/// <summary>
66+
/// Gets the <see cref="IConfiguration"/> from the underlying host.
67+
/// </summary>
68+
/// <returns>The <see cref="IConfiguration"/>.</returns>
69+
public IConfiguration Configuration => Services.GetService<IConfiguration>();
70+
5871
/// <summary>
5972
/// Replace scoped service with a mock object.
6073
/// </summary>
@@ -94,12 +107,7 @@ protected virtual void Dispose(bool disposing)
94107
if (_disposed)
95108
return;
96109

97-
if (_waf != null)
98-
{
99-
_waf.Dispose();
100-
_waf = null;
101-
}
102-
110+
_waf.Dispose();
103111
_disposed = true;
104112
}
105113
}

0 commit comments

Comments
 (0)