Skip to content

Commit

Permalink
Switch from NUnit to xUnit (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 authored May 8, 2017
1 parent 1206a7d commit 26d2129
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 147 deletions.
4 changes: 0 additions & 4 deletions src/.nuget/packages.config

This file was deleted.

5 changes: 0 additions & 5 deletions src/React.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CB51F03F
template.nuspec = template.nuspec
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F2875D3A-0C8A-439B-B734-ECABA00AC629}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "React.Sample.Mvc4", "React.Sample.Mvc4\React.Sample.Mvc4.csproj", "{22796879-968A-4C26-9B4B-4C44792B36DB}"
ProjectSection(ProjectDependencies) = postProject
{AF531A37-B93F-4113-9C2C-4DB28064B926} = {AF531A37-B93F-4113-9C2C-4DB28064B926}
Expand Down
51 changes: 25 additions & 26 deletions tests/React.Tests/Core/BabelTransformerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@

using System;
using Moq;
using NUnit.Framework;
using React.Exceptions;
using Xunit;

namespace React.Tests.Core
{
[TestFixture]
public class BabelTransformerTests
{
private Mock<IReactEnvironment> _environment;
private Mock<ICache> _cache;
private Mock<IFileSystem> _fileSystem;
private Mock<IFileCacheHash> _fileCacheHash;
private Babel _babel;

[SetUp]
public void SetUp()
private readonly Mock<IReactEnvironment> _environment;
private readonly Mock<ICache> _cache;
private readonly Mock<IFileSystem> _fileSystem;
private readonly Mock<IFileCacheHash> _fileCacheHash;
private readonly Babel _babel;

public BabelTransformerTests()
{
_environment = new Mock<IReactEnvironment>();

Expand All @@ -47,7 +45,7 @@ public void SetUp()
);
}

[Test]
[Fact]
public void ShouldTransformJsx()
{
const string input = "<div>Hello World</div>";
Expand All @@ -61,7 +59,7 @@ public void ShouldTransformJsx()
));
}

[Test]
[Fact]
public void ShouldWrapExceptionsInJsxExeption()
{
_environment.Setup(x => x.ExecuteWithBabel<string>(
Expand All @@ -75,7 +73,7 @@ public void ShouldWrapExceptionsInJsxExeption()
Assert.Throws<BabelException>(() => _babel.Transform(input));
}

[Test]
[Fact]
public void ShouldUseCacheProvider()
{
_cache.Setup(x => x.Get<JavaScriptWithSourceMap>("JSX_v3_foo.jsx", null)).Returns(new JavaScriptWithSourceMap
Expand All @@ -84,10 +82,10 @@ public void ShouldUseCacheProvider()
});

var result = _babel.TransformFile("foo.jsx");
Assert.AreEqual("/* cached */", result);
Assert.Equal("/* cached */", result);
}

[Test]
[Fact]
public void ShouldUseFileSystemCacheIfHashValid()
{
SetUpEmptyCache();
Expand All @@ -96,10 +94,10 @@ public void ShouldUseFileSystemCacheIfHashValid()
_fileCacheHash.Setup(x => x.ValidateHash(It.IsAny<string>(), It.IsAny<string>())).Returns(true);

var result = _babel.TransformFile("foo.jsx");
Assert.AreEqual("/* filesystem cached */", result);
Assert.Equal("/* filesystem cached */", result);
}

[Test]
[Fact]
public void ShouldTransformJsxIfFileCacheHashInvalid()
{
SetUpEmptyCache();
Expand All @@ -115,10 +113,10 @@ public void ShouldTransformJsxIfFileCacheHashInvalid()
)).Returns(new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" });

var result = _babel.TransformFile("foo.jsx");
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
Assert.EndsWith("React.DOM.div('Hello World')", result);
}

[Test]
[Fact]
public void ShouldTransformJsxIfNoCache()
{
SetUpEmptyCache();
Expand All @@ -132,10 +130,10 @@ public void ShouldTransformJsxIfNoCache()
)).Returns(new JavaScriptWithSourceMap { Code = "React.DOM.div('Hello World')" });

var result = _babel.TransformFile("foo.jsx");
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
Assert.EndsWith("React.DOM.div('Hello World')", result);
}

[Test]
[Fact]
public void ShouldSaveTransformationResult()
{
_fileSystem.Setup(x => x.ReadAsString("foo.jsx")).Returns("<div>Hello World</div>");
Expand All @@ -152,11 +150,11 @@ public void ShouldSaveTransformationResult()
);

var resultFilename = _babel.TransformAndSaveFile("foo.jsx");
Assert.AreEqual("foo.generated.js", resultFilename);
StringAssert.EndsWith("React.DOM.div('Hello World')", result);
Assert.Equal("foo.generated.js", resultFilename);
Assert.EndsWith("React.DOM.div('Hello World')", result);
}

[Test]
[Fact]
public void ShouldSkipTransformationIfCacheIsValid()
{
_fileSystem.Setup(x => x.ReadAsString("foo.jsx")).Returns("<div>Hello World</div>");
Expand All @@ -175,8 +173,9 @@ public void ShouldSkipTransformationIfCacheIsValid()
);

