What is the "update path" from Assertion.AssertEquals?

I have inherited some unit test code that gives me an obsolescence warning because it uses "Assertion.AssertEquals":

warning CS0618: "NUnit.Framework.Assertion" is deprecated: "Use the Assert class instead"

However, I don't see the obvious method in the Assert class that I should use instead?

AssertEquals accepts two objects and a message that can be used to report an error if there is a failure. eg.

        Assertion.AssertEquals(
             "Enqueuing first item should set count to 1",
             1, pq.Count);

What is the equivalent method in the Assert class?

+3
source share
4 answers

Jon Skeet "" , , . , .

, :

""

Assert.AreEqual(1, pq.Count,
    "Enqueuing first item should set count to 1");

" "

Assert.That(
    pq.Count,
    Is.EqualTo(1),
    "Enqueuing first item should set count to 1");

, .

+8

:

Assert.AreEqual(1, pq.Count,
                "Enqueuing first item should set count to 1");
+5
Assert.That(a, Is.EqualTo(b),
    "Enqueuing first item should set count to 1");
+4
source

Replace the full regex:

Assertion\.AssertEquals(\(.*\),\(.*\),\(.*\))

should be replaced by:

Assert.That(\2, \1, \0)

AND Assertion.Assert(\(.*\),\(.*\))

should be replaced by:

Assert.That(\2, \1)
0
source

Source: https://habr.com/ru/post/1717826/


All Articles