Summary
The NUnit to TUnit migration code fixer should handle the ExpectedResult property in NUnit test attributes and convert it to TUnit's assertion style.
NUnit Pattern
[TestCase(2, 3, ExpectedResult = 5)]
public int Add(int a, int b)
{
return a + b;
}
[TestCase("hello", ExpectedResult = 5)]
public int GetLength(string input)
{
return input.Length;
}
Expected TUnit Output
[Test]
[Arguments(2, 3)]
public async Task Add(int a, int b)
{
await Assert.That(a + b).IsEqualTo(5);
}
[Test]
[Arguments("hello")]
public async Task GetLength(string input)
{
await Assert.That(input.Length).IsEqualTo(5);
}
Implementation Notes
- Detect
ExpectedResult = <value> in NUnit attributes ([TestCase], [TestCaseSource], etc.)
- Remove
ExpectedResult from the migrated [Arguments] attribute
- Change method return type from
T to async Task
- Wrap the return expression with
await Assert.That(<expr>).IsEqualTo(<expected>)
- Handle various return types (int, string, bool, objects, etc.)
Edge Cases to Consider
- Methods with multiple return statements
- Methods with complex return expressions
- Generic return types
- Nullable return types
ExpectedResult = null
Summary
The NUnit to TUnit migration code fixer should handle the
ExpectedResultproperty in NUnit test attributes and convert it to TUnit's assertion style.NUnit Pattern
Expected TUnit Output
Implementation Notes
ExpectedResult = <value>in NUnit attributes ([TestCase],[TestCaseSource], etc.)ExpectedResultfrom the migrated[Arguments]attributeTtoasync Taskawait Assert.That(<expr>).IsEqualTo(<expected>)Edge Cases to Consider
ExpectedResult = null