using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnitTestSharp; namespace TestsForUnitTestSharp { public class ErrorAsWarningAttributeTests : UnitTestSharp.TestFixture { [IgnoreTest] [ErrorAsWarning] public void Warning() { Check(false); } [IgnoreTest] public void Failing() { Check(false); } [IgnoreTest] [ErrorAsWarning] public void ThrowsException() { throw new Exception("Treat as warning."); } [IgnoreTest] public void ManualSetting() { internals.TreatErrorsAsWarnings = true; Check(false); } public void Without() { int failedChecks = 0; string output = ""; var fixture = new ErrorAsWarningAttributeTests(); bool pass = TestRunner.RunTest(fixture, GetType().GetMethod("Failing"), null, 0, (outputString) => output += outputString, ref failedChecks); CheckFalse(pass); CheckEqual(1, failedChecks); CheckEqualRegex("error", output); } public void With() { int failedChecks = 0; string output = ""; var fixture = new ErrorAsWarningAttributeTests(); bool pass = TestRunner.RunTest(fixture, GetType().GetMethod("Warning"), null, 0, (outputString) => output += outputString, ref failedChecks); Check(pass); CheckEqual(0, failedChecks); CheckNotEqualRegex("error", output); } public void Exception() { int failedChecks = 0; string output = ""; var fixture = new ErrorAsWarningAttributeTests(); bool pass = TestRunner.RunTest(fixture, GetType().GetMethod("ThrowsException"), null, 0, (outputString) => output += outputString, ref failedChecks); Check(pass); CheckEqual(0, failedChecks); CheckNotEqualRegex("error", output); } public void Manual() { int failedChecks = 0; string output = ""; var fixture = new ErrorAsWarningAttributeTests(); bool pass = TestRunner.RunTest(fixture, GetType().GetMethod("ManualSetting"), null, 0, (outputString) => output += outputString, ref failedChecks); Check(pass); CheckEqual(0, failedChecks); CheckNotEqualRegex("error", output); } } }