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

Using Fluent assertion to compare XML file having multiple Elements with same Name

I am trying to check the elements of an xml file I generate. I use Fluent Assertions and I am sure there must be a way to assert that "this element exists in the document" by providing only one argument. For testing purposes, I need to know if some…
vvilin
  • 185
  • 10
0
votes
2 answers

Calling Excluding method in extension method for FluentAssertions.Primitives.ObjectAssertions does not work, but calling it normally works

I have started using FluentAssertions library in my integration tests for the REST endpoints. The problem is I have to compare two entities, but excluding their _id properties. This property is being inherited from my IEntity interface. public…
0
votes
0 answers

Assert ONLY json .Net Object attributes name without values

Is that possible to assert just the json attribute names rather than values. Actual: { CartId = 0 ConvertedAt = null Currency = BankCurrency { BaseCurrencyCode = null BaseToGlobalRate = 0 BaseToQuoteRate = 0 …
Shabar
  • 2,617
  • 11
  • 57
  • 98
0
votes
1 answer

unit test convert to dto extension method with fluentconversion

if i have a extension method that converts an Person object to a PersonDTO then should i unit test that the conversion occurs correctly if so and i use fluentassertions how do i assert that the conversion is correct my extension method…
JimmyShoe
  • 2,009
  • 4
  • 21
  • 40
0
votes
1 answer

Testing list equivalency by including properties in nested lists using Fluent Assertions

Is there a way to assert the equivalency of two lists of objects by properties located in a nested list? I know you can test equivalency with ShouldAllBeEquivalentTo() and Include() only certain properties, but I would like to call Include() on a…
Craig Curtis
  • 853
  • 10
  • 24
0
votes
1 answer

FluentAssertions Compare two IQueryables

I have two Iqueryables which have different values. I want to use FluentAssertions to compare the elements in the Iqueryable for my Unittests. What I have is the following: [Fact] public void TestCompareIQueryables() { // Arrange var…
Robbert Raats
  • 259
  • 3
  • 18
0
votes
1 answer

Mixing MockVerify and FluentAssertions.Should() in C#

I am trying the following in my Unit Test: var sut = new MyClass(dependentOne.Object, dependentTwo.Object); Action act = () => sut.DoSomething(); // Assert dependentOne.Verify(m => m.MethodOne(), Times.Once); …
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
0
votes
2 answers

FluentAssertion - Adding assertion to if statement

I have the following Fluent Assertion which i would like to put in an if statement. I get an error saying I cannot implicitly convert type to bool. I have tried to explicitly cast it but i still get an error saying cannot convert type to…
Miko
  • 109
  • 1
  • 7
0
votes
1 answer

FluentAssertions .ShouldNotThrow() method is not found with ver5.4.2 but it's found with ver4.19.4

I have a salt-of-the-earth test project target .net4.7.1. I installed FluentAssertions ver5.4.2 via nuget package manager of visual studio. For some reason this kind of things: someAction.ShouldNotThrow() Was throwing an error about…
XDS
  • 3,786
  • 2
  • 36
  • 56
0
votes
1 answer

Does FluentAssertions support Test projects that are .NET Core 2.0?

I have a Class Library (.NET Core 2.0) being tested by an MSTest Test Project (.NET Core 2.0). The FluentAssertions site says .NET Core 2.0 is supported (and I stepped down from 2.1). It works locally, but on the build machine I get the following…
KarlZ
  • 170
  • 9
0
votes
0 answers

Fluent Assertions: Approximately compare Dictionary values

I'm once again having difficulty getting the customisable aspects of FluentAssertions Should().BeEquivalentTo to do what I'm after. The current problem is approximately comparing dictionary values. How would I go about getting this test to pass…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
0
votes
0 answers

FluentAssertions: use Should().NotThrow() on async method

Is use c# FluentAssertions and I want to assert if i given async method does not throw an exception. Given a synchronous method, fluent assertions libray allows me to assert like this Action action = () => YourSynchronousMethod(); …
hannes neukermans
  • 12,017
  • 7
  • 37
  • 56
0
votes
1 answer

Asserting Redirect to Action

When using ASP.Net Core 2 MVC and FluentAssertions.AspNetCore.Mvc, how do I assert that a controller redirected to an action? For example, given the following controller action: public IActionResult SomeAction() { return…
Ben Gribaudo
  • 5,057
  • 1
  • 40
  • 75
0
votes
0 answers

FluentAssertions throws ArgumentOutOfRangeException when assertion fails (possibly NCrunch related)

I'm using FluentAssertions 5.3.0 run under NCrunch 3.14.0.1. When a test fails, I often seen this error as FluentAssertions tries to generate a report message... System.ArgumentOutOfRangeException: startIndex cannot be larger than length of…
NeilMacMullen
  • 3,339
  • 2
  • 20
  • 22
0
votes
2 answers

FluentAssertions - how to exclude comparison of dictionary keys?

Using Should().BeEquivalentTo() I want to compare 2 objects which contain a series of key-value pairs but to exclude the actual value of the keys because that will vary. So basically I'm only interested in comparing the contents of the…
FSatmar
  • 11
  • 3