XUnitTestBase 1.0.0
See the version list below for details.
dotnet add package XUnitTestBase --version 1.0.0
NuGet\Install-Package XUnitTestBase -Version 1.0.0
<PackageReference Include="XUnitTestBase" Version="1.0.0" />
<PackageVersion Include="XUnitTestBase" Version="1.0.0" />
<PackageReference Include="XUnitTestBase" />
paket add XUnitTestBase --version 1.0.0
#r "nuget: XUnitTestBase, 1.0.0"
#:package XUnitTestBase@1.0.0
#addin nuget:?package=XUnitTestBase&version=1.0.0
#tool nuget:?package=XUnitTestBase&version=1.0.0
XUnitTestBase
XUnitTestBase v1.0 โ A clean, extensible test foundation for .NET with auto-mocking, integration testing, and developer-friendly conventions.
๐ฏ Purpose
XUnitTestBase provides a standardized and developer-friendly test foundation for .NET applications using:
- ๐งช xUnit
- ๐ค Moq with AutoMocker
- ๐งฑ WebApplicationFactory<T> for integration testing
It helps teams write cleaner, faster, and more maintainable unit and integration tests with minimal setup.
โจ Key Features
- โ TestSubject<T>: auto-mocked unit test base class using Moq.AutoMocker
- โ MockOf<T>(): get & verify dependency mocks
- โ With<T>(): override mocks or inject custom test doubles
- โ IntegrationTestBase<T>: lightweight base for API integration tests
- โ Support for WebApplicationFactory, InMemory EF Core, and Fake Auth
๐ Integration Testing
Use IntegrationTestBase<T> to verify your app's full stack:
csharp public class UserApiTests : IntegrationTestBase<Program> { public UserApiTests() : base(services โ { services.AddDbContext<AppDbContext>(options โ options.UseInMemoryDatabase("TestDb")); }) { }
[Fact]
public async Task GetUser_ReturnsOk()
{
var response = await Client.GetAsync("/api/users/1");
response.EnsureSuccessStatusCode();
}
}
๐งช Unit Testing
Extend TestSubject<T> for clean unit tests:
csharp public class UserServiceTests : TestSubject<UserService> { [Fact] public async Task Register_CallsAllDependencies() { var user = FakeBuilder.Create<User>();
MockOf<IUserRepository>()
.Setup(r => r.GetByEmailAsync(user.Email))
.ReturnsAsync((User?)null);
await Subject.Register(user);
MockOf<IEmailSender>().Verify(s => s.SendWelcomeAsync(user.Email), Times.Once);
MockOf<IAuditLogger>().Verify(l => l.LogEvent("UserRegistered", user.Email), Times.Once);
}
}
๐ก Example Highlights
- ๐งช Auto-mocking multiple dependencies
- ๐ Overriding mocks with real/fake implementations
- ๐ End-to-end HTTP testing with in-memory HttpClient
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Moq (>= 4.20.72)
- Moq.AutoMock (>= 3.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.