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

Is there a FluentAssertions Should for checking an XML document versus an expected document?

Is there a FluentAssertions "Should.Be" for checking an entire XML document versus an expected document?
SteveC
  • 15,808
  • 23
  • 102
  • 173
3
votes
2 answers

FluentAssertions: check a list contains an object, excluding a property

I have several Event classes which implement IEvent. To check actual event against expected event I use actualEvent.ShouldBeEquivalentTo(expectedEvent,opt => opt.RespectingRuntimeTypes() …
Darren Hall
  • 97
  • 1
  • 1
  • 9
3
votes
2 answers

Using ShouldBeEquivalentTo and handling different names

I want to make a mapper test that maps a database model to a dto In the database model there is class Order { long Id } But on the Dto the same field is named class OrderDto { long OrderId } Using ShouldBeEquivalentTo how do I tell…
Mech0z
  • 3,627
  • 6
  • 49
  • 85
3
votes
3 answers

Fluent Assertions : How to check for key value pair with out case

I have a dictionary of type Dictionary which I am trying assert with Fluent Assertions. I need to check if it contains a key called "iss" and value "ABC". I need to do assert the "value" field without considering the case. Is it…
Shetty
  • 1,792
  • 4
  • 22
  • 38
3
votes
1 answer

FluentAssertions Asserting an Exception has been thrown for an overloaded operator

I've been using FluentAssertions for my unit testing, and have started looking at asserting whether Exceptions are thrown correctly. I know that I can use the ExpectedExceptions method attribute, but I would like to learn the FluentAssertion…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
3
votes
1 answer

FluentAssertions WhenTypeIs double.NaN

I have two complex objects, with diferent types inside(objects, strings, doubles, etc). I want to compare them by using the following code: myActualObject.ShouldBeEquivalentTo(myExpectedObject, options => options .Using(dbl =>…
Jose
  • 1,857
  • 1
  • 16
  • 34
3
votes
1 answer

Comparing collections with different item types

I have two collections with different item types, for example: var collection1 = new List(); var collection2 = new List(); Is it possible to assert that two collections with different item types contain equal items in any order using…
Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
3
votes
1 answer

Fluent Assertions - Overriding comparison in ShouldBeEquivalentTo()

I have the following DTO: public class Dto { public DateTime Date { get; set; } } And I'm trying to override the comparison of a property using this syntax as per the FA wiki: public void Override_test() { // Arrange var actual = new…
Kevin Kuszyk
  • 1,958
  • 24
  • 37
3
votes
2 answers

How to assert a default value of a property with FluentAssertions?

I have a class with some fields/properties etc., of various types: public string SomeStringData; public int? SomeNullableIntegerData; public SomeDataClass SomeSpecificData; public int SomeIntegerData; In part of my code, only the SomeStringData…
Marcel
  • 15,039
  • 20
  • 92
  • 150
3
votes
2 answers

Extending Simple.Data with assertions

I'm using this very nice mini ORM, Simple.Data, to setup a lot of test data, quick and easy. I would really like to extend it for assertions. For example i would like to assert on count: Db.MyTable.GetCount(); <- Returns a dynamic So that I could…
Christian Mikkelsen
  • 1,661
  • 2
  • 19
  • 44
2
votes
4 answers

FluentAssertion fail to compare enumerable of strings

This code works fine [Test] public void boo() { var collection = new[] { 1, 2, 3 }; collection.Should().Equal(1, 2, 3); } But, this fails [Test] public void foo() { var collection = new[] { "1",…
Alexander Beletsky
  • 19,453
  • 9
  • 63
  • 86
2
votes
4 answers

How to mock exception types in "Throws" and "ThrowsAsync"

I would like to write one unit test for a set of different exception types. My common approach is to use InlineAutoMoqData for a certain set of test inputs. This works fine for values but I cannot get it working for types. Below you can find my idea…
xMutzelx
  • 566
  • 8
  • 22
2
votes
1 answer

FluentAssertions: Custom Double Comparer

I try to get started with FluentAssertions but quite soon I ran in a problem. I use it along with MSTest. The test below fails what shouldn´t happen (from my point of view). [TestMethod] public void DoubleTest() { double…
2
votes
1 answer

FluentAssertion, check constraint just for condition

Inside a c# test I'm asserting with FluentAssertion. But, in this test, the "assert" only should be executed under a condition (when result is not valid) This is my actual code: if (!result.IsValid) { result .Errors .Should() …
dani herrera
  • 48,760
  • 8
  • 117
  • 177
2
votes
1 answer

Fluent Assertions 6: Comparing two collections with different members types and names

In the previous versions of Fluent Assertions, there was a possibility to compare two collections with different members types and names by creating a class which implements IEquivalencyStep: https://stackoverflow.com/a/55898570 Unfortunately,…
rgb
  • 1,750
  • 1
  • 20
  • 35