-
Notifications
You must be signed in to change notification settings - Fork 158
NUnit2008
Topic | Value |
---|---|
Id | NUnit2008 |
Severity | Warning |
Enabled | True |
Category | Assertion |
Code | IgnoreCaseUsageAnalyzer |
IgnoreCase modifier should only be used for string or char arguments. Using it on another type will not have any effect.
To bring developers' attention to a scenario in which their code is actually having no effect and may reveal that their test is not doing what they expect.
[Test]
public void Nunit2008SampleTest()
{
var date = DateTime.Now;
Assert.That(date, Is.Not.EqualTo(date.AddDays(1)).IgnoreCase);
}
Using IgnoreCase here doesn't make any sense, because the types we're comparing don't have the concept of case. Therefore, it's only suitable to use on textual primitives (e.g. string
and char
).
Remove the errant call to IgnoreCase
:
[Test]
public void Nunit2008SampleTest()
{
var date = DateTime.Now;
Assert.That(date, Is.Not.EqualTo(date.AddDays(1)));
}
Or update the code to compare based on the primitives that are supported by IgnoreCase
:
[Test]
public void Nunit2008SampleTest()
{
var date = DateTime.Now;
Assert.That(date.ToString(), Is.Not.EqualTo(date.AddDays(1).ToString()).IgnoreCase);
}
Configure the severity per project, for more info see MSDN.
#pragma warning disable NUnit2008 // Incorrect IgnoreCase usage.
Code violating the rule here
#pragma warning restore NUnit2008 // Incorrect IgnoreCase usage.
Or put this at the top of the file to disable all instances.
#pragma warning disable NUnit2008 // Incorrect IgnoreCase usage.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Assertion",
"NUnit2008:Incorrect IgnoreCase usage.",
Justification = "Reason...")]
Copyright (c) 2018 The NUnit Project - Licensed under CC BY-NC-SA 4.0