Questions tagged [fluent-assertions]

Fluent Assertions is a set of .NET extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style test and which tries to keep you out of the debugger hell. Targets .NET Framework 4.5 and 4.7, as well as .NET Core 2.0, .NET Core 3.0, .NET Standard 1.3, 1.6 and 2.0. Supports the unit test frameworks MSTest, MSTest2, Gallio, NUnit, XUnit, MBUnit, MSpec, and NSpec.

Fluent Assertions is a library with extension methods to be used for assertions in your unit tests. The main goals of Fluent Assertions are to keep your unit tests readable, and to give descriptive error messages in case of failing tests.

Resources

394 questions
1
vote
2 answers

Fluent Assertions between two collection class

I have a class with collection class inside public class SearchResult { public int Id { get; set; } public int Total { get; set; } public IEnumerable Books { get; set; } } public class Book { public int BookId…
Jack Man
  • 19
  • 3
1
vote
1 answer

how to combine multiple assertion using FluentAssertions

I came to know that through FluentAssertions library we can combine multiple assertion in a single like. Just want to know if below 2 assert can be combined in a single line? // Act IActionResult actionResult =…
user584018
  • 10,186
  • 15
  • 74
  • 160
1
vote
1 answer

Is there an equivalent way to use Fluent Assertions as replacement for Moq.Verify?

We use the Moq framework and FluentAssertions in oue tests. At the moment we use both to do our assertions, e.g. we will verify that methods etc. on mocks are called. It would be great, if we could do this within the FluentAssertions framework as we…
1
vote
2 answers

Formatting Exception displayed when a unit test fails (xunit , C#)

I am using .Net6 + Xunit + Fluent Assertions and am trying to format the exception display that is output to console when an exception is encountered. (what I really want to see is the Data property on the Exception) In my program itself I add a…
ehiller
  • 1,346
  • 17
  • 32
1
vote
1 answer

Is it possible to suppress the "with configuration:" part of a fluent assertion message

I have a parameterised test I run from the command line and when all the tests fail, in the error message I'm getting this text for each failure: With configuration: - Use declared types and members - Compare enums by value - Include all non-private…
sixeyes
  • 483
  • 3
  • 14
1
vote
1 answer

How to create custom FluentAssertion error messages?

I have a test that looks something like this: using (new AssertionScope()) { foreach (var parameterType in parameterTypes) { var fooType = typeof(IFoo<>); var genericType = providerType.MakeGenericType(parameterType); …
ilitirit
  • 16,016
  • 18
  • 72
  • 111
1
vote
0 answers

FluentAssertions: Assert that a collection contains any item that contains a string (case insensitive)

I have a collection of strings var greetings = new[] { "Hello boy", "Hello girl", "Hello all"}; I would like to create an assertion using FluentAssertions that verifies that the collection contains at least one item that contains a given…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
1
vote
2 answers

Fluent Assertions: Equivalency of two lists of arrays, with arrays needing strict ordering

I'm trying to use Fluent Assertions to test a permutation generating algorithm. The algorithm generates a List, where the List order does not matter, but the elements of each int[] do. [Fact] public void Are_all_permutations_generated() { …
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
1
vote
0 answers

Fluent assertion - compare empty objects

I'm generating a C# solution using another project. The generated solution contains multiple classes and a unit test file for each class. A unit test creates two instances of a class and compares them. For the comparison, I chose FluentAssertion (I…
rotem agel
  • 11
  • 3
1
vote
2 answers

Fluent Assertion - compare models properties ignoring null values

case I am working on is - what is best solution to compare two objects with properties but excluding members with null values. Ex. objectA.prop1 = "value1"; objectA.prop2 = "value2"; objectA.prop3 = "value3"; expectedObjectB.prop1 =…
MichalM
  • 11
  • 4
1
vote
0 answers

Is there a possibility to get back in a list the passed and failed fields in Fluent Assertion?

Is there a possibility to get back a list of failed and passed objects in Fluent Assertions? E.g. var results = actual.Should().BeEquivalentTo(tc.Expected); I am trying to get all of the results so that I could build an HTML report, which would…
YoungDad
  • 765
  • 2
  • 6
  • 14
1
vote
1 answer

Does FluentAssertions support WithStrictOrdering for dictionaries?

I'm comparing two simple dictionaries. I add items to the dictionaries in opposite order. I'm using the WithStrictOrdering option in FluentAssertions but this test passes and I think it should fail: var actual = new Dictionary
NJS
  • 426
  • 4
  • 15
1
vote
2 answers

How am I mis-using NotThrowAsync

I used FluentAssertions; it's great! :) I particularly like using the .Invoking().Should().Throw() pattern it provides. I wrote this line in my test: myObject.Invoking(r => r.SomeAsyncFunc()).Should().NotThrowAsync(); Where…
Brondahl
  • 7,402
  • 5
  • 45
  • 74
1
vote
2 answers

Fluent Assertions: Be() vs Equals()

What is the difference between: subject.Should().Be(expected) subject.Should().Equals(expected) I always use Be(), but I now have a testcase where Be() gives a different result, then Equals(). My testcase involves a struct and comparing it with…
Remy van Duijkeren
  • 9,894
  • 1
  • 19
  • 12
1
vote
1 answer

How do I compare object graphs that are linked by means of IDs?

The Fluent Assertions library puts quite some emphasis on its capabilities of comparing object graphs by means of the Should().BeEquivalentTo method and related methods. As the documentation points out: Should().BeEquivalentTo is a very powerful…
F-H
  • 663
  • 1
  • 10
  • 21