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

How can I make FluentAssertions ShouldBeEquivalentTo fail if expected has members that actual does not

I'm trying to make a "strict" compare using FluentAssertions ShouldBeEquivilantTo. Everything seems to work good if the "actual value" has properties that the "expected value" does not but I need to achieve the behavior so that if the "expected…
ashelley
  • 1
  • 1
0
votes
1 answer

Mocking inner objects gets lost with function call

I am mocking chessboard, on which I can add pieces. I want to unit test allowed LinearMoves, when there are some pieces on the chessboard. Code starts…
FrenkyB
  • 6,625
  • 14
  • 67
  • 114
0
votes
2 answers

.Net FluentAssertions .Contains doesn't compare objects properly

I'm using FluentAssertions and I need to compare 2 lists of objects. They are from the same class which contains the Values property. I want to compare both lists but I want all Values from list1 to exist on list2, but ignore extra values. Something…
Ricardo Smania
  • 2,939
  • 2
  • 26
  • 35
0
votes
2 answers

VS/xUnit/FluentAssertions: Provide file link in test message

In some of my tests I have to compare the content of XML files with some reference files (golden files approach). For comparing the XML files, I'm using XmlDiff, which produces HTML pointing out the differences of the files (see e.g. here). Now, in…
csoltenborn
  • 1,127
  • 1
  • 12
  • 22
0
votes
2 answers

Is it possible to use Fluent Assertions library with PowerShell?

Fluent Assertions is a .NET library for assertions of any kind, but I cannot get it to work with PowerShell. Is it possible at all? I used Add-Type cmdlet to add the library's DLLs and tried the following example: PS C:\Users\ymm> $test = 'test…
YMM
  • 632
  • 1
  • 10
  • 21
0
votes
1 answer

How to correctly combine Using and WhenTypeIs in Fluent Assertions

I have a dictionary of objects like so: Attributes = new Dictionary(); Within the dictionary is a DateTime, I am trying test if that DateTime falls on a particular day, like so: Attributes[key].ShouldBeEquivalentTo(DateTime.Now,…
James Wood
  • 17,286
  • 4
  • 46
  • 89
0
votes
1 answer

Show test output on pass in ReSharper test runner

When using ReSharper's built in test runner with FluentAssertions a test failing will produce an output message that you can specify within the test. In some cases having this output appear on a passing test would still be useful, mostly to help…
LWood
  • 417
  • 4
  • 16
0
votes
1 answer

Assert that two objects are exactly equivalent

In the simple example below I try do find a single Should() assertion that makes the test pass and fail the way I described in the comments. The one that I currently use result.ShouldBeEquivalentTo(expectedResult, o => o.RespectingRuntimeTypes())…
bitbonk
  • 48,890
  • 37
  • 186
  • 278
0
votes
1 answer

FluentAssertion failing on Mongo DateTime comparisons

I have a unit test using FluentAssertion resembling this: var instance = new ServiceInstance(name, "1.0.0", new Uri("http://www.google.com")); var id = registry.RegisterInstance(instance); registry.ExistsInstance(id).Should().BeTrue(); var…
David Brabant
  • 41,623
  • 16
  • 83
  • 111
0
votes
1 answer

How to test XElement's child element's attributes, values by using Fluent Assertions?

Let's say I have an XElement object, which represents Xml like Changed name Some dummy…
hardywang
  • 4,864
  • 11
  • 65
  • 101
0
votes
1 answer

FluentAssertions Comparing two list of different type

I wonder if there is a way to compare two lists of different types. I found this method: public AndConstraint Equal(IEnumerable expectation, Func predicate, string because = "", params object[] reasonArgs) …
Marco Medrano
  • 2,530
  • 1
  • 21
  • 35
0
votes
1 answer

FluentAssertions - complete tutorial for creating custom assertions

Has anybody seen a complete tutorial for creating custom assertion classes with FluentAssertions? Best regards
Yannik
  • 709
  • 1
  • 7
  • 11
0
votes
1 answer

FluentAssertions compile error after upgrade

I have upgraded my project to the latest FluentAssertions and got a weird compilation error on the following line: myArray.Should().Equal(new int[] { 0, 0, 1, 2, 3, 4, 5 }); The error is: 'System.Array' does not contain a definition for 'Should'…
SiberianGuy
  • 24,674
  • 56
  • 152
  • 266
0
votes
1 answer

How to check if Dictionary of type class can be verified using ContainValue in Fluent Assertion

I am trying to check Dictionary of type custom class as Value. I would like to know if my approach of searching for value within Dictionary is correct using ContainValue in Fluent Assertion. Here is the code public static void…
Karthik KK
  • 38
  • 5
0
votes
0 answers

FluentAssertions - ShouldAllBeEquivalent and Exluding property - failing unexpectedly

I want to assert that the contents of two lists of dtos are equivalent. However, I want one property on each item to be ignored in the comparison. From reading the collections & dictionaries subsection of the Fluent Assertions documentation, my…
cormacb
  • 11
  • 4