Skip to content

Instantly share code, notes, and snippets.

@markryd
Last active July 12, 2019 13:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markryd/ff0a361d4de6a4a74aef3fd545a28d16 to your computer and use it in GitHub Desktop.
Save markryd/ff0a361d4de6a4a74aef3fd545a28d16 to your computer and use it in GitHub Desktop.
Do a rough conversion from nunit to xunit + fluentassertions
$testFolder = "C:\dev\Calamari\source\Calamari.Tests"
Function Convert-ToXunit {
Param(
[System.IO.FileInfo]$file
)
$result = (Get-Content $file.FullName -Raw) `
-replace 'using NUnit.Framework;', 'using Xunit;' `
-replace '\[Test\]', '[Fact]' `
-replace '\[TestFixture\]', '' `
-replace '\[TestCase', '[InlineData' `
-replace '\[Category\(', '[Trait("Category",' `
-replace 'Assert.AreEqual\((.*), (.*)\)', '$2.Should().Be($1)' `
-replace 'Assert.AreNotEqual\((.*), (.*)\)', '$2.Should().NotBe($1)' `
-replace 'Assert.That\((.*), Is.EqualTo\((.*)\)\)', '$1.Should().Be($2)' `
-replace 'Assert.That\((.*), Is.Null\)', '$1.Should().BeNull()' `
-replace 'Assert.That\((.*), Is.Not.Null\)', '$1.Should().NotBeNull()' `
-replace 'Assert.That\((.*), Is.Not.Empty\)', '$1.Should().NotBeEmpty()' `
-replace 'Assert.That\((.*), Is.True\)', '$1.Should().BeTrue()' `
-replace 'Assert.That\((.*), Is.False\)', '$1.Should().BeFalse()' `
-replace 'Assert.IsNull\((.*)\)', '$1.Should().BeNull()' `
-replace 'Assert.IsNotNull\((.*)\)', '$1.Should().NotBeNull()' `
-replace 'Assert.IsTrue\((.*)\)', '$1.Should().BeTrue()' `
-replace 'Assert.IsFalse\((.*)\)', '$1.Should().BeFalse()' `
-replace 'Assert.That\((.*), Does.Contain\((.*)\)\)', '$1.Should().Contain($2)' `
-replace 'Assert.That\((.*), Does.Not.Contain\((.*)\)\)', '$1.Should().NotContain($2)' `
-replace 'Assert.That\((.*), Does.Match\((.*)\)\)', '$1.Should().MatchRegex($2)' `
-replace 'Assert.That\((.*), Does.Not.Match\((.*)\)\)', '$1.Should().NotMatchRegex($2)' `
-replace 'Assert.That\((.*), Is.LessThan\((.*)\)\)', '$1.Should().BeLessThan($2)' `
-replace 'Assert.That\((.*), Is.GreaterThan\((.*)\)\)', '$1.Should().BeGreaterThan($2)'
[System.IO.File]::WriteAllLines($file.FullName, $result)
}
Get-ChildItem $testFolder -Recurse -Include *.cs -File | % { Convert-ToXunit -file $_ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment