Add integration test project with MediatR procedure tests
Added ReC.Tests project with integration tests for stored procedure commands and queries via MediatR, covering endpoints, actions, results, and profiles. Introduced a test base for DI/configuration, helper for private property access, and updated the solution to include the new test suite. Tests use NUnit and cover both positive and negative scenarios.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using ReC.Application.Common.Procedures.DeleteProcedure;
|
||||
using ReC.Application.Common.Procedures.InsertProcedure;
|
||||
using ReC.Application.Common.Procedures.UpdateProcedure;
|
||||
using ReC.Application.RecActions.Commands;
|
||||
using ReC.Tests.Application;
|
||||
|
||||
namespace ReC.Tests.Application.RecActions;
|
||||
|
||||
[TestFixture]
|
||||
public class RecActionProcedureTests : RecApplicationTestBase
|
||||
{
|
||||
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
|
||||
{
|
||||
var scope = ServiceProvider.CreateScope();
|
||||
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
|
||||
return (sender, scope);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task InsertActionProcedure_runs_via_mediator()
|
||||
{
|
||||
var procedure = new InsertActionProcedure { ProfileId = 1, Active = true, Sequence = 1 };
|
||||
var objectProc = procedure.ToObjectProcedure("ReC.Tests");
|
||||
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
var result = await sender.Send(objectProc);
|
||||
|
||||
Assert.That(result, Is.GreaterThan(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UpdateActionProcedure_runs_via_mediator()
|
||||
{
|
||||
var procedure = new UpdateActionProcedure { ProfileId = 2, Active = false, Sequence = 2 };
|
||||
var objectProc = procedure.ToObjectProcedure(35, "ReC.Tests");
|
||||
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
var result = await sender.Send(objectProc);
|
||||
|
||||
Assert.That(result, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DeleteActionProcedure_runs_via_mediator()
|
||||
{
|
||||
var procedure = new DeleteActionProcedure { Start = 7, End = 8, Force = true };
|
||||
var objectProc = procedure.ToObjectProcedure();
|
||||
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
var result = await sender.Send(objectProc);
|
||||
|
||||
Assert.That(result, Is.EqualTo(0));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using ReC.Application.RecActions.Queries;
|
||||
using ReC.Tests.Application;
|
||||
|
||||
namespace ReC.Tests.Application.RecActions;
|
||||
|
||||
[TestFixture]
|
||||
public class RecActionQueryTests : RecApplicationTestBase
|
||||
{
|
||||
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
|
||||
{
|
||||
var scope = ServiceProvider.CreateScope();
|
||||
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
|
||||
return (sender, scope);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ReadRecActionViewQuery_returns_actions_for_profile()
|
||||
{
|
||||
var profileId = Configuration.GetValue<long?>("FakeProfileId");
|
||||
Assert.That(profileId, Is.Not.Null.And.GreaterThan(0), "FakeProfileId must be configured in appsettings.json");
|
||||
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
|
||||
var actions = await sender.Send(new ReadRecActionViewQuery
|
||||
{
|
||||
ProfileId = profileId
|
||||
});
|
||||
|
||||
Assert.That(actions, Is.Not.Empty);
|
||||
Assert.That(actions.All(a => a.ProfileId == profileId));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReadRecActionViewQuery_with_unknown_profile_throws_not_found()
|
||||
{
|
||||
var (sender, scope) = CreateScopedSender();
|
||||
using var _ = scope;
|
||||
|
||||
var invalidProfileId = long.MaxValue;
|
||||
|
||||
Assert.ThrowsAsync<NotFoundException>(async () =>
|
||||
await sender.Send(new ReadRecActionViewQuery
|
||||
{
|
||||
ProfileId = invalidProfileId
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user