var resultFilename = _babel.TransformAndSaveFile("foo.jsx");
Assert.AreEqual("foo.generated.js", resultFilename);
Assert.IsNull(result, "There should be no result. Cached result should have been used.");
Assert.Equal("foo.generated.js", resultFilename);
// There should be no result. Cached result should have been used.
Assert.Null(result);
}

private void SetUpEmptyCache()
Expand Down
27 changes: 13 additions & 14 deletions tests/React.Tests/Core/FileCacheHashTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,54 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

using NUnit.Framework;
using Xunit;

namespace React.Tests.Core
{
[TestFixture]
public class FileCacheHashTests
{
private const string SAMPLE_HASH = "0A4D55A8D778E5022FAB701977C5D840BBC486D0";

[Test]
[Fact]
public void TestCalculateHash()
{
var hash = new FileCacheHash();
Assert.AreEqual(SAMPLE_HASH, hash.CalculateHash("Hello World"));
Assert.Equal(SAMPLE_HASH, hash.CalculateHash("Hello World"));
}

[Test]
[Fact]
public void ValidateHashShouldReturnFalseForEmptyString()
{
var hash = new FileCacheHash();
Assert.IsFalse(hash.ValidateHash(string.Empty, SAMPLE_HASH));
Assert.False(hash.ValidateHash(string.Empty, SAMPLE_HASH));
}

[Test]
[Fact]
public void ValidateHashShouldReturnFalseForNull()
{
var hash = new FileCacheHash();
Assert.IsFalse(hash.ValidateHash(null, SAMPLE_HASH));
Assert.False(hash.ValidateHash(null, SAMPLE_HASH));
}

[Test]
[Fact]
public void ValidateHashShouldReturnFalseWhenNoHashPrefix()
{
var hash = new FileCacheHash();
Assert.IsFalse(hash.ValidateHash("Hello World", SAMPLE_HASH));
Assert.False(hash.ValidateHash("Hello World", SAMPLE_HASH));
}

[Test]
[Fact]
public void ValidateHashShouldReturnFalseWhenHashDoesNotMatch()
{
var hash = new FileCacheHash();
Assert.IsFalse(hash.ValidateHash("// @hash NOTCORRECT\nHello World", SAMPLE_HASH));
Assert.False(hash.ValidateHash("// @hash NOTCORRECT\nHello World", SAMPLE_HASH));
}

[Test]
[Fact]
public void ValidateHashShouldReturnTrueWhenHashMatches()
{
var hash = new FileCacheHash();
Assert.IsTrue(hash.ValidateHash("// @hash v3-" + SAMPLE_HASH + "\nHello World", SAMPLE_HASH));
Assert.True(hash.ValidateHash("// @hash v3-" + SAMPLE_HASH + "\nHello World", SAMPLE_HASH));
}
}
}
10 changes: 5 additions & 5 deletions tests/React.Tests/Core/FileSystemBaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

using NUnit.Framework;
using Xunit;

namespace React.Tests.Core
{
[TestFixture]
public class FileSystemBaseTests
{
[TestCase("~/Test.txt", "C:\\Test.txt")]
[TestCase("~/Scripts/lol.js", "C:\\Scripts\\lol.js")]
[Theory]
[InlineData("~/Test.txt", "C:\\Test.txt")]
[InlineData("~/Scripts/lol.js", "C:\\Scripts\\lol.js")]
public void ToRelativePath(string expected, string input)
{
var fileSystem = new TestFileSystem();
Assert.AreEqual(expected, fileSystem.ToRelativePath(input));
Assert.Equal(expected, fileSystem.ToRelativePath(input));
}

private class TestFileSystem : FileSystemBase
Expand Down
18 changes: 9 additions & 9 deletions tests/React.Tests/Core/FileSystemExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

using NUnit.Framework;
using Xunit;

namespace React.Tests.Core
{
[TestFixture]
public class FileSystemExtensionsTests
{
[TestCase("*.txt", true)]
[TestCase("foo?.js", true)]
[TestCase("first\\second\\third\\*.js", true)]
[TestCase("lol.js", false)]
[TestCase("", false)]
[TestCase("hello\\world.js", false)]
[Theory]
[InlineData("*.txt", true)]
[InlineData("foo?.js", true)]
[InlineData("first\\second\\third\\*.js", true)]
[InlineData("lol.js", false)]
[InlineData("", false)]
[InlineData("hello\\world.js", false)]
public void IsGlobPattern(string input, bool expected)
{
Assert.AreEqual(expected, input.IsGlobPattern());
Assert.Equal(expected, input.IsGlobPattern());
}
}
}
7 changes: 3 additions & 4 deletions tests/React.Tests/Core/GuidExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
*/

using System;
using NUnit.Framework;
using Xunit;

namespace React.Tests.Core
{
[TestFixture]
public class GuidExtensionsTests
{
[TestCase]
[Fact]
public void ToShortGuid()
{
var guid = Guid.Parse("c027191d-3785-485d-9fd7-5e0b376bd547");
Assert.AreEqual("HRknwIU3XUif114LN2vVRw", guid.ToShortGuid());
Assert.Equal("HRknwIU3XUif114LN2vVRw", guid.ToShortGuid());
}
}
}
Loading

0 comments on commit 26d2129

Please sign in to comment.