-
-
Notifications
You must be signed in to change notification settings - Fork 539
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
103 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
78 changes: 78 additions & 0 deletions
78
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,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
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 configurationStore = new TestConfigurationStore { Data = { [Configuration.TestFrameworkConfigurationKey] = "xunit2" } }; | ||
var configuration = new Configuration(configurationStore); | ||
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 configurationStore = new TestConfigurationStore { Data = { [Configuration.TestFrameworkConfigurationKey] = "foo" } }; | ||
var configuration = new Configuration(configurationStore); | ||
|
||
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 configurationStore = new TestConfigurationStore { Data = { [Configuration.TestFrameworkConfigurationKey] = "nspec3" } }; | ||
var configuration = new Configuration(configurationStore); | ||
|
||
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 configurationStore = new TestConfigurationStore { Data = { [Configuration.TestFrameworkConfigurationKey] = "nunit" } }; | ||
var configuration = new Configuration(configurationStore); | ||
|
||
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 class TestConfigurationStore : IConfigurationStore | ||
{ | ||
public IDictionary<string, string> Data { get; } = new Dictionary<string, string>(); | ||
|
||
public string GetSetting(string name) | ||
{ | ||
Data.TryGetValue(name, out var setting); | ||
return setting ?? string.Empty; | ||
} | ||
} | ||
} |