Introduce Assert.All(IEnumerable<T> collection, Predicate<T> match) and Assert.None(IEnumerable<T> collection, Predicate<T> match)

Aperta
#12,260 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
56/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
testing

Direzione di ricerca

Read the existing MSTest Assert collection assertion APIs and their tests to find where predicate-based assertions belong. The issue gives examples for IEnumerable<T>, but does not specify overload details or expected failure message format. Done means Assert.All and Assert.None evaluate predicates and report useful details about the items that cause failure.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/analyzers area/assertion

It would also be nice to have a way to verify whether all or none of the items in an IEnumerable<T> (or IEnumerable, ...) match a given predicate.

The MSTest failure message could provide information on how many items did (not) match and even provide details on the first item (non) matching item. It could surely do this if there's only one item that did (not) match.

For example:

string[] fragments = [ "AB", "A", "BC" ];

Assert.All(fragments, f => f.Length < 3); // success
Assert.All(fragments, f => f.Length == 2); // fails as "A" does not match the predicate
Assert.None(fragments, f => f.Length > 2); // success
Assert.None(fragments, f => f.Length == 1); // fails as "A" matches the predicate

One can of course use plain LINQ, but you'll only get "true" or "false" failure messages that do not help you to pinpoint the item(s) that caused the condition to fail.

For example:

string[] fragments = [ "AB", "A", "BC" ];

Assert.IsTrue(fragments.All(f => f.Length < 3)); // success
Assert.IsTrue(fragments.All(f => f.Length == 2)); // fails as "A" does not match the predicate
Assert.IsTrue(!fragments.Any(f => f.Length > 2)); // success
Assert.IsTrue(!fragments.Any(f => f.Length == 1)); // fails as "A" matches the predicate

Perhaps such predicate support would also be useful for existing Assert methods, but that may not be necessary. I guess that - for example - Assert.IsNotEmpty(...) or Assert.IsEmpty(...) could just be modified to provide details on the (first) item that caused the assert to fail.

Sorry if such functionality already exist!

Lingua principale
C#
Stelle
1.1k
Fork
314
Merge medio
11h 9m
PR unite (30g)
340

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/testfx

Tutte le issue di microsoft/testfx

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.