-
Notifications
You must be signed in to change notification settings - Fork 2
TUnit Support #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b1845cc
TUnit Support
thomhurst f471a2b
format
thomhurst 8f3061a
Style fixes
thomhurst 99fc3f8
Format
thomhurst 51542fa
Format
thomhurst 5639805
File scoped namespace
thomhurst 7555521
Style fixes
thomhurst 3303d9f
Tidy
thomhurst de35fc7
Fixes
thomhurst 2d66ed8
Moved internal extensions to internal namespace
aivascu bb94182
Renamed code style configuration files
aivascu a16ceb1
Rolled back changes to editorconfig
aivascu f7c830c
Added code style configuration files to solution items
aivascu 8fde0e8
Applied code style fixes
aivascu ee61f05
Fixed documentation comment
aivascu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
root = true | ||
|
||
[*.{cs,fs,fsx}] | ||
indent_size = 4 | ||
indent_style = space | ||
|
||
[*.{sln,csproj,fsproj,config,xml,props}] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.cs] | ||
indent_size = 4 | ||
indent_style = space | ||
|
||
# Require "this." keyword qualification in code | ||
dotnet_style_qualification_for_field = true:suggestion | ||
dotnet_style_qualification_for_property = true:suggestion | ||
dotnet_style_qualification_for_method = true:suggestion | ||
dotnet_style_qualification_for_event = true:suggestion | ||
|
||
dotnet_diagnostic.CA1510.severity = suggestion | ||
dotnet_diagnostic.CA1859.severity = suggestion |
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,15 +1,16 @@ | ||
using System.Text.RegularExpressions; | ||
using Nuke.Common.CI.GitHubActions; | ||
|
||
namespace Nuke.Common.CI.GitHubActions | ||
public static partial class GitHubActionsExtensions | ||
{ | ||
public static class GitHubActionsExtensions | ||
{ | ||
private static readonly Regex SemVerRef = new(@"^refs\/tags\/v(?<version>\d+\.\d+\.\d+)", RegexOptions.Compiled); | ||
private static readonly Regex SemVerRef = GetSemVerRegex(); | ||
|
||
public static bool IsOnSemVerTag(this GitHubActions source) | ||
{ | ||
return !string.IsNullOrWhiteSpace(source?.Ref) | ||
&& SemVerRef.IsMatch(source.Ref); | ||
} | ||
public static bool IsOnSemVerTag(this GitHubActions source) | ||
{ | ||
return !string.IsNullOrWhiteSpace(source?.Ref) | ||
&& SemVerRef.IsMatch(source.Ref); | ||
} | ||
|
||
[GeneratedRegex(@"^refs\/tags\/v(?<version>\d+\.\d+\.\d+)", RegexOptions.Compiled)] | ||
private static partial Regex GetSemVerRegex(); | ||
} |
This file contains hidden or 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 hidden or 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,52 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using AutoFixture.TUnit.Internal; | ||
|
||
namespace AutoFixture.TUnit; | ||
|
||
/// <summary> | ||
/// Provides a data source for a data theory, with the data coming from inline | ||
/// values combined with auto-generated data specimens generated by AutoFixture. | ||
/// </summary> | ||
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", | ||
Justification = "This attribute is the root of a potential attribute hierarchy.")] | ||
public class ArgumentsAutoDataAttribute : AutoFixtureDataSourceAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ArgumentsAutoDataAttribute" /> class. | ||
/// </summary> | ||
/// <param name="values">The data values to pass to the theory.</param> | ||
public ArgumentsAutoDataAttribute(params object?[] values) | ||
: this(() => new Fixture(), values) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ArgumentsAutoDataAttribute" /> class. | ||
/// </summary> | ||
/// <param name="fixtureFactory">The fixture factory.</param> | ||
/// <param name="values">The data values to pass to the theory.</param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
protected ArgumentsAutoDataAttribute(Func<IFixture> fixtureFactory, params object?[]? values) | ||
{ | ||
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); | ||
this.Values = values ?? [null]; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the fixture factory. | ||
/// </summary> | ||
public Func<IFixture> FixtureFactory { get; } | ||
|
||
/// <summary> | ||
/// Gets the data values to pass to the theory. | ||
/// </summary> | ||
public object?[] Values { get; } | ||
|
||
/// <inheritdoc /> | ||
public override IEnumerable<object?[]> GetData(DataGeneratorMetadata dataGeneratorMetadata) | ||
{ | ||
return new AutoDataSource(this.FixtureFactory, new InlineDataSource(this.Values)) | ||
.GenerateDataSources(dataGeneratorMetadata) | ||
.Select(x => x()); | ||
} | ||
} |
This file contains hidden or 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,51 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using AutoFixture.TUnit.Internal; | ||
|
||
namespace AutoFixture.TUnit; | ||
|
||
/// <summary> | ||
/// Provides auto-generated data specimens generated by AutoFixture as an extension to | ||
/// xUnit.net's Theory attribute. | ||
/// </summary> | ||
[SuppressMessage("Microsoft.Performance", "CA1813:AvoidUnsealedAttributes", | ||
Justification = "This attribute is the root of a potential attribute hierarchy.")] | ||
public class AutoDataAttribute : AutoFixtureDataSourceAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AutoDataAttribute" /> class. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para> | ||
/// This constructor overload initializes the <see cref="Fixture" /> to an instance of | ||
/// <see cref="Fixture" />. | ||
/// </para> | ||
/// </remarks> | ||
public AutoDataAttribute() | ||
: this(() => new Fixture()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AutoDataAttribute" /> class | ||
/// with the supplied <paramref name="fixtureFactory" />. Fixture will be created | ||
/// on demand using the provided factory. | ||
/// </summary> | ||
/// <param name="fixtureFactory">The fixture factory used to construct the fixture.</param> | ||
protected AutoDataAttribute(Func<IFixture> fixtureFactory) | ||
{ | ||
this.FixtureFactory = fixtureFactory ?? throw new ArgumentNullException(nameof(fixtureFactory)); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the fixture factory. | ||
/// </summary> | ||
public Func<IFixture> FixtureFactory { get; } | ||
|
||
/// <inheritdoc /> | ||
public override IEnumerable<object?[]> GetData(DataGeneratorMetadata dataGeneratorMetadata) | ||
{ | ||
var source = new AutoDataSource(this.FixtureFactory); | ||
|
||
return source.GenerateDataSources(dataGeneratorMetadata).Select(x => x()); | ||
} | ||
} |
This file contains hidden or 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,56 @@ | ||
using AutoFixture.TUnit.Internal; | ||
|
||
namespace AutoFixture.TUnit; | ||
|
||
/// <summary> | ||
/// Base class for data sources that provide AutoFixture test data for TUnit data driven tests. | ||
/// </summary> | ||
public abstract class AutoFixtureDataSourceAttribute : NonTypedDataSourceGeneratorAttribute, IDataSource | ||
{ | ||
/// <summary> | ||
/// Returns the test data provided by the source. | ||
/// </summary> | ||
/// <param name="dataGeneratorMetadata"></param> | ||
/// <returns></returns> | ||
public abstract IEnumerable<object?[]?> GetData(DataGeneratorMetadata dataGeneratorMetadata); | ||
|
||
/// <inheritdoc /> | ||
public override IEnumerable<Func<object?[]>> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) | ||
{ | ||
if (dataGeneratorMetadata is null) | ||
{ | ||
throw new ArgumentNullException(nameof(dataGeneratorMetadata)); | ||
} | ||
|
||
return GetTestDataEnumerable(); | ||
|
||
IEnumerable<Func<object?[]>> GetTestDataEnumerable() | ||
{ | ||
var parameters = dataGeneratorMetadata.MembersToGenerate; | ||
if (parameters.Length == 0) | ||
{ | ||
// If the method has no parameters, a single test run is enough. | ||
yield return () => []; | ||
yield break; | ||
} | ||
|
||
var enumerable = this.GetData(dataGeneratorMetadata) | ||
?? throw new InvalidOperationException("The source member yielded no test data."); | ||
|
||
foreach (var testData in enumerable) | ||
{ | ||
if (testData is null) | ||
{ | ||
throw new InvalidOperationException("The source member yielded a null test data."); | ||
} | ||
|
||
if (testData.Length > parameters.Length) | ||
{ | ||
throw new InvalidOperationException("The number of arguments provided exceeds the number of parameters."); | ||
} | ||
|
||
yield return () => testData; | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.