Refactor nunit tests off EF InMemory provider and web server
Extract IMicCheckDbContext so DB access can be mocked with Moq instead of the InMemory provider, per project testing guidelines. Add shared async DbSet test doubles (TestSupport/) to back the mocks. Rewrite HTTP-pipeline tests (WebApplicationFactory) to exercise controllers and auth handlers directly instead of running the web server. Drop DbContext/seeder tests that only made sense against a real provider, and remove stale duplicate test files left over from a namespace move.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace MicCheck.Api.Tests.Unit.TestSupport;
|
||||
|
||||
public class TestAsyncEnumerable<T> : EnumerableQuery<T>, IAsyncEnumerable<T>, IQueryable<T>
|
||||
{
|
||||
public TestAsyncEnumerable(IEnumerable<T> enumerable) : base(enumerable) { }
|
||||
|
||||
public TestAsyncEnumerable(Expression expression) : base(expression) { }
|
||||
|
||||
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default) =>
|
||||
new TestAsyncEnumerator<T>(this.AsEnumerable().GetEnumerator());
|
||||
|
||||
IQueryProvider IQueryable.Provider => new TestAsyncQueryProvider<T>(this);
|
||||
}
|
||||
|
||||
public sealed class TestAsyncEnumerator<T>(IEnumerator<T> inner) : IAsyncEnumerator<T>
|
||||
{
|
||||
public T Current => inner.Current;
|
||||
|
||||
public ValueTask<bool> MoveNextAsync() => ValueTask.FromResult(inner.MoveNext());
|
||||
|
||||
public ValueTask DisposeAsync()
|
||||
{
|
||||
inner.Dispose();
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user