fluentassertions / fluentassertions/fluentassertions.analyzers

No FAA0001 when `?.` is followed by `Should().BeApproximately`

Aperta
#405 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
C#
Stelle
131
Fork
25
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Suppose for the sake of this bug report that we have the following type:

public interface IExample {
    double Amount { get; }
}

Then if we write the following incorrect test:

public void TestMethod() {
    IExample? actual = null;

    actual?.Amount.Should().BeApproximately(3.14, 0.01);   // no FAA0001 here?!
}

then we get no message from FluentAssertions.Analyzers about the wrong code.

For other assertions, this works fine. For example:

    actual?.Amount.Should().BeGreaterThan(3.1);  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

or:

    actual?.Amount.Should().BePositive();  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

or:

    actual?.Amount.Should().BeInRange(3.1, 3.2);  // good, we get 'FAA0001: Use .Should() instead of ?.Should()'

We need the FAA0001 with .BeApproximately(3.14, 0.01) as well. Without it, the author may think his tests proves actual is an instance where Amount equals 3.14 within a tolerance of 0.01 when in fact actual is a null reference (and no Amount exists).

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

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.

Direzione di ricerca

Inizia riproducendo il problema con l'esempio C# usando actual?.Amount.Should().BeApproximately(3.14, 0.01), quindi confronta la gestione di FAA0001 per BeApproximately con BeGreaterThan, BePositive e BeInRange. Il lavoro è completato quando l'analizzatore segnala FAA0001 per il caso BeApproximately, mantenendo il comportamento esistente per le altre assertions.

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

Valutazione

Stack tecnologico
csharp
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
68/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.