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

fluentassertion won't compile

I am obviously missing some assembly or reference to make this work, it may be fluent assertions or it may be Microsoft.Team Foundation.Warehouse. Neither of which I am sure how to use / add as references (well I am sure how to install fluent…
Mr Heelis
  • 2,370
  • 4
  • 24
  • 34
2
votes
2 answers

Strange failure in Nunit test with NHibernate

running a simple test with NUnit and FluentAssertion i have this messagge for failure: Expected object to be Gedi.Domain.Object.Entity.Persona { Annullato = False Descrizione = "Persona1" Id = 1 }, but found…
gt.guybrush
  • 1,320
  • 3
  • 19
  • 48
2
votes
1 answer

FluentAssertions reference not importing properly

If I download FluentAssertions 1.7.1 (which all of my unit tests are currently written against) then I can do a reference to the dll and the test below will work just fine. But I tried to upgrade via NuGet and using FluentAssertions versions 3.0.90…
HodlDwon
  • 1,131
  • 1
  • 13
  • 30
2
votes
1 answer

String comparison assertion failing when it looks like it should pass

I have a test for checking that an item is serialized correctly public interface IMyJsIdentity { string Forename { get; } string Surname { get; } string Guid { get; } } public class MyIdentity : IMyJsIdentity { …
Neil
  • 5,179
  • 8
  • 48
  • 87
2
votes
1 answer

FluentAssertions fails when comparing objects if one property is nullable

Scenario: I have an object with a nullable property that will be updated when I run the method under test. In the expected object, I don't specify it, since I want to validate the value separately. Here is a simple test demonstration using…
Eris
  • 7,378
  • 1
  • 30
  • 45
2
votes
2 answers

How do I compare a list of dictionaries for equality in C#

I'm trying to compare 2 objects expectedItems and resultItems of type IEnumerable> but haven't been able to do much with it. Also, one dictionary is initialised in the code, and the other one is built from a JSON response…
divyanshm
  • 6,600
  • 7
  • 43
  • 72
2
votes
3 answers

How to use Fluid Assertions .ShouldBeNull()

I am trying to use the Fluent Assertions ShouldBeNull() extension method to assert that my instance is indeed null. Result.ShouldBeNull(); Clearly, this throws an exception because I cannot call the extension on a null…
Nick
  • 6,366
  • 5
  • 43
  • 62
2
votes
3 answers

Nunit: Which assert to use to ensure that everything passed at the end of my unit test?

I have written a test and I just want to ensure that everything passed and no exceptions were thrown ? Is there some kind of special Assert to use at the end of the test? What are the recommendations here? Thanks in advance
Martin
  • 23,844
  • 55
  • 201
  • 327
2
votes
2 answers

Verifying function call order in a unit test

I want a unit test that verifies 2 function calls happen in the correct order. In the example, the first function encrypts a file and saves it to the file system, and the second function sends the encrypted file to a 3rd party processor (via FTP). I…
Matt Slavicek
  • 841
  • 10
  • 18
2
votes
2 answers

Should().Contain() with equivalency options

I am attempting to assert that a collection of Claims contains an expected set of claims. The problem that I seem to be running into is that there's no way to check for a subset and supply my own equivalency options. var expected = new[] { new…
joshperry
  • 41,167
  • 16
  • 88
  • 103
1
vote
1 answer

FluentAssertions Reflection-based equal

I have a simple class: public class MyClass() { public string Property1 {get;set;} public string Property2 {get;set;} } Is there any way to asssert two instances of this class for equality without Equal method implementation (I guess reflection…
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
1
vote
1 answer

Testing ValueTask method with FluentAssertions, should not throw

I'm a bit confused here. I'm using FluentAssertions and I have this test method: [Test] public void DoNothingWhenEmpty() { FileCleanUpProcessor fileProcessor = new(); Func act = () =>…
AlexB
  • 4,167
  • 4
  • 45
  • 117
1
vote
2 answers

How to use FluentAssertions to test for the fact that all properties should have been modified without having any known/fixed target property values

I want to use FluentAssertion's object graph comparison to assert the fact that all properties have been changed/modified to any value I don't care about the target value. Actually, to highlight that, let's say I do not even have access to the…
rklec
  • 73
  • 10
1
vote
1 answer

How to check nullable int against nullable enum in unit test assertion?

Writing some integration tests we want to compare values read from the DB (int) against the object being used (enum field on a DTO). So conceptually dto.EnumValue.Should().Be((MyEnum)expectedIntValue) However these are both nullable. I know how to…
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
1
vote
0 answers

Getting "'" instead of string in output of VSTest@2 in test run where soft assertion fails

I use Fluent Assertions in Visual Studio when I write automated tests in C#/Selenium. I HAVE PLACED AN INTENTIONAL FAILED ASSERTION IN MY CODE to demonstrate the problem. The output looks fine on Failed soft assertions in my runs on Dev Studio. In…