question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add collection constraints from NUnit

See original GitHub issue

Description

I just wrote some tests and wanted to test a collection that has the equivalent item than another.

Could you please implement the collection constraints from NUnit?

Repro steps

I have to use NUnit’s function with like: let areCollectionsEqual = CollectionAssert.AreEquivalent([1;2;3], [3;1;2])

It’s not so “F#-ish”.

Known workarounds

I “extended” FsUnit with an extra function:

module FsUnit = 
  open NUnit.Framework.Constraints

  let equalsToCollection x = CollectionEquivalentConstraint x

So I can use this function like:

let areCollectionsEqual () = [1;2;3] |> should equalsToCollection [3;1;2]

Collection contraints implemented:

  • equivalent
  • supersetOf
  • subsetOf

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:18 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
CaptnCodrcommented, Oct 30, 2019

I would like to implement the subsetOf operator, too. To have the counterpart of supersetOf.

Like: [4;5] |> should be (subsetOf [1..10])

Is this okay?

2reactions
sergey-tihoncommented, Oct 15, 2019

I guess CollectionAssert.AreEqual case should be covered by equal operator due to structured equality

[1;2;3] |> should equal [1;2;3]

(we may add such test-cases and check)

for NUnit and MSTest is make sense to wrap CollectionAssert.AreEquivalent into equivalent operator. I am not sure about xUnit, we can leave it not implemented because it is not idiomatic for framework or reimplement logic from NUnit on our side

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Constraints
You can implement your own custom constraints by creating a class that inherits from the Constraint abstract class, which supports performing a test...
Read more >
Collection Constraints (NUnit 2.4 / 2.5)
Collection constraints perform tests that are specific to collections. The following collection constraints are provided. Before NUnit 2.4.6, ...
Read more >
NUnit.Framework.Constraints Namespace
Explore all classes and interfaces of the NUnit. ... Represents a constraint that succeeds if all the members of a collection match a...
Read more >
Today I Learned How to Create Custom NUnit Constraints
The first step in creating a NUnit custom constraint is to read the documentation. ... Add whatever logic you need to to the...
Read more >
Creating a NUnit constraint meaning "{collection} does not ...
If you are using NUnit 2.4 / 2.5 you may checkout the collection constraints. Share.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found