Improve description for rule S3431 (CSharp)

The solution suggestion of rule S3431 should be improved and consider the MSTest V2 Assert.ThrowsException features.

Severity Code Description Project File Line Suppression State
Warning S3431 Replace the ‘ExpectedException’ attribute with a try/catch block. PluginExport_uTest D:\sometest\TokenClientTest.cs 162 Active

The current suggestion was correct for MSTest V1 and should not be used anymore. Unit tests should not use try…catch in this context.

e.g. Compliant Solution

public void ErrorIfReadingBeforeInitialized_CaptureExDemo()
    var sut = new TemperatureSensor();
    var ex = Assert.ThrowsException<InvalidOperationException>(() => sut.ReadCurrentTemperature());
    Assert.AreEqual("Cannot read temperature before initializing.", ex.Message);

Hi @Bertk

Thank you very much for reaching out to us.
Based on your valuable suggestion I created a pull request and updated both the message and the compliant example of rule S3431.