Added configurators
All checks were successful
HopFrame CI / build (push) Successful in 2m10s
HopFrame CI / test (push) Successful in 1m27s

This commit is contained in:
2026-02-22 19:32:33 +01:00
parent 79ed400185
commit b2a029d50b
40 changed files with 1837 additions and 1 deletions

View File

@@ -0,0 +1,98 @@
using HopFrame.Core.Repositories;
using Moq;
namespace HopFrame.Tests.Core.Repositories;
public class HopFrameRepositoryTests {
private Mock<HopFrameRepository<TestModel>> CreateMock()
=> new(MockBehavior.Strict);
// -------------------------------------------------------------
// LoadPageGenericAsync
// -------------------------------------------------------------
[Fact]
public async Task LoadPageGenericAsync_DelegatesToTypedMethod() {
var mock = CreateMock();
var expected = new List<TestModel> { new TestModel { Id = 1 } };
mock.Setup(r => r.LoadPageAsync(2, 10, It.IsAny<CancellationToken>()))
.ReturnsAsync(expected);
var result = await mock.Object.LoadPageGenericAsync(2, 10);
Assert.Equal(expected, result);
}
// -------------------------------------------------------------
// SearchGenericAsync
// -------------------------------------------------------------
[Fact]
public async Task SearchGenericAsync_DelegatesToTypedMethod() {
var mock = CreateMock();
var expected = new List<TestModel> { new TestModel { Id = 5 } };
mock.Setup(r => r.SearchAsync("abc", 1, 20, It.IsAny<CancellationToken>()))
.ReturnsAsync(expected);
var result = await mock.Object.SearchGenericAsync("abc", 1, 20);
Assert.Equal(expected, result);
}
// -------------------------------------------------------------
// CreateGenericAsync
// -------------------------------------------------------------
[Fact]
public async Task CreateGenericAsync_CastsAndDelegates() {
var mock = CreateMock();
var model = new TestModel { Id = 99 };
mock.Setup(r => r.CreateAsync(model, It.IsAny<CancellationToken>()))
.Returns(Task.CompletedTask);
await mock.Object.CreateGenericAsync(model, CancellationToken.None);
mock.Verify(r => r.CreateAsync(model, It.IsAny<CancellationToken>()), Times.Once);
}
// -------------------------------------------------------------
// DeleteGenericAsync
// -------------------------------------------------------------
[Fact]
public async Task DeleteGenericAsync_CastsAndDelegates() {
var mock = CreateMock();
var model = new TestModel { Id = 42 };
mock.Setup(r => r.DeleteAsync(model, It.IsAny<CancellationToken>()))
.Returns(Task.CompletedTask);
await mock.Object.DeleteGenericAsync(model, CancellationToken.None);
mock.Verify(r => r.DeleteAsync(model, It.IsAny<CancellationToken>()), Times.Once);
}
// -------------------------------------------------------------
// CountAsync (direct abstract method)
// -------------------------------------------------------------
[Fact]
public async Task CountAsync_CanBeMockedAndReturnsValue() {
var mock = CreateMock();
mock.Setup(r => r.CountAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(123);
var result = await mock.Object.CountAsync();
Assert.Equal(123, result);
}
}