Files
Govor/tests/Govor.Server.Tests/Security/HubSessionTests.cs
T
Artemy 2d99c57a3b Expand server tests and enforce coverage
Consolidate server tests under tests/, upgrade them to .NET 10, and add CI coverage thresholds and reports. Expand API and application boundary coverage while fixing related issues in media handling, friend blocking, session crypto, presence, username validation, and local storage.
2026-10-24 15:30:32 +07:00

38 lines
1.4 KiB
C#

using Govor.API.Filters;
using Govor.Contracts.Responses.SignalR;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
namespace Govor.Server.Tests;
[TestFixture]
public class HubSessionTests
{
[Test]
public async Task InvalidSessionReturnsAHubResultAndAbortsWithoutRunningMethod()
{
using var db = new TestDatabase();
var caller = new Mock<HubCallerContext>();
var hub = new StubHub();
var invocation = new HubInvocationContext(caller.Object, Mock.Of<IServiceProvider>(), hub,
typeof(StubHub).GetMethod(nameof(StubHub.Echo))!, Array.Empty<object?>());
var filter = new HubExceptionFilter(NullLogger<HubExceptionFilter>.Instance, db.Context);
var invoked = false;
var response = await filter.InvokeMethodAsync(invocation, _ =>
{
invoked = true;
return ValueTask.FromResult<object?>(HubResult<string>.Ok("unexpected"));
});
Assert.That(invoked, Is.False);
Assert.That(response, Is.TypeOf<HubResult<string>>());
Assert.That(((HubResult<string>)response!).Status, Is.EqualTo(HubResultStatus.Unauthorized));
caller.Verify(c => c.Abort(), Times.Once);
}
private sealed class StubHub : Hub
{
public Task<HubResult<string>> Echo() => Task.FromResult(HubResult<string>.Ok("ok"));
}
}