Minicon.Assertions
1.2.5
dotnet add package Minicon.Assertions --version 1.2.5
NuGet\Install-Package Minicon.Assertions -Version 1.2.5
<PackageReference Include="Minicon.Assertions" Version="1.2.5" />
<PackageVersion Include="Minicon.Assertions" Version="1.2.5" />
<PackageReference Include="Minicon.Assertions" />
paket add Minicon.Assertions --version 1.2.5
#r "nuget: Minicon.Assertions, 1.2.5"
#:package Minicon.Assertions@1.2.5
#addin nuget:?package=Minicon.Assertions&version=1.2.5
#tool nuget:?package=Minicon.Assertions&version=1.2.5
Minicon.Assertions
Eine schlanke, kostenlose und MIT-lizenzierte Fluent-Assertion-Bibliothek für .NET im
vertrauten FluentAssertions-Stil (value.Should().Be(...)).
Hintergrund: FluentAssertions ist seit Version 8 kommerziell lizenzpflichtig.
Minicon.Assertionsbietet die wichtigsten Assertions als freie Alternative – ohne kommerzielle Einschränkungen, ohne Lizenzkosten.
Installation
dotnet add package Minicon.Assertions
Schnellstart
using Minicon.Assertions;
// Gleichheit
result.Should().Be(42);
name.Should().NotBe("falsch");
// Null
value.Should().NotBeNull();
optional.Should().BeNull();
// Begründung (because) – erscheint in der Fehlermeldung
order.Total.Should().Be(100, "die Summe der Positionen ergibt {0}", 100);
Funktioniert nahtlos mit xUnit, NUnit und MSTest: Fehlschläge werden automatisch
als die jeweils passende Test-Framework-Exception geworfen, damit Runner und IDE den
Fehler korrekt als fehlgeschlagene Assertion anzeigen. Ohne erkanntes Framework wird
MiniconAssertionException geworfen.
Unterstützte Assertions
Allgemein / Objekte
obj.Should().Be(expected);
obj.Should().NotBe(other);
obj.Should().BeNull();
obj.Should().NotBeNull();
obj.Should().BeSameAs(reference);
obj.Should().BeOfType<MyType>();
obj.Should().BeAssignableTo<IMyInterface>();
obj.Should().Match(x => x.Id > 0);
obj.Should().BeOneOf(a, b, c);
Strings
text.Should().Be("exakt");
text.Should().BeEquivalentTo("EXAKT"); // Groß-/Kleinschreibung egal
text.Should().Contain("teil");
text.Should().StartWith("Hallo");
text.Should().EndWith("Welt");
text.Should().HaveLength(11);
text.Should().BeEmpty();
text.Should().NotBeNullOrWhiteSpace();
Zahlen & vergleichbare Werte (int, long, double, decimal, DateTime, TimeSpan, …)
value.Should().BeGreaterThan(3);
value.Should().BeGreaterThanOrEqualTo(5);
value.Should().BeLessThan(10);
value.Should().BeInRange(1, 100);
value.Should().BePositive();
value.Should().BeNegative();
pi.Should().BeApproximately(3.14, 0.01); // Toleranz für Fließkomma
Nullable-Werte
int? x = 5;
x.Should().HaveValue();
x.Should().BeGreaterThan(3);
int? y = null;
y.Should().NotHaveValue();
Booleans
flag.Should().BeTrue();
flag.Should().BeFalse();
Collections
list.Should().HaveCount(3);
list.Should().BeEmpty();
list.Should().NotBeEmpty();
list.Should().Contain(item);
list.Should().Contain(x => x.IsActive);
list.Should().NotContain(item);
list.Should().ContainSingle();
list.Should().OnlyContain(x => x > 0);
list.Should().OnlyHaveUniqueItems();
list.Should().Equal(1, 2, 3); // gleiche Reihenfolge
list.Should().BeEquivalentTo(new[] {3, 2, 1}); // Reihenfolge egal
list.Should().ContainInOrder(1, 3);
Exceptions
Action act = () => service.Do();
act.Should().Throw<InvalidOperationException>()
.WithMessage("genaue Meldung");
act.Should().Throw<ArgumentException>()
.WithMessageContaining("teilstring");
act.Should().ThrowExactly<ArgumentException>(); // exakter Typ, keine Ableitung
act.Should().NotThrow();
// Komfort-Helfer
service.Invoking(s => s.Divide(1, 0))
.Should().Throw<DivideByZeroException>();
Verkettung mit .And
result.Should().NotBeNull().And.Be("abc");
Migration von FluentAssertions
Die API ist bewusst kompatibel gehalten. In den meisten Fällen genügt es, das
using auszutauschen:
- using FluentAssertions;
+ using Minicon.Assertions;
Nicht jede FluentAssertions-Methode ist (noch) abgedeckt – siehe Liste oben. Fehlt dir etwas? Pull Requests willkommen.
Build & Test
dotnet build
dotnet test
dotnet pack src/Minicon.Assertions/Minicon.Assertions.csproj -c Release
Lizenz
MIT – frei für kommerzielle und private Nutzung.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.