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

Checking ShouldThrow Exception.Data in Fluent Assertions in .NET

OK, I am running a unit test to see if the Exception.Data property contains a specific value against a specific named key. Exception.Data is of type IDictionary. IDictionary only has 2 overloads which I cant see a way to verify what is in the…
Andez
  • 5,588
  • 20
  • 75
  • 116
7
votes
1 answer

I have a unit test project which references FluentAssertions, I get errors when I update to version 3

I have a .net 4.0 test project which is throwing a method not found exceptions for the Should() extension method. Then I noticed it also was throwing exceptions for an int type as well. Does anybody know why FluentAssertions V3 is behaving this…
BraveNewMath
  • 8,090
  • 5
  • 46
  • 51
7
votes
1 answer

FluentAssertions: match each object of a collection

How to check that each object of a collection conforms to a given predicate? E.g.: check for each item (from a given collection) that it matches a given predicate (MyPredicate). Code should probably look something like…
D.R.
  • 20,268
  • 21
  • 102
  • 205
7
votes
1 answer

FluentAssertions ShouldBeEquivalentTo() versus Should().BeEquivalentTo()

I have a test that verifies the collection output of a method. This variation of the test passes: [TestMethod, TestCategory("BVT")] public void TheStatusesAreReturned() { var expectedUnprocessedStatuses = new…
Matt Slavicek
  • 841
  • 10
  • 18
6
votes
1 answer

Fluent Assertions "Maximum recursion depth was reached…"

I have a number of nested complex objects that I'm attempting to compare with Fluent Assertions with the following code: restResponse.Should().BeEquivalentTo(mappedSoapResponse, options => { …
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
6
votes
1 answer

How to compare case insensitive string using FluentAssertions? C#

How can I easy compare string case insensitive using FluentAssertions? Something like: symbol.Should().Be(expectedSymbol, StringComparison.InvariantCultureIgnoreCase); Edit: Regarding possible duplicate and…
Krzysztof Morcinek
  • 1,011
  • 13
  • 42
6
votes
3 answers

How can I make FluentAssertions ShouldBeEquivalentTo check for type when comparing?

I have 2 dictionaries and I would expect the contents not to be equivalent as the dictionary contains values of different types. However the following test passes [Scenario] public void DictionariesWithDifferentTypesShouldBeEquivalent( …
Rachael
  • 61
  • 1
  • 2
6
votes
1 answer

Is this a bug when comparing a nullable type with its underlying type using FluentAssertions?

I was writing some unit tests for a utility library when I came across a test I would expect to fail that actually passed. The issue is related to comparing two float variables, versus comparing one float? and one float variable. I'm using the…
Julian
  • 20,008
  • 17
  • 77
  • 108
5
votes
1 answer

FluentAssertions Should.Equal on collections, containing nulls

FluentAssertions seems to fail with NullReferece exception when I try comparing two collections with nulls [Test] public void DeepWithNulls() { var l1 = new List { "aaa", null }; var l2 = new List { "aaa",…
tensorsigma
  • 71
  • 1
  • 4
5
votes
1 answer

Fluent Assertions ShouldAllBeEquivalentTo

I'm not sure if an old version of FluentAssertions had this or not but I'd like to compare a collection to another collection. I have a dto like so: public class UserDTO { public int Id { get; set; } public string Username { get; set;…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
5
votes
0 answers

FluentAssertions equivalent to xUnit Assert.Collection

What's the closest FluentAssertions equivalent to the following xUnit/FluentAssertions combo? Assert.Collection(things, thing => { thing.Id.Should().Be(guid1); thing.Name.Should().Be("Thing1"); …
nzkeith
  • 343
  • 2
  • 10
5
votes
1 answer

FluentAssertions: string does not contain a definition for ShouldBeEquivalentTo

I am trying to use Nspec. I have followed these instructions: http://nspec.org/ Create a class library project Nuget: Install-Package nspec Nuget: Install-Package FluentAssertions Create a class file and paste the following code: using…
w0051977
  • 15,099
  • 32
  • 152
  • 329
5
votes
1 answer

FluentAssertions: Should contain every element of sequence

I have a list, every single element should also show up in another list, but not necessarily in the same order. I could probably do the assert with a foreach, like this Assert.IsTrue(list1.Count == list2.Count); foreach(var element in list1) { …
Kaito Kid
  • 983
  • 4
  • 15
  • 34
5
votes
1 answer

How to compare nested lists in object graphs using fluent assertions

If I have an expected object graph that includes a list, like so: var expectedExperiment = new Experiment { Number= "12345", AllocatedInstrument = "Instrument 1", Experimenters = new…
Ed Vowles
  • 67
  • 5
5
votes
1 answer

Why are nested classes ignored in FluentAssertions when using "Including"?

To illustrate the problem, consider these three classes: class Orange { public String color { get; set; } } class Foo { public Int32 size { get; set; } public Orange orange { get; set; } } class Bar { public Int32 size { get; set; } …
Michael Ray Lovett
  • 6,668
  • 7
  • 27
  • 36