Files
ReC/tests/ReC.Tests/Application/Results/ResultProcedureTests.cs
TekH 302fee4908 Refactor tests to send commands directly to mediator
Refactored test code to remove ToObjectProcedure usage and send command objects directly to the mediator. Updated update procedure tests to use Data and Id properties. Replaced custom Execute*Procedure methods with sender.Send. Cleaned up unused usings. These changes improve consistency and reflect updates to command structures.
2026-03-24 11:29:15 +01:00

59 lines
1.8 KiB
C#

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.Results.Commands;
using ReC.Tests.Application;
namespace ReC.Tests.Application.Results;
[TestFixture]
public class ResultProcedureTests : RecApplicationTestBase
{
private (ISender Sender, IServiceScope Scope) CreateScopedSender()
{
var scope = ServiceProvider.CreateScope();
var sender = scope.ServiceProvider.GetRequiredService<ISender>();
return (sender, scope);
}
[Test]
public async Task InsertResultProcedure_runs_via_mediator()
{
var procedure = new InsertResultProcedure { ActionId = 1, StatusId = 200, Header = "h", Body = "b" };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(procedure);
Assert.That(result, Is.GreaterThan(0));
}
[Test]
public async Task UpdateResultProcedure_runs_via_mediator()
{
var procedure = new UpdateResultProcedure { Data = { ActionId = 2, StatusId = 500, Header = "h2", Body = "b2" }, Id = 55 };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(procedure);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
[Test]
public async Task DeleteResultProcedure_runs_via_mediator()
{
var procedure = new DeleteResultProcedure { Start = 11, End = 12, Force = false };
var (sender, scope) = CreateScopedSender();
using var _ = scope;
var result = await sender.Send(procedure);
Assert.That(result, Is.Not.EqualTo(default(int)));
}
}