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

Unit Test with Async is Inconclusive with FluentAssertions and NSubstitute

I'm testing this factory public class ContratoFactory : IContratoFactory { private readonly IContratoPodeSerCriadoValidation _contratoPodeSerCriadoValidation; public ContratoFactory(IContratoPodeSerCriadoValidation…
Jedi31
  • 735
  • 1
  • 6
  • 22
1
vote
1 answer

Fluent Assertions: Approximately compare the properties of objects stored in Lists

This question builds on one I previously asked: Fluent Assertions: Approximately compare a classes properties If I have a class, say Vector3 public class Vector3 { public double X { get; } public double Y { get; } public double Z { get;…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
1
vote
2 answers

Fluent Assertions: Approximately compare two 2D rectangular arrays

I'm able to approximately compare two 2D rectangular arrays in Fluent Assertions like this: float precision = 1e-5f; float[,] expectedArray = new float[,] { { 3.1f, 4.5f}, { 2, 4} }; float[,] calculatedArray = new float[,] { { 3.09f, 4.49f}, { 2, 4}…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
1
vote
2 answers

How can I report on the name of an object with fluent assertions

I have a test that checks several objects in a table on our website. The test is written in SpecFlow and C# It looks something like this: When I click proceed Then I should see the following values | key | value | | tax |…
Festivejelly
  • 670
  • 2
  • 12
  • 30
1
vote
2 answers

Update to latest FluentAssertions breaks my unittests

I am trying to update my Unittest projects with the latest version of FluentAssertions (4.0.1), but my test do not compile anymore due to a change of the API. Before update I was using version 3.4.1 and the following code compiled and worked…
Jehof
  • 34,674
  • 10
  • 123
  • 155
1
vote
1 answer

Fluent Assertions OnlyContain

Using FluentAssertions, I want to check a list only contains objects with certain values. For example, I attempted to use a lambda; myobject.Should().OnlyContain(x=>x.SomeProperty == "SomeValue"); However, this syntax is not allowed.
djnz
  • 109
  • 1
  • 14
1
vote
1 answer

How to assert two lists are not equivalent if in different order using Fluent Assertions

Using Fluent Assertions we can assert that two collections are equal (in terms of property values) using something like: list1.ShouldBeEquivalentTo(list2); Assuming list1 and list2 are contain the same objects in any order, the assertion will be…
davy
  • 4,474
  • 10
  • 48
  • 71
1
vote
2 answers

How to test whether my factories are properly bound?

Using Ninject, I have the following and wish to test using FluentAssertions: [Test] public void InterfacesEndingWithFactoryShouldBeBoundAsFactories() { // Given IKernel kernel = new StandardKernel(); kernel.Bind(services => services …
Will Marcouiller
  • 23,773
  • 22
  • 96
  • 162
1
vote
1 answer

Fluent Assertions ThatAreNotDecoratedWith

I would like to use FluentAssertions to test for all methods that are not decorated with the NonActionAttribute. (This will reduce the set of action methods automatically generated as placeholders by T4MVC.) My specific problem is with chaining…
Kevin Swarts
  • 435
  • 7
  • 17
1
vote
1 answer

Fluent Assertion custom comparison with ref arguments

I have a matrix struct, and custom comparison methods: static bool AlmostEquals(ref Matrix a, ref Matrix b); static bool AlmostEquals(ref Matrix a, ref Matrix b, float epsilon); What's the correct call to Fluent Assertion to get this comparison to…
Wilbert
  • 7,251
  • 6
  • 51
  • 91
1
vote
1 answer

ShouldBeEquivalentTo for objects with different types

In my test I have the result of type HttpRequestMessage and I need to assert that it's property Content is set to correct object. The problem is that HttpRequestMessage.Content has a different (base) type than the object I want to compare with and I…
Michael Logutov
  • 2,551
  • 4
  • 28
  • 32
1
vote
1 answer

How to successfully set a breakpoint within FluentAssertions 2.1.0.0?

Using Visual Studio 2013, I have installed FluentAssertions 2.1.0.0 via NuGet into this C# project, but am unable to set breakpoints within FluentAssertions even though I have pointed the debugger to its source code at tag v2.1. How can I…
aknuds1
  • 65,625
  • 67
  • 195
  • 317
1
vote
2 answers

ShouldBeEquivalentTo failing for equivalent objects when the subject is a DateTime

What I'm trying to do I've just set up a test to ensure that a NodaTime LocalDateTime is mapped to a .NET DateTime, retaining the same date and time values. I'm using FluentAssertions' ShouldBeEquivalentTo method to compare the corresponding…
Sam
  • 40,644
  • 36
  • 176
  • 219
1
vote
2 answers

Fluent Assertions PropertyInfo BeDecoratedWith

The .NET FluentAssertions library (version 2.1.0) has several BeDecoratedWith() implementations for asserting that a type (or type member) has a given attribute applied to it. These calls look like this: typeof(X).Should() …
nikmd23
  • 9,095
  • 4
  • 42
  • 57
1
vote
1 answer

Assert that a float is approximate to one of several values

I'm trying to use Fluent Assertions to verify that a vector projected onto its own axis is approximate to either v.Length() or -v.Length(). I can assert that the projection is approximate: result.Should().BeApproximately(v.Length()) or I can assert…
Alex
  • 7,639
  • 3
  • 45
  • 58