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

BeEquivalentTo doesn't work with Anonymous Methods

I have an xunit test using FA 4.19.3. I have recently upgraded to 5.3.0 without too many issues, except for some Object graph comparisons. Old test: var result = await MyClass.GetResultAsync(); result.ShouldBeEquivalentTo(new { StatusCode =…
Allan Nielsen
  • 260
  • 2
  • 13
1
vote
0 answers

Can't use FluentAssertions/Shouldly

I wanted to use FluentAssertions or Shouldly so I added packageReference like this:
Mate
  • 192
  • 2
  • 18
1
vote
1 answer

How to use Excluding in FluentAssertions to exclude specific KeyValue pair in Dictionary

I'm using FluentAssertions with ShouldBeEquivalentTo to compare two dictionaries of type Dictionary but want to exclude one or more specific KeyValue pairs (because they contain timestamps in this case). How to do this? I tried…
jvanderwoude
  • 17
  • 2
  • 5
1
vote
1 answer

Fluent Assertions ShouldBeEquivalentTo always passes with different properties

I've created a simple composite pattern with a component defined as public abstract class Component : IEnumerable { protected EntityComponent(int id) { Id = id; } public int Id { get;…
James B
  • 8,975
  • 13
  • 45
  • 83
1
vote
2 answers

How to check property changed signalled with FluentAssertions when internally raised for all properties?

I'm using FluentAssertions to check the view models. I would like to verify correctly raising PropertyChanged events for the properties. This is working fine when signaling individual properties: public string MyName { get => this.myName; set =>…
lg2de
  • 616
  • 4
  • 16
1
vote
1 answer

How to display items not in actual list but are in expected list using fluentassertions?

Lets say I have 2 dictionary objects: Dictionary dictA, Dictionary dictB. I'm doing the following when comparing them: dictB.ShouldBeEquivalentTo(dictA); When the total items do not match, I just get a message…
quldude
  • 507
  • 5
  • 16
1
vote
1 answer

How to enter into this rulefor fluent validation only if textbox is empty

I am using simple form fluent validations. How to enter into this rule only if it's Notes Textbox is empty and should return validation if that linq query returns a record. If textbox is not empty it should not enter into this rule. Here's what I…
sgl
  • 563
  • 1
  • 6
  • 16
1
vote
1 answer

Ignore DataMember in Fluent Assertions.ShouldBeEquivalentTo

I'm using the FluentAssertions library to verify serialization is working as expected using the DataContractSerializer. Many of the objects I'm serializing have [IgnoreDataMember] attributes on some properties. Is there a a way to instruct fluent…
on3al
  • 2,090
  • 4
  • 20
  • 19
1
vote
1 answer

CollectionAssert.AreEquivalent in FluentAssertions?

I'm trying to replace usage of "CollectionAssert.AreEquivalent()" with FluentAssertion". I've tried using ShouldAllBeEquivalentTo, but the function doesn't fail when comparing similar objects of different types. In the example below, both calls…
FrequentGuest
  • 182
  • 2
  • 11
1
vote
1 answer

Binary serialize a .NET Exception-derived class; unit testing with FluentAssertions

I have a custom exception that takes in a couple strings in the ctor followed by the usual Exception innerException last parameter. The exception class is decorated with [Serializable]. This exception class MyException also inherits from…
Glenn Doten
  • 2,603
  • 3
  • 21
  • 22
1
vote
1 answer

FluentAssertions fails when comparing exception messages

I just updated my old project to use version 4.13.0 and there was a lot of exception validation with ComparisonMode.Substring, but ComparisonMode.Substring does not exist in the newest version. I found this that explains that: As a result of this,…
Mech0z
  • 3,627
  • 6
  • 49
  • 85
1
vote
2 answers

Comparing Collections Fluent Assertions Should All Be Equivalent To Synonyms

I'm using Fluent Assertions to Validate to different test Objects public class DTO { public int Key {get; set;} public string Code { get; set; } } public class KeyDTO { public int Id {get; set;} public string Code { get; set; } } Note:…
johnny 5
  • 19,893
  • 50
  • 121
  • 195
1
vote
3 answers

FluentAssertions; combining collection and object graph comparison assertions

I am trying to use FluentAssertions to combine collection and object graph comparison assertions. I have the following class. public class Contract { public Guid Id { get; set; } public string Name { get; set; } } Which are returned in a…
James Wood
  • 17,286
  • 4
  • 46
  • 89
1
vote
1 answer

How can I assert a collection is sorted by 2 properties with FluentAssertions?

I recently discovered that FluentAssertions has a collection assertion named BeInAscendingOrder. Awesome! public class MyItems { public int SequenceNumber { get; set; } public int Name { get; set; } } IList resultingList =…
Larry Fix
  • 187
  • 8
1
vote
1 answer

FluentAssertions: How to compare properties of a different name

I have two objects of the same type that I need to compare, but the value of one object property on objectA should be equal to a property of a different name on objectB. Given my object: class MyObject { public string Alpha {get; set;} …