Skip to content

Commit

Permalink
Latest UnitTestEx and CoreEx (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored Dec 2, 2023
1 parent 392d14b commit 232cc47
Show file tree
Hide file tree
Showing 52 changed files with 231 additions and 269 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
dotnet-version: |
6.0.x
7.0.x
8.0.x
# Tools

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Represents the **NuGet** versions.

## v5.7.0
- *Enhancement:* `UnitTestEx` as of `v4.0.0` removed all dependencies to `CoreEx`; the equivalent functionality has been included in new `CoreEx.UnitTest` and `CoreEx.UnitTest.NUnit` (`v3.6.0`) packages. Replace existing `UnitTestEx.NUnit` package with the corresponding `CoreEx.UnitTesting.NUnit` package.
- Unfortunately, this change has resulted in a number of breaking changes that will require manual remediation to existing unit tests; see the `UnitTestEx` [change log](https://github.com/Avanade/UnitTestEx/blob/main/CHANGELOG.md#v400) and `CoreEx` [change log](https://github.com/Avanade/CoreEx/blob/main/CHANGELOG.md#v360) for details and instructions to remediate.
- Upgraded `CoreEx` (`v3.6.0`) to include all related fixes and improvements.
- Upgraded `UnitTestEx` (`v4.0.0`) to include all related fixes and improvements
- *Enhancement:* Added `net7.0` and `net8.0` support.

## v5.6.9
- *Fixed:* The `yaml` sub-command generated code updated to leverage the new `Entity.Behavior`, being `behavior: cgupd`, where CRUD capabilities are requested.

Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>5.6.9</Version>
<Version>5.7.0</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
2 changes: 1 addition & 1 deletion samples/Cdr.Banking/Cdr.Banking.Api/Cdr.Banking.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.4.1" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Folder Include="DataSvc\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreEx.Cosmos" Version="3.4.1" />
<PackageReference Include="CoreEx.Validation" Version="3.4.1" />
<PackageReference Include="CoreEx.Cosmos" Version="3.6.0" />
<PackageReference Include="CoreEx.Validation" Version="3.6.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<Folder Include="Entities\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreEx" Version="3.4.1" />
<PackageReference Include="CoreEx" Version="3.6.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions samples/Cdr.Banking/Cdr.Banking.Test/AccountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void OneTimeSetUp()
[Test]
public void B110_GetAccounts_User1()
{
var v = Agent<AccountAgent, AccountCollectionResult>()
var v = this.Agent<AccountAgent, AccountCollectionResult>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAccountsAsync(null)).Value;

Expand Down Expand Up @@ -223,7 +223,7 @@ public void C140_GetDetail_NoAuth()
[Test]
public void D110_GetBalance_Found()
{
var v = Agent<AccountAgent, Balance?>()
var v = this.Agent<AccountAgent, Balance?>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetBalanceAsync("12345678")).Value;

Expand Down
4 changes: 2 additions & 2 deletions samples/Cdr.Banking/Cdr.Banking.Test/Cdr.Banking.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="UnitTestEx.NUnit" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="CoreEx.UnitTesting.NUnit" Version="3.6.0" />
</ItemGroup>

<ItemGroup>
Expand Down
13 changes: 7 additions & 6 deletions samples/Cdr.Banking/Cdr.Banking.Test/TransactionArgsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using NUnit.Framework;
using System;
using System.Threading.Tasks;
using UnitTestEx;
using UnitTestEx.Expectations;
using UnitTestEx.NUnit;

Expand All @@ -16,7 +17,7 @@ public class TransactionArgsTest
public async Task A110_ArgsValidator_Empty()
{
var ta = new TransactionArgs();
var r = await ValidationTester.Create().RunAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
var r = await GenericTester.Create().Validation().WithAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));

Assert.IsFalse(r!.Result.HasErrors);
Assert.AreEqual(DateTime.UtcNow.Date.AddDays(-90), ta.FromDate!.Value.Date);
Expand All @@ -30,7 +31,7 @@ public async Task A110_ArgsValidator_Empty()
public async Task A120_ArgsValidator_ToDateOnly()
{
var ta = new TransactionArgs { ToDate = new DateTime(2020, 03, 01) };
var r = await ValidationTester.Create().RunAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
var r = await GenericTester.Create().Validation().WithAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));

Assert.IsFalse(r!.Result.HasErrors);
Assert.AreEqual(new DateTime(2020, 03, 01).AddDays(-90), ta.FromDate);
Expand All @@ -44,7 +45,7 @@ public async Task A120_ArgsValidator_ToDateOnly()
public async Task A130_ArgsValidator_ValidSame()
{
var ta = new TransactionArgs { FromDate = new DateTime(2020, 03, 01), ToDate = new DateTime(2020, 03, 01), MinAmount = 100m, MaxAmount = 100m, Text = "Best Buy" };
var r = await ValidationTester.Create().RunAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
var r = await GenericTester.Create().Validation().WithAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));

Assert.IsFalse(r!.Result.HasErrors);
Assert.AreEqual(new DateTime(2020, 03, 01), ta.FromDate);
Expand All @@ -58,7 +59,7 @@ public async Task A130_ArgsValidator_ValidSame()
public async Task A140_ArgsValidator_ValidDiff()
{
var ta = new TransactionArgs { FromDate = new DateTime(2020, 03, 01), ToDate = new DateTime(2020, 04, 01), MinAmount = 100m, MaxAmount = 120m, Text = "Best Buy" };
var r = await ValidationTester.Create().RunAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
var r = await GenericTester.Create().Validation().WithAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));

Assert.IsFalse(r!.Result.HasErrors);
Assert.AreEqual(new DateTime(2020, 03, 01), ta.FromDate);
Expand All @@ -72,13 +73,13 @@ public async Task A140_ArgsValidator_ValidDiff()
public async Task A150_ArgsValidator_Invalid()
{
var ta = new TransactionArgs { FromDate = new DateTime(2020, 03, 01), ToDate = new DateTime(2020, 02, 01), MinAmount = 100m, MaxAmount = 80m, Text = "Best*Buy" };
await ValidationTester.Create()
await GenericTester.Create()
.ConfigureServices(sc => sc.AddValidationTextProvider())
.ExpectErrors(
"Oldest time must be less than or equal to Newest time.",
"Min Amount must be less than or equal to Max Amount.",
"Text contains invalid or non-supported wildcard selection.")
.RunAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
.Validation().WithAsync(async () => await new TransactionArgsValidator().ValidateAsync(ta));
}
}
}
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.Api/Beef.Demo.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CoreEx.AspNetCore" Version="3.4.1" />
<PackageReference Include="CoreEx.AspNetCore" Version="3.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.5.0" />
</ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions samples/Demo/Beef.Demo.Business/Beef.Demo.Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx" Version="3.4.1" />
<PackageReference Include="CoreEx.Cosmos" Version="3.4.1" />
<PackageReference Include="CoreEx.Database" Version="3.4.1" />
<PackageReference Include="CoreEx.Database.SqlServer" Version="3.4.1" />
<PackageReference Include="CoreEx.EntityFrameworkCore" Version="3.4.1" />
<PackageReference Include="CoreEx.Validation" Version="3.4.1" />
<PackageReference Include="CoreEx.FluentValidation" Version="3.4.1" />
<PackageReference Include="CoreEx" Version="3.6.0" />
<PackageReference Include="CoreEx.Cosmos" Version="3.6.0" />
<PackageReference Include="CoreEx.Database" Version="3.6.0" />
<PackageReference Include="CoreEx.Database.SqlServer" Version="3.6.0" />
<PackageReference Include="CoreEx.EntityFrameworkCore" Version="3.6.0" />
<PackageReference Include="CoreEx.Validation" Version="3.6.0" />
<PackageReference Include="CoreEx.FluentValidation" Version="3.6.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.20" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion samples/Demo/Beef.Demo.Common/Beef.Demo.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<Folder Include="Agents\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CoreEx" Version="3.4.1" />
<PackageReference Include="CoreEx" Version="3.6.0" />
<PackageReference Include="Grpc.Tools" Version="2.45.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
5 changes: 3 additions & 2 deletions samples/Demo/Beef.Demo.Test/Beef.Demo.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="CoreEx.UnitTesting" Version="3.6.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="UnitTestEx.NUnit" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="UnitTestEx.NUnit" Version="4.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
44 changes: 22 additions & 22 deletions samples/Demo/Beef.Demo.Test/ContactTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ public void A110_Get()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent, Contact>()
var r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue((t) => new Contact { Id = 1.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert", Status = "P", StatusDescription = "Pending", Communications = new ContactCommCollection { { "home", new ContactComm { Value = "411671953", IsPreferred = true } }, { "fax", new ContactComm { Value = "411123789" } } } })
.Run(a => a.GetAsync(1.ToGuid()));

Assert.NotNull(r.Response.Headers?.ETag?.Tag);
var etag = r.Response.Headers?.ETag?.Tag;

r = test.Agent<ContactAgent, Contact>()
r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue((t) => new Contact { Id = 1.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert", Status = "P", StatusDescription = "Pending", Communications = new ContactCommCollection { { "home", new ContactComm { Value = "411671953", IsPreferred = true } }, { "fax", new ContactComm { Value = "411123789" } } } })
.Run(a => a.GetAsync(1.ToGuid()));
Expand All @@ -46,18 +46,18 @@ public void A112_Patch_Dict()
{
using var test = ApiTester.Create<Startup>();

var v = test.Agent<ContactAgent, Contact>()
var v = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAsync(1.ToGuid())).Value!;

v.Communications.Remove("fax");
v.Communications.Add("mobile", new ContactComm { Value = "4258762983" });

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.PatchAsync(CoreEx.Http.HttpPatchOption.MergePatch, "{\"communications\":{\"mobile\":{\"value\":\"4258762983\"},\"fax\":null}}", 1.ToGuid()));

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue(v)
.Run(a => a.GetAsync(1.ToGuid()));
Expand All @@ -68,11 +68,11 @@ public void A112a_Patch_Dict_KeyError()
{
using var test = ApiTester.Create<Startup>();

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAsync(1.ToGuid()));

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.BadRequest)
.ExpectErrors("Communication Type is invalid.")
.Run(a => a.PatchAsync(CoreEx.Http.HttpPatchOption.MergePatch, "{\"communications\":{\"xyz\":{\"value\":\"4258762983\"},\"fax\":null}}", 1.ToGuid()));
Expand All @@ -83,11 +83,11 @@ public void A112b_Patch_Dict_ValueError()
{
using var test = ApiTester.Create<Startup>();

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAsync(1.ToGuid()));

test.Agent<ContactAgent, Contact>()
test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.BadRequest)
.ExpectErrors(
"Value is required.",
Expand All @@ -100,7 +100,7 @@ public void A120_Get_LogicallyDeleted()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent, Contact>()
var r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.NotFound)
.Run(a => a.GetAsync(2.ToGuid()));
}
Expand All @@ -110,7 +110,7 @@ public void A130_Update_LogicallyDeleted()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent, Contact>()
var r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.NotFound)
.Run(a => a.UpdateAsync(new Contact { Id = 2.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert" }, 2.ToGuid()));
}
Expand All @@ -120,7 +120,7 @@ public void A140_UpdateAndCheckEventOutboxDequeue()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent, Contact>()
var r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue((t) => new Contact { Id = 1.ToGuid(), FirstName = "Jenny", LastName = "Cuthbert", Status = "P", StatusDescription = "Pending" }, "Communications")
.Run(a => a.GetAsync(1.ToGuid()));
Expand All @@ -137,7 +137,7 @@ public void A140_UpdateAndCheckEventOutboxDequeue()
var v = r.Value;
v.LastName += "X";

r = test.Agent<ContactAgent, Contact>()
r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue((t) => v)
.Run(a => a.UpdateAsync(v, 1.ToGuid()));
Expand Down Expand Up @@ -167,14 +167,14 @@ public void A150_GetAll()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent, ContactCollectionResult>()
var r = test.Agent().With<ContactAgent, ContactCollectionResult>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAllAsync());

Assert.NotNull(r.Response.Headers?.ETag?.Tag);
var etag = r.Response.Headers?.ETag?.Tag;

r = test.Agent<ContactAgent, ContactCollectionResult>()
r = test.Agent().With<ContactAgent, ContactCollectionResult>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAllAsync());

Expand All @@ -185,12 +185,12 @@ public void A150_GetAll()
v.LastName += "X";

// Update and ensure that the etag has changed as a result.
var r2 = test.Agent<ContactAgent, Contact>()
var r2 = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.OK)
.ExpectValue((t) => v)
.Run(a => a.UpdateAsync(v, v.Id));

r = test.Agent<ContactAgent, ContactCollectionResult>()
r = test.Agent().With<ContactAgent, ContactCollectionResult>()
.ExpectStatusCode(HttpStatusCode.OK)
.Run(a => a.GetAllAsync());

Expand All @@ -203,15 +203,15 @@ public void A160_Delete()
{
using var test = ApiTester.Create<Startup>();

test.Agent<ContactAgent>()
test.Agent().With<ContactAgent>()
.ExpectStatusCode(HttpStatusCode.NoContent)
.Run(a => a.DeleteAsync(1.ToGuid()));

var r = test.Agent<ContactAgent, Contact>()
var r = test.Agent().With<ContactAgent, Contact>()
.ExpectStatusCode(HttpStatusCode.NotFound)
.Run(a => a.GetAsync(1.ToGuid()));

test.Agent<ContactAgent>()
test.Agent().With<ContactAgent>()
.ExpectStatusCode(HttpStatusCode.NoContent)
.Run(a => a.DeleteAsync(1.ToGuid()));

Expand All @@ -232,7 +232,7 @@ public void A200_RaiseEvent_EventOutboxFailure()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent>()
var r = test.Agent().With<ContactAgent>()
.ExpectStatusCode(HttpStatusCode.InternalServerError)
.Run(a => a.RaiseEventAsync(true));

Expand All @@ -247,7 +247,7 @@ public void A210_RaiseEvent_EventOutboxSuccess()
{
using var test = ApiTester.Create<Startup>();

var r = test.Agent<ContactAgent>()
var r = test.Agent().With<ContactAgent>()
.ExpectStatusCode(HttpStatusCode.NoContent)
.Run(a => a.RaiseEventAsync(false));

Expand Down
Loading

0 comments on commit 232cc47

Please sign in to comment.