soxtoby / easyassertions Goto Github PK
View Code? Open in Web Editor NEWEasy-to-use fluent assertions with actually useful failure messages.
License: MIT License
Easy-to-use fluent assertions with actually useful failure messages.
License: MIT License
ShouldHaveFlag for [Flags] enums.
Try adding ShouldBe for enums that gets R# autocompletion working.
new[] { "foo", "bar" }.ShouldOnlyContain(new[] { "foo" })
produces an error where the sample shows up like:
[
[
<f>,
<o>,
<o>
...
Obviously, strings shouldn't get treated like IEnumerable for this sort of thing.
Specifically function exceptions, but things like .And()
and equality predicates as well.
E.g. .ShouldNotBeNull().And
is never null
"foo\nbar".ShouldBe("foo\nbaz");
results in an error message like:
should be "foo\nbaz"
but was "foo\nbar"
^
Task.Delay(1000, new CancellationToken(true)).ShouldFail()
new [] { new [] { 1 } }.ShouldMatch(new[] { new [] { 2 } });
Fails with a message like "Array'1[Int32] should have been Array'1[Int32]", but it should be more like: "Item 0, 0 should have been 2, but was 1". Doesn't have to be perfect, but it should get across that it's the items that aren't matching, not the inner enumerables.
To stop people from accidentally using comparison functions when they should be asserting, add ItemsSatisfy, AllItemsSatisfy etc. functions that take Funcs instead of Actions, and mark them as obsolete.
Replace single extension with two more constrained extensions:
public static void ShouldBeNull<TActual>(this TActual actual, string message = null) where TActual : class { }
public static void ShouldBeNull<TActual>(this TActual? actual, string message = null) where TActual : struct { }
One of the versions is 2.0.0.0 and another is 2.0.0.17941 (which is what gets used in the reference), which might be the problem. They should probably both be 2.0.0 (or whatever version the NuGet package is).
Should support ValueTask & IAsyncEnumerable. Record types are probably fine, but better double-check.
As much as I hoped to avoid it, I keep needing to assert that a task doesn't complete after a certain period of time. If it has a default timeout, it should be much less than ShouldComplete's default of 1 second.
Instead of
listA.ShouldMatch(listB, (a, b) => a.Prop == b.Prop));
you should be able to assert:
listA.ShouldMatch(listB, (a, b) => a.Prop.ShouldBe(b.Prop));
The error messages would be a lot more useful when you know which property didn't match.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.