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
0
votes
0 answers

How to increase the context of the line difference in FluentAssertions

For example, I have the first "Good day brother" and the second "Good day sister" line, where in FluentAssertions, when calling the Should().Be() method, I will get the following error: Expected string to be "Good day sister" with a length of 15,…
0
votes
1 answer

C# Deeply Compare Nested Collections with FluentAssertions

How can I write a unit test such that the following two objects are considered equal? And in general how can I ensure collections nested arbitrarily deeply are compared against counterpart via their matching index location (Lists) and matching key…
AffluentOwl
  • 3,337
  • 5
  • 22
  • 32
0
votes
0 answers

How to assert some combinations of Enum Values are true while all other should be false in xUnit

In short: Is there an easy way to make a unit test to assert a combination of 2 Enum value combinations results in true while all other combinations results in false? Detailed situation: There is a method, taking two Enum values and returning bool.…
this.myself
  • 2,101
  • 2
  • 22
  • 36
0
votes
1 answer

How can I assert the duration of the synchronous part of an async call?

I need to assert that the initial synchronous part of an async method executes within a certain duration. Is this possible with fluent assertions? I also need to assert the minimum and maximum total duration (eg, using CompleteWithinAsync and…
tg73
  • 415
  • 3
  • 10
0
votes
1 answer

How do I assert that an async task should complete within a minimum and maximum time?

I can assert that a task should complete within a specified maximum time like this: await obj.Awaiting( o => o.DoSomethingAsync() ).Should().CompleteWithinAsync( 1.Second() ); But how can I also require that the task also takes at least a certain…
tg73
  • 415
  • 3
  • 10
0
votes
0 answers

FluentAssertions GraphComparison, all properties of only output object should be filled

Often in my team people forget to map certain fields from an input object to an output object. I wanted to write a library for unit testing, that checks if all properties on an output object have been filled with a value different than the default…
BartKrul
  • 577
  • 1
  • 8
  • 21
0
votes
1 answer

FluentAssertions: Assert all object properties are different from another object

Is there any way to assert that all properties of objectA are different from all properties of objectB using FluentAssertions? objectA and objectB are instances of the same class. .BeEquivalentTo() checks if any of the property is different. I'm…
Andrei
  • 450
  • 2
  • 9
0
votes
0 answers

Display discrepancies between collections

When asserting the equality of two string collections using collectionA.Should().Equal(collectionB) the message is: "Expected collectionA to be equal to {"a", "b", "c", …5 more…} , but {"a", "b", "c", …13 more…} contains 8 item(s) too many." Is…
Nafas
  • 183
  • 1
  • 9
0
votes
2 answers

FluentAssertions: Test if an Enumerable contains "subset" of itself

I'm looking for the elegant expression to test if an enumerable contains a 'subset' of itself. Lets me illustrate with a sample: [Fact] public void Test1() { // Arrange var expected = new[] { new {F1 = 1, F2 = "1" }, new…
dani herrera
  • 48,760
  • 8
  • 117
  • 177
0
votes
0 answers

How can I used BeEquivalentTo to make null equivalent to empty?

How can I used BeEquivalentTo to compare ActualObject.Flied=null and ExpectedObject.Filed = String.Empty and get they are equivalent? I am looking for something…
0
votes
1 answer

Fluent assertions event monitoring does not work

I try to using following features for my unit testing https://fluentassertions.com/eventmonitoring/ But I catch a strange exception on execution line. Message:  System.InvalidProgramException : Common Language Runtime detected an invalid program. …
0
votes
1 answer

FluentAssertions .Pass declaration

After performing a test, we typically do an Assert.True(someCondition). When a condition check isn't necessary and just completion of the test is sufficient, I end a test with Assert.Pass(). I'm using FluentAssertions and have been doing…
BillRob
  • 4,659
  • 4
  • 26
  • 38
0
votes
0 answers

Can I assert that certain Http requests were made BEFORE or AFTER other Http requests in an Xunit unit test?

I have a simple Xunit project setup to test my code. During the method under test, I make two, separate, consecutive Http requests to an endpoint on the network. My test should check that the first Http request is always made BEFORE the second Http…
Ben Smith
  • 23
  • 4
0
votes
1 answer

IEnumerable.GetEnumerator unit Test

My part of code: public class BinaryTree : IEnumerable, IReadOnlyCollection where T : IComparable { ......... public IEnumerator GetEnumerator() { return…
Izauma
  • 3
  • 1
0
votes
1 answer

How to capture an exception thrown by an invocation using FluentAssertions

In FluentAssertions, how does one capture an exception thrown by an invocation? Exceptions shows basic code samples, but in my case I have a CustomException with a public enum. I'd like to assert that the correct enum value was thrown. public class…
user246392
  • 2,661
  • 11
  • 54
  • 96