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
0 answers

How to customize Fluent Assertions error message

I want to prepend a component name and the type information before any errors are shown. Typically I am asserting custom types. I want to know which types are being compared before seeing the rest of the error messages which are focused only on the…
Ceco
  • 1,586
  • 3
  • 16
  • 23
0
votes
1 answer

FluentAssertion : Assert object equality with private inner list of object

I try to make a test using FluentAssertion pass but i get the famous "System.InvalidOperationException : No members were found for comparison" and i don't know how i can make it pass in this specific context. The root compared object type has a…
MigMax
  • 80
  • 4
0
votes
2 answers

Fluent Assertions: XElement .Should().HaveValueContaining?

I want to test that an XML element's value contains a particular string. [The code below is clearly highly contrived and not from the real codebase I am working on]. How to check with Fluent Assertions that the XElement's Value contains a…
Adrian S
  • 514
  • 7
  • 16
0
votes
1 answer

FluentAssertions object graph comparison including JSON objects

I have a simple class with a property of type object, which can contain JSON built from different sources public class SimpleClass { public string Id { get; set; } public object JSONData { get; set; } } I'm using FluentAssertions object…
NJS
  • 426
  • 4
  • 15
0
votes
1 answer

How do you use `BeApproximately` with a value that changes in each iteration of a loop?

Description I'm iterating over 2 lists I want to compare the 2 values at each point in the list I want the value to be within 0.1% of each other Complete minimal example reproducing the issue var sheetRows = new List { -24.0, 0.1, 10}; var…
Smurf-IV
  • 1
  • 2
0
votes
1 answer

Using Fluent Assertion It is possible to attach the result of an assertion to a custom logger

I'm trying to determine the result of an assertion in order to use the output for reporting, something like this: ProblemResolution().Should().Match("easy"); Logger(Assertion.Result()); I also tried by creating an extension, but I can't figure out…
0
votes
1 answer

How to test a MessageBox in wpf?

I'm going to do some unit tests and I am struggling with a MessageBox. I have a MessageBox that is showing a text and an "Ok" button in my code. When I trying to unit test the method that contains the MessageBox.Show("Text"), it pops up in the unit…
Maria
  • 43
  • 2
  • 9
0
votes
1 answer

Incorrect identification of Visual Studio warning CA1806 (Do not ignore method results) when using FluentAssertion

I'm writing a C# unit test in Visual Studio 2019. I'm using Xunit with FluentAssertion. The two main lines of code (for illustrative purposes) in one of the tests are: Action a = () => new…
millie
  • 2,642
  • 10
  • 39
  • 58
0
votes
1 answer

FluentAssertions without exceptions?

This seems like a long shot... I am building a test harness for manual testing (for my QA Team). It runs in a console application and can output some level of smart data, but nothing so automatic as a fully automated test (not my rules). I would…
Vaccano
  • 78,325
  • 149
  • 468
  • 850
0
votes
3 answers

C# Testing - compare list of custom type

I'm trying to write test checking if JSON converter corectly deserialize input to my custom list [TestMethod] public void JSONInput_Changed() { List _expectedPointsOnChart; _expectedPointsOnChart = new…
Siewak
  • 35
  • 1
  • 4
0
votes
2 answers

C# FluentAssertions continue after Failed Assertion

Is it possible to continue after a failed Assertion in FluentAssertions? I had some assertions which are no show stoppers and should only be reported but not failing the Test run. [TestClass] public class UnitTest1 { [TestMethod] public…
Christian
  • 1,022
  • 13
  • 28
0
votes
0 answers

Reusing build-in object graph comparison in custom assertions in FluentAssertions

How can I reuse the FluentAssertions' build-in object graph comparison in my custom assertions class, so that I can use the options parameter to scope the comparison. Here is an example. There is a base entity called record that can represent…
GKalnytskyi
  • 579
  • 7
  • 16
0
votes
1 answer

How to assert a collection is a child of other collection using fluent-assertions?

I want to test a method returning collection using fluent-assertions to ensure that returned collection is a child of other collection, I tried fatherCollection.Should().Contain(childCollection); but not work. How to do that?
jimbo R
  • 253
  • 2
  • 3
  • 14
0
votes
1 answer

Fluents Assertions: exclude field recursively

I have simple class, for example class Person { public string Name; public string LastName; public Person Parent; public static int IdCounter = 0; public int Id; public Person(string name, string lastName, Person parent) { …
Arzybek
  • 547
  • 2
  • 6
  • 27
0
votes
1 answer

How to assert exceptions with FluentAssertions version 4.x?

I am working on a larger solution which is using FluentAssertions-4.8.0. As I currently don't have time to upgrade to the latest version (5.9.0 as of writing) I would like to know how to assert exceptions in the mentioned version. I know how its…
Matthias Güntert
  • 4,013
  • 6
  • 41
  • 89