Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for better coverage in Execution namespace (#2042)
- Loading branch information
Showing
7 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Tests/FluentAssertions.Specs/Execution/FallbackTestFrameworkTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using FluentAssertions.Execution; | ||
using Xunit; | ||
|
||
namespace FluentAssertions.Specs.Execution; | ||
|
||
public class FallbackTestFrameworkTests | ||
{ | ||
[Fact] | ||
public void The_fallback_test_framework_is_available() | ||
{ | ||
var sut = new FallbackTestFramework(); | ||
|
||
sut.IsAvailable.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void Throwing_with_messages_throws_the_exception() | ||
{ | ||
var sut = new FallbackTestFramework(); | ||
|
||
sut.Invoking(x => x.Throw("test message")).Should().ThrowExactly<AssertionFailedException>() | ||
.WithMessage("test message"); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
Tests/FluentAssertions.Specs/Execution/TestFrameworkProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System; | ||
using FluentAssertions.Common; | ||
using FluentAssertions.Execution; | ||
using Xunit; | ||
using Xunit.Sdk; | ||
|
||
namespace FluentAssertions.Specs.Execution; | ||
|
||
public class TestFrameworkProviderTests | ||
{ | ||
[Fact] | ||
public void When_running_xunit_test_implicitly_it_should_be_detected() | ||
{ | ||
// Arrange | ||
var configuration = new Configuration(new TestConfigurationStore()); | ||
var testFrameworkProvider = new TestFrameworkProvider(configuration); | ||
|
||
// Act | ||
Action act = () => testFrameworkProvider.Throw("MyMessage"); | ||
|
||
// Assert | ||
act.Should().Throw<XunitException>(); | ||
} | ||
|
||
[Fact] | ||
public void When_running_xunit_test_explicitly_it_should_be_detected() | ||
{ | ||
// Arrange | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "xunit2" | ||
}; | ||
var testFrameworkProvider = new TestFrameworkProvider(configuration); | ||
|
||
// Act | ||
Action act = () => testFrameworkProvider.Throw("MyMessage"); | ||
|
||
// Assert | ||
act.Should().Throw<XunitException>(); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_unknown_test_framework_it_should_throw() | ||
{ | ||
// Arrange | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "foo" | ||
}; | ||
var testFrameworkProvider = new TestFrameworkProvider(configuration); | ||
|
||
// Act | ||
Action act = () => testFrameworkProvider.Throw("MyMessage"); | ||
|
||
// Assert | ||
act.Should().Throw<InvalidOperationException>() | ||
.WithMessage("*the test framework 'foo' but this is not supported*"); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_direct_bound_but_unavailable_test_framework_it_should_throw() | ||
{ | ||
// Arrange | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "nspec3" | ||
}; | ||
var testFrameworkProvider = new TestFrameworkProvider(configuration); | ||
|
||
// Act | ||
Action act = () => testFrameworkProvider.Throw("MyMessage"); | ||
|
||
// Assert | ||
act.Should().Throw<InvalidOperationException>() | ||
.WithMessage("*test framework 'nspec3' but it could not be found*"); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_late_bound_but_unavailable_test_framework_it_should_throw() | ||
{ | ||
// Arrange | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "nunit" | ||
}; | ||
var testFrameworkProvider = new TestFrameworkProvider(configuration); | ||
|
||
// Act | ||
Action act = () => testFrameworkProvider.Throw("MyMessage"); | ||
|
||
act.Should().Throw<InvalidOperationException>() | ||
.WithMessage("*test framework 'nunit' but the required assembly 'nunit.framework' could not be found*"); | ||
} | ||
|
||
private sealed class TestConfigurationStore : IConfigurationStore | ||
{ | ||
string IConfigurationStore.GetSetting(string name) => string.Empty; | ||
} | ||
} |