Assert.That on a null non-generic IEnumerable throws ArgumentNullException, so IsNull() cannot pass

オープン 初心者向け
#7,698 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
testing

調査の方向性

非ジェネリック IEnumerable 用の Assert.That オーバーロードから始め、その null の処理をジェネリックな IEnumerable<T> 用および object 用のオーバーロードと比較してください。関連する IsNull() や他のアサーションの経路を確認し、null 値と null でない値のテストを追加してください。IsNull() が null の IEnumerable に対して成功し、他のアサーションが ArgumentNullException ではなくアサーション失敗を報告すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug P2

Assert.That(x).IsNull() throws ArgumentNullException when x is a null non-generic IEnumerable, so the assertion can never pass. With TUnit 1.79.0:

IEnumerable? renderings = null;
await Assert.That(renderings).IsNull();   // ArgumentNullException: Value cannot be null. (Parameter 'source')

The generic and object overloads accept the same null value:

IEnumerable<int>? items = null;
await Assert.That(items).IsNull();        // passes

object? value = null;
await Assert.That(value).IsNull();        // passes

The overload taking a non-generic IEnumerable also declares its parameter non-nullable, so the compiler warns (CS8604) at the call above. Casting the value to object? makes the assertion pass.

Expected: IsNull() passes for a null non-generic IEnumerable, as it does for IEnumerable<T>. Other assertions on a null value should fail with an assertion failure rather than ArgumentNullException.

Found while migrating an xUnit suite, where Assert.Null(renderings) on a non-generic IEnumerable passed.

主要言語
C#
スター
4k
フォーク
139
平均マージ
7時間 16分
マージ済み PR(30日)
355

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

thomhurst/TUnit のほかの issue

thomhurst/TUnit の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。