Skip to content

Commit ae03dc7

Browse files
authored
Switch from NUnit to xUnit (#405)
1 parent b486cda commit ae03dc7

14 files changed

+123
-147
lines changed

Diff for: src/.nuget/packages.config

-4
This file was deleted.

Diff for: src/React.sln

-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CB51F03F
2323
template.nuspec = template.nuspec
2424
EndProjectSection
2525
EndProject
26-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F2875D3A-0C8A-439B-B734-ECABA00AC629}"
27-
ProjectSection(SolutionItems) = preProject
28-
.nuget\packages.config = .nuget\packages.config
29-
EndProjectSection
30-
EndProject
3126
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "React.Sample.Mvc4", "React.Sample.Mvc4\React.Sample.Mvc4.csproj", "{22796879-968A-4C26-9B4B-4C44792B36DB}"
3227
ProjectSection(ProjectDependencies) = postProject
3328
{AF531A37-B93F-4113-9C2C-4DB28064B926} = {AF531A37-B93F-4113-9C2C-4DB28064B926}

Diff for: tests/React.Tests/Core/BabelTransformerTests.cs

+25-26
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99

1010
using System;
1111
using Moq;
12-
using NUnit.Framework;
1312
using React.Exceptions;
13+
using Xunit;
1414

1515
namespace React.Tests.Core
1616
{
17-
[TestFixture]
1817
public class BabelTransformerTests
1918
{
20-
private Mock<IReactEnvironment> _environment;
21-
private Mock<ICache> _cache;
22-
private Mock<IFileSystem> _fileSystem;
23-
private Mock<IFileCacheHash> _fileCacheHash;
24-
private Babel _babel;
25-
26-
[SetUp]
27-
public void SetUp()
19+
private readonly Mock<IReactEnvironment> _environment;
20+
private readonly Mock<ICache> _cache;
21+
private readonly Mock<IFileSystem> _fileSystem;
22+
private readonly Mock<IFileCacheHash> _fileCacheHash;
23+
private readonly Babel _babel;
24+
25+
public BabelTransformerTests()
2826
{
2927
_environment = new Mock<IReactEnvironment>();
3028

@@ -47,7 +45,7 @@ public void SetUp()
4745
);
4846
}
4947

50-
[Test]
48+
[Fact]
5149
public void ShouldTransformJsx()
5250
{
5351
const string input = "<div>Hello World</div>";
@@ -61,7 +59,7 @@ public void ShouldTransformJsx()
6159
));
6260
}
6361

64-
[Test]
62+
[Fact]
6563
public void ShouldWrapExceptionsInJsxExeption()
6664
{
6765
_environment.Setup(x => x.ExecuteWithBabel<string>(
@@ -75,7 +73,7 @@ public void ShouldWrapExceptionsInJsxExeption()
7573
Assert.Throws<BabelException>(() => _babel.Transform(input));
7674
}
7775

78-
[Test]
76+
[Fact]
7977
public void ShouldUseCacheProvider()
8078
{
8179
_cache.Setup(x => x.Get<JavaScriptWithSourceMap>("JSX_v3_foo.jsx", null)).Returns(new JavaScriptWithSourceMap
@@ -84,10 +82,10 @@ public void ShouldUseCacheProvider()
8482
});
8583

8684
var result = _babel.TransformFile("foo.jsx");
87-
Assert.AreEqual("/* cached */", result);
85+
Assert.Equal("/* cached */", result);
8886
}
8987

90-
[Test]
88+
[Fact]
9189
public void ShouldUseFileSystemCacheIfHashValid()
9290
{
9391
SetUpEmptyCache();
@@ -96,10 +94,10 @@ public void ShouldUseFileSystemCacheIfHashValid()
9694
_fileCacheHash.Setup(x => x.ValidateHash(It.IsAny<string>(), It.IsAny<string>())).Returns(true);
9795

9896
var result = _babel.TransformFile("foo.jsx");
99-
Assert.AreEqual("/* filesystem cached */", result);
97+
Assert.Equal("/* filesystem cached */", result);
10098
}
10199

102-
[Test]
100+
[Fact]
103101
public void ShouldTransformJsxIfFileCacheHashInvalid()
104102
{
105103
SetUpEmptyCache();
@@ -115,10 +113,10 @@ public void ShouldTransformJsxIfFileCacheHashInvalid()
115113
)).Returns(new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" });
116114

117115
var result = _babel.TransformFile("foo.jsx");
118-
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
116+
Assert.EndsWith("React.DOM.div('Hello World')", result);
119117
}
120118

121-
[Test]
119+
[Fact]
122120
public void ShouldTransformJsxIfNoCache()
123121
{
124122
SetUpEmptyCache();
@@ -132,10 +130,10 @@ public void ShouldTransformJsxIfNoCache()
132130
)).Returns(new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" });
133131

134132
var result = _babel.TransformFile("foo.jsx");
135-
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
133+
Assert.EndsWith("React.DOM.div('Hello World')", result);
136134
}
137135

138-
[Test]
136+
[Fact]
139137
public void ShouldSaveTransformationResult()
140138
{
141139
_fileSystem.Setup(x => x.ReadAsString("foo.jsx")).Returns("<div>Hello World</div>");
@@ -152,11 +150,11 @@ public void ShouldSaveTransformationResult()
152150
);
153151

154152
var resultFilename = _babel.TransformAndSaveFile("foo.jsx");
155-
Assert.AreEqual("foo.generated.js", resultFilename);
156-
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
153+
Assert.Equal("foo.generated.js", resultFilename);
154+
Assert.EndsWith("React.DOM.div('Hello World')", result);
157155
}
158156

159-
[Test]
157+
[Fact]
160158
public void ShouldSkipTransformationIfCacheIsValid()
161159
{
162160
_fileSystem.Setup(x => x.ReadAsString("foo.jsx")).Returns("<div>Hello World</div>");
@@ -175,8 +173,9 @@ public void ShouldSkipTransformationIfCacheIsValid()
175173
);
176174

177175
var resultFilename = _babel.TransformAndSaveFile("foo.jsx");
178-
Assert.AreEqual("foo.generated.js", resultFilename);
179-
Assert.IsNull(result, "There should be no result. Cached result should have been used.");
176+
Assert.Equal("foo.generated.js", resultFilename);
177+
// There should be no result. Cached result should have been used.
178+
Assert.Null(result);
180179
}
181180

182181
private void SetUpEmptyCache()

Diff for: tests/React.Tests/Core/FileCacheHashTests.cs

+13-14
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,54 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
using NUnit.Framework;
10+
using Xunit;
1111

1212
namespace React.Tests.Core
1313
{
14-
[TestFixture]
1514
public class FileCacheHashTests
1615
{
1716
private const string SAMPLE_HASH = "0A4D55A8D778E5022FAB701977C5D840BBC486D0";
1817

19-
[Test]
18+
[Fact]
2019
public void TestCalculateHash()
2120
{
2221
var hash = new FileCacheHash();
23-
Assert.AreEqual(SAMPLE_HASH, hash.CalculateHash("Hello World"));
22+
Assert.Equal(SAMPLE_HASH, hash.CalculateHash("Hello World"));
2423
}
2524

26-
[Test]
25+
[Fact]
2726
public void ValidateHashShouldReturnFalseForEmptyString()
2827
{
2928
var hash = new FileCacheHash();
30-
Assert.IsFalse(hash.ValidateHash(string.Empty, SAMPLE_HASH));
29+
Assert.False(hash.ValidateHash(string.Empty, SAMPLE_HASH));
3130
}
3231

33-
[Test]
32+
[Fact]
3433
public void ValidateHashShouldReturnFalseForNull()
3534
{
3635
var hash = new FileCacheHash();
37-
Assert.IsFalse(hash.ValidateHash(null, SAMPLE_HASH));
36+
Assert.False(hash.ValidateHash(null, SAMPLE_HASH));
3837
}
3938

40-
[Test]
39+
[Fact]
4140
public void ValidateHashShouldReturnFalseWhenNoHashPrefix()
4241
{
4342
var hash = new FileCacheHash();
44-
Assert.IsFalse(hash.ValidateHash("Hello World", SAMPLE_HASH));
43+
Assert.False(hash.ValidateHash("Hello World", SAMPLE_HASH));
4544
}
4645

47-
[Test]
46+
[Fact]
4847
public void ValidateHashShouldReturnFalseWhenHashDoesNotMatch()
4948
{
5049
var hash = new FileCacheHash();
51-
Assert.IsFalse(hash.ValidateHash("// @hash NOTCORRECT\nHello World", SAMPLE_HASH));
50+
Assert.False(hash.ValidateHash("// @hash NOTCORRECT\nHello World", SAMPLE_HASH));
5251
}
5352

54-
[Test]
53+
[Fact]
5554
public void ValidateHashShouldReturnTrueWhenHashMatches()
5655
{
5756
var hash = new FileCacheHash();
58-
Assert.IsTrue(hash.ValidateHash("// @hash v3-" + SAMPLE_HASH + "\nHello World", SAMPLE_HASH));
57+
Assert.True(hash.ValidateHash("// @hash v3-" + SAMPLE_HASH + "\nHello World", SAMPLE_HASH));
5958
}
6059
}
6160
}

Diff for: tests/React.Tests/Core/FileSystemBaseTests.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
using NUnit.Framework;
10+
using Xunit;
1111

1212
namespace React.Tests.Core
1313
{
14-
[TestFixture]
1514
public class FileSystemBaseTests
1615
{
17-
[TestCase("~/Test.txt", "C:\\Test.txt")]
18-
[TestCase("~/Scripts/lol.js", "C:\\Scripts\\lol.js")]
16+
[Theory]
17+
[InlineData("~/Test.txt", "C:\\Test.txt")]
18+
[InlineData("~/Scripts/lol.js", "C:\\Scripts\\lol.js")]
1919
public void ToRelativePath(string expected, string input)
2020
{
2121
var fileSystem = new TestFileSystem();
22-
Assert.AreEqual(expected, fileSystem.ToRelativePath(input));
22+
Assert.Equal(expected, fileSystem.ToRelativePath(input));
2323
}
2424

2525
private class TestFileSystem : FileSystemBase

Diff for: tests/React.Tests/Core/FileSystemExtensionsTest.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
using NUnit.Framework;
10+
using Xunit;
1111

1212
namespace React.Tests.Core
1313
{
14-
[TestFixture]
1514
public class FileSystemExtensionsTests
1615
{
17-
[TestCase("*.txt", true)]
18-
[TestCase("foo?.js", true)]
19-
[TestCase("first\\second\\third\\*.js", true)]
20-
[TestCase("lol.js", false)]
21-
[TestCase("", false)]
22-
[TestCase("hello\\world.js", false)]
16+
[Theory]
17+
[InlineData("*.txt", true)]
18+
[InlineData("foo?.js", true)]
19+
[InlineData("first\\second\\third\\*.js", true)]
20+
[InlineData("lol.js", false)]
21+
[InlineData("", false)]
22+
[InlineData("hello\\world.js", false)]
2323
public void IsGlobPattern(string input, bool expected)
2424
{
25-
Assert.AreEqual(expected, input.IsGlobPattern());
25+
Assert.Equal(expected, input.IsGlobPattern());
2626
}
2727
}
2828
}

Diff for: tests/React.Tests/Core/GuidExtensionsTests.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
*/
99

1010
using System;
11-
using NUnit.Framework;
11+
using Xunit;
1212

1313
namespace React.Tests.Core
1414
{
15-
[TestFixture]
1615
public class GuidExtensionsTests
1716
{
18-
[TestCase]
17+
[Fact]
1918
public void ToShortGuid()
2019
{
2120
var guid = Guid.Parse("c027191d-3785-485d-9fd7-5e0b376bd547");
22-
Assert.AreEqual("HRknwIU3XUif114LN2vVRw", guid.ToShortGuid());
21+
Assert.Equal("HRknwIU3XUif114LN2vVRw", guid.ToShortGuid());
2322
}
2423
}
2524
}

0 commit comments

Comments
 (0)