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 TestFrameworkProvider
- Loading branch information
Showing
3 changed files
with
104 additions
and
16 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
79 changes: 79 additions & 0 deletions
79
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,79 @@ | ||
using System; | ||
using FluentAssertions.Common; | ||
using FluentAssertions.Execution; | ||
using Xunit; | ||
|
||
namespace FluentAssertions.Specs.Execution; | ||
|
||
public class TestFrameworkProviderTests | ||
{ | ||
[Fact] | ||
public void When_running_xunit_test_implicitly_it_should_be_detected() | ||
{ | ||
var configuration = new Configuration(new TestConfigurationStore()); | ||
var result = TestFrameworkProvider.DetectFramework(configuration); | ||
|
||
result.IsAvailable.Should().BeTrue(); | ||
result.Should().BeOfType<XUnit2TestFramework>(); | ||
} | ||
|
||
[Fact] | ||
public void When_running_xunit_test_explicitly_it_should_be_detected() | ||
{ | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "xunit2" | ||
}; | ||
var result = TestFrameworkProvider.DetectFramework(configuration); | ||
|
||
result.IsAvailable.Should().BeTrue(); | ||
result.Should().BeOfType<XUnit2TestFramework>(); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_unknown_test_framework_it_should_throw() | ||
{ | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "foo" | ||
}; | ||
|
||
this.Invoking(_ => TestFrameworkProvider.AttemptToDetectUsingAppSetting(configuration)) | ||
.Should().Throw<InvalidOperationException>() | ||
.WithMessage("FluentAssertions was configured to use the test framework 'foo' but this is not supported." | ||
+ " Please use one of the supported frameworks: mspec, nspec3, nunit, mstestv2, xunit2."); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_direct_bound_but_unavailable_test_framework_it_should_throw() | ||
{ | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "nspec3" | ||
}; | ||
|
||
this.Invoking(_ => TestFrameworkProvider.AttemptToDetectUsingAppSetting(configuration)) | ||
.Should().Throw<InvalidOperationException>() | ||
.WithMessage("FluentAssertions was configured to use the test framework 'nspec3' but it could not be found." | ||
+ " Please use one of the supported frameworks: mspec, nspec3, nunit, mstestv2, xunit2."); | ||
} | ||
|
||
[Fact] | ||
public void When_running_test_with_late_bound_but_unavailable_test_framework_it_should_throw() | ||
{ | ||
var configuration = new Configuration(new TestConfigurationStore()) | ||
{ | ||
TestFrameworkName = "nunit" | ||
}; | ||
|
||
this.Invoking(_ => TestFrameworkProvider.AttemptToDetectUsingAppSetting(configuration)) | ||
.Should().Throw<InvalidOperationException>() | ||
.WithMessage("FluentAssertions was configured to use the test framework 'nunit' but the required assembly 'nunit.framework' could not be found." | ||
+ " Please use one of the supported frameworks: mspec, nspec3, nunit, mstestv2, xunit2."); | ||
} | ||
|
||
private sealed class TestConfigurationStore : IConfigurationStore | ||
{ | ||
string IConfigurationStore.GetSetting(string name) => string.Empty; | ||
} | ||
} |