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
2
votes
1 answer

FluentAssertions causing ObjectDisposedException when ExcludingNestedObjects is set

I have an EF model defined as follows: public class ProgramManagerRolePermission { [Key, Column(Order = 1)] public Guid ShardKey { get; set; } [Key, Column(Order = 2)] public Guid RoleId { get; set; } [Key, Column(Order = 3)] …
Craig W.
  • 17,838
  • 6
  • 49
  • 82
2
votes
1 answer

Output additional information when tests fail

One of my test containing Assert.Equal(2, list.Count); fails on Appveyor, a continuous integration server, but I cannot reproduce the failure on my local machine. I hope to get more information from the error message, but don't know how to do. The…
Gqqnbig
  • 5,845
  • 10
  • 45
  • 86
2
votes
1 answer

Using FluentAssertions to compare two collections of dictionaries that are containing different types

From our database, we querying sets of records that are put in a collection of dynamic objects of type ExpandoObject that implements IDictionary on the fields. These are the actual values. From our SpecFlow BDD tests we get a…
AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47
2
votes
1 answer

Should FluentAssertions be used in production code?

I've been using FluentAssertions for unit testing and was wondering why it's only ever mentioned in that context. If you generally write fail-fast production code with guards you would have to duplicate some of the functionality FluentAssertions…
Nelson Rothermel
  • 9,436
  • 8
  • 62
  • 81
2
votes
0 answers

FluentAssertions: Changing default comparison of ShouldBeEquivalent for property

I have a model with a boolean property called "InActiveFlag" which comes from a third party API. This gets mapped to a property called "IsActive" in my view model. "IsActive" is the inverse of "InActiveFlag" Here is the ViewModel Class: public class…
Jason Learmouth
  • 569
  • 5
  • 9
2
votes
3 answers

Comparing lists of objects with double property with FluentAssertions (C#)

I am trying to compare two list of objects with FluentAssertions. The objects have a property stored as a double that may be off by a small amount. Is there an efficient way to do this without iterating through the lists? My current method looks…
yinnonsanders
  • 1,831
  • 11
  • 28
2
votes
1 answer

Fluent Assertions: check if the collection contains the object, equivalent to the provided one?

I am using Fluent Assertions and willing to test if my collection contains some object using deep object graph comparison. I don't want to implement all that equality members. However, I can not find the way to do the test for equivalence…
Oleksandr Nechai
  • 1,811
  • 16
  • 27
2
votes
2 answers

Fluent-ASsertions ShouldRaisePropertyChangeFor does not work for async Tasks?

I have a simple class that implements INotifyPropertyChanged, I invoke the property change on another thread, and I had a pretty hard time getting FluentAsserts to see that the propertyChanged was invoked. It does not seem to happen if I use a…
2
votes
2 answers

Running XUnit and FluentAssertions with OpenCover gives error message

I am trying to run code coverage with Xunit and Fluent Assertions on ASP.NET Core. However, I am getting an error message which I don't really understand. My project.json of the test project: { "version": "1.0.0-*", "testRunner": "xunit", …
Stefan
  • 1,590
  • 3
  • 18
  • 33
2
votes
1 answer

FluentAssertions Recursion Depth Reached in object with recursive structure

I'm trying to unit test an object that recursively represents a directory structure, but even at the simplest level the fluentAssertions ShouldBeEquivalentTo is failing with The maximum recursion depth was reached. How should this test be written to…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
2
votes
2 answers

FluentAssertions: how to specify that collection should contain a certain number of elements matching predicate?

For ex. I need to assert that list: var list = new List { "James", "Michael", "Tom", "John" }; Should contain a certain number (currently 2) of elements matching specific predicate: list.Should().Contain(element => element.StartsWith("J"),…
Hopeless
  • 579
  • 1
  • 8
  • 25
2
votes
1 answer

How to write FluentAssertion for nested collections, order independent?

Using FluentAssertions 3.5.1, I'm trying to assert that a List of Integer arrays is equivalent to another list of integer arrays, without caring about item order. This is not working. In trying to break this problem down, I've tried to assert that…
Michael Ray Lovett
  • 6,668
  • 7
  • 27
  • 36
2
votes
1 answer

How to specify key and value comparers for checking dictionaries in Fluent Assertions?

I'm just getting started with Fluent Assertions 4.1.1. Looks like the code for comparing dictionaries is actualDictionary.ShouldAllBeEquivalentTo(expectedDictionary); but how do I specify my own equality function (comparer) for the keys and values…
EM0
  • 5,369
  • 7
  • 51
  • 85
2
votes
0 answers

How to (correctly) exclude read-only properties with FluentAssertions?

I'd like to do a deep object comparison with FluentAssertions' awesome ShouldBeEquivalent method that excludes read-only properties. The following works: x.ShouldBeEquivalentTo(y, opts => opts.Excluding(si => !si.PropertyInfo.CanWrite)); But…
Todd Menier
  • 37,557
  • 17
  • 150
  • 173
2
votes
0 answers

FluentAssertions graph comparison, ExcludingNestedObjects ignored?

I've got a unit/integration test as follows. using (var repository = _factory.Get()) { applicationBefore = repository.Applications .Include(a => a.AcceptedAgreements) .Single(a => a.AggregateId == applicationId); } // Perform an…
Craig W.
  • 17,838
  • 6
  • 49
  • 82