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

Count verifications in unit test using Fluent Assertions and Nunit

I am looking for a solid way to keep track of the number of assertions made in a unit test for reporting purposes in automation. I know that with Nunit one is able to keep track of the assertions that are being made for a test with…
Jand
  • 406
  • 2
  • 7
  • 22
0
votes
1 answer

Fluent Assertions target framework

I had installed Fluent Assertions v.3 on the unit tests project and all was good until i had to update it to v.5. After that i get: Obj does not contain a definition for 'ShouldBeEquivalentTo' and no extension method 'ShouldBeEquivalentTo'…
Jake Manet
  • 1,174
  • 3
  • 15
  • 26
0
votes
1 answer

Fluent Assertion - Tuples

Is there a way for asserting Tuples using Fluent Assertions? var t1 = new Tuple>(Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}"), new [] { Guid.Parse("{DA18B047-2F62-45F0-A437-748976B41D22}") }); var t2 = new…
Andez
  • 5,588
  • 20
  • 75
  • 116
0
votes
1 answer

Setting FluentAssertions Expectation on Nullable Enum

I have the following object (reduced to single property for brevity) public class MyObject { public string MyProperty { get; set; } } and corresponding DTO public class MyDto { public MyEnum? MyProperty {get; set;} } and my mapping is set…
James B
  • 8,975
  • 13
  • 45
  • 83
0
votes
1 answer

Fluent Assertion namespace not recognised

I am using .Net version 4.6.1 and have installed fluent assertion 3.3.0 on an MVC4 project, but the namespace is not being recognised in the Unit Test of the project. Can anyone help?
kehoewex86
  • 21
  • 1
  • 12
0
votes
3 answers

Getting result from Func>

Method Under Test protected override async Task DoExecuteAsync(NameContext context) { context.ThrowIfNull("context"); var request = new Request { Id = context.Id, …
Muralikrishna
  • 159
  • 1
  • 11
0
votes
0 answers

FluentAssertions System.FormatException (possible bug)

I've been having some trouble with FluentAssertions lately, and after playing around with it a little bit, it seems like there is some sort of bug that may have something to do with Guids. Here's the code that throws an error: class Dto { …
yinnonsanders
  • 1,831
  • 11
  • 28
0
votes
1 answer

Prevent Unit Tests against Task

I have the problem that some Unit Tests are written against async methods. These methods return Task and I found one that tests if the return value is not null. Instead the test should have tested if the return value of the task is not null. This…
0
votes
2 answers

Ignore case for object properties when comparing collections

I have two collections that contain objects of my custom type. I compare these collections using FluentAssertions library: Collection1.Should().BeEquivalentTo(Collection2); Let's say, objects in the collections have string property called Title,…
YMM
  • 632
  • 1
  • 10
  • 21
0
votes
2 answers

Fluent assertions and comparison of List>

I have a problem using Fluent Assertions to compare two collections of type List>. When using the Should().Equal() method (order is important) I get the following (cryptic ;-) message: Expected collection to be equal to…
jvanderwoude
  • 17
  • 2
  • 5
0
votes
1 answer

FluentAssertion. How to verify that two lists have at least one the same element

I have expected and actual responses that look like JSON objects by default. In my case there are two lists. I have to verify that this two lists have at list one the same element. Function should be look like: (expectedResponse, actualResponse) =>…
Bazaka Bazaka
  • 135
  • 11
0
votes
1 answer

ShouldBeEquivalentTo with Exclude and case insensitivity comparison

I want to use ShouldBeEquivalentTo() of fluent Assertion, by excluding few properties and making it an case insensitive comparison. For ex. I am comparing below 2 objects admin and lookUp by excluding LastModifiedDate and the County comparison…
Haseena Parkar
  • 939
  • 2
  • 12
  • 28
0
votes
1 answer

Why does FluentAssertions ShouldBeEquivalentTo validate internals?

Recently I answered SO question describing how to avoid internal object state validation in FluentAssertions. Now I faced the same problem and wondering why does FluentAssertions validate internal properties OOTB? public class Class1 { [Fact] …
Serhii Shushliapin
  • 2,528
  • 2
  • 15
  • 32
0
votes
1 answer

How to assert if converter is applied on a type using Fluent Assertions

I need to apply some complex logic for creating map so i have used custom type converter as below: cfg.CreateMap>().ConvertUsing(); I am using fluentassertions in unit testing and want…
Sudama Tripathi
  • 349
  • 1
  • 5
  • 20
0
votes
1 answer

What is the simplest way to completely replace an assertion message using FA (and nunit)?

For example; results.Errors.Count.Should().Be(0, $"because {results.Errors[0]}"); produces the Result Message: Expected value to be 0 because 'Name' should not be empty., but found 2. But what I really want, in this particular instance (invocation…
davegi
  • 1