Aicrosoft.NUnit
8.0.0-beta.260130.2
dotnet add package Aicrosoft.NUnit --version 8.0.0-beta.260130.2
NuGet\Install-Package Aicrosoft.NUnit -Version 8.0.0-beta.260130.2
<PackageReference Include="Aicrosoft.NUnit" Version="8.0.0-beta.260130.2" />
<PackageVersion Include="Aicrosoft.NUnit" Version="8.0.0-beta.260130.2" />
<PackageReference Include="Aicrosoft.NUnit" />
paket add Aicrosoft.NUnit --version 8.0.0-beta.260130.2
#r "nuget: Aicrosoft.NUnit, 8.0.0-beta.260130.2"
#:package Aicrosoft.NUnit@8.0.0-beta.260130.2
#addin nuget:?package=Aicrosoft.NUnit&version=8.0.0-beta.260130.2&prerelease
#tool nuget:?package=Aicrosoft.NUnit&version=8.0.0-beta.260130.2&prerelease
Aicrosoft.NUnit
Testing framework extensions and base classes for NUnit, integrated with FakeItEasy and Shouldly.
Last Update: 2026-01-29
Introduction
Aicrosoft.NUnit provides a standardized testing foundation for Aicrosoft projects. It encapsulates common testing patterns and setup/teardown logic.
Dependencies
The framework automatically includes the following testing libraries:
- NUnit: The testing framework.
- FakeItEasy: For mocking dependencies (migrated from Moq).
- Shouldly: For fluent assertions.
Usage
1. Inherit from TestBase
Create your test classes by inheriting from TestBase (if applicable) or decorating with [TestFixture].
using Aicrosoft.NUnit;
using NUnit.Framework;
using Shouldly;
namespace MyProject.Tests;
[TestFixture]
public class MyTests
{
[Test]
public void Should_Work()
{
// Arrange
var value = 1;
// Act
var result = value + 1;
// Assert
result.ShouldBe(2);
}
}
2. Mocking with FakeItEasy
Use FakeItEasy to create mock objects.
using FakeItEasy;
// 创建 Fake 对象
var fakeRepo = A.Fake<IRepository>();
// 配置返回值
A.CallTo(() => fakeRepo.Get(1)).Returns(new Entity { Id = 1 });
// 配置抛出异常
A.CallTo(() => fakeRepo.Delete(A<int>._)).Throws<InvalidOperationException>();
// 验证调用
A.CallTo(() => fakeRepo.Get(1)).MustHaveHappenedOnceExactly();
A.CallTo(() => fakeRepo.Save(A<Entity>._)).MustHaveHappened();
A.CallTo(() => fakeRepo.Delete(A<int>._)).MustNotHaveHappened();
3. Migration from Moq
如果你正在从 Moq 迁移,以下是主要的语法映射:
| Moq | FakeItEasy |
|---|---|
new Mock<T>() |
A.Fake<T>() |
mock.Object |
直接使用 fake 对象 |
mock.Setup(x => x.Method()).Returns(value) |
A.CallTo(() => fake.Method()).Returns(value) |
mock.Setup(x => x.Method()).Throws<Ex>() |
A.CallTo(() => fake.Method()).Throws<Ex>() |
mock.Verify(x => x.Method(), Times.Once) |
A.CallTo(() => fake.Method()).MustHaveHappenedOnceExactly() |
mock.Verify(x => x.Method(), Times.Never) |
A.CallTo(() => fake.Method()).MustNotHaveHappened() |
mock.Verify(x => x.Method(), Times.AtLeastOnce) |
A.CallTo(() => fake.Method()).MustHaveHappened() |
It.IsAny<T>() |
A<T>._ 或 A<T>.Ignored |
It.Is<T>(predicate) |
A<T>.That.Matches(predicate) |
Links
| 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
- Aicrosoft.Extensions (>= 8.0.0-beta.260130.2)
- Aicrosoft.Extensions.Hosting (>= 8.0.0-beta.260130.2)
- FakeItEasy (>= 9.0.1)
- NUnit (>= 4.4.0)
- Shouldly (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0-beta.260130.2 | 111 | 1/30/2026 |