-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move FluentAssertion reference into its own package
- Loading branch information
1 parent
fa2af95
commit a2a14a6
Showing
12 changed files
with
176 additions
and
49 deletions.
There are no files selected for viewing
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
src/Snapshooter.NUnit.TypedFluentAssertions/FluentSnapshotExtension.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,31 @@ | ||
using FluentAssertions; | ||
using System; | ||
|
||
namespace Snapshooter.NUnit; | ||
|
||
public static class FluentSnapshotExtension | ||
{ | ||
/// <summary> | ||
/// Creates a json snapshot of the given object and compares it with the | ||
/// already existing snapshot of the test. | ||
/// If no snapshot exists, a new snapshot will be created from the current result | ||
/// and saved under a certain file path, which will shown within the test message. | ||
/// </summary> | ||
/// <param name="currentResult">The object to match.</param> | ||
/// <param name="matchOptions"> | ||
/// Additional compare actions, which can be applied during the snapshot comparison | ||
/// </param> | ||
public static void MatchSnapshot<TSubject>( | ||
this TypedAssertions<TSubject> currentResult, | ||
Func<MatchOptions<TSubject>, MatchOptions<TSubject>>? matchOptions = null) | ||
{ | ||
var cleanedObject = currentResult.RemoveUnwantedWrappers(); | ||
|
||
Func<MatchOptions, MatchOptions>? chainedMatchOptions = | ||
matchOptions != null ? m => matchOptions(new MatchOptions<TSubject>(m)) : null; | ||
|
||
Snapshot.Match( | ||
cleanedObject, | ||
chainedMatchOptions); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Snapshooter.NUnit.TypedFluentAssertions/Snapshooter.NUnit.TypedFluentAssertions.csproj
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$(CCResourceProjectProps)" Condition="Exists('$(CCResourceProjectProps)')" /> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Snapshooter.NUnit.TypedFluentAssertions</AssemblyName> | ||
<RootNamespace>Snapshooter.NUnit.TypedFluentAssertions</RootNamespace> | ||
<PackageId>Snapshooter.NUnit.TypedFluentAssertions</PackageId> | ||
<Description> | ||
TypedFluentAssertions is an extention to FluentAssertions and Snapshooter.NUnit. | ||
It allows to configure snapshots in a type save and fluent way. | ||
</Description> | ||
<IsTestProject>false</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Snapshooter.NUnit\Snapshooter.NUnit.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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
29 changes: 29 additions & 0 deletions
29
src/Snapshooter.Xunit.TypedFluentAssertions/FluentAssertionsExtension.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,29 @@ | ||
using FluentAssertions.Primitives; | ||
|
||
// Extension of Fluent assertion to not loose type information of asserted object | ||
namespace FluentAssertions; | ||
|
||
/// <summary> | ||
/// Contains a number of methods to assert that an <see cref="object"/> is in the expected state. | ||
/// </summary> | ||
public class TypedAssertions<T> : ObjectAssertions<T, TypedAssertions<T>> | ||
{ | ||
internal TypedAssertions(T value) : base(value) | ||
{ | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Contains extension methods for custom assertions in unit tests. | ||
/// </summary> | ||
public static class AssertionExtensions | ||
{ | ||
/// <summary> | ||
/// Returns an <see cref="TypedAssertions{T}"/> object that can be used to assert the | ||
/// current <see cref="object"/>. | ||
/// </summary> | ||
public static TypedAssertions<TSubject> Should<TSubject>(this TSubject actualValue) | ||
{ | ||
return new TypedAssertions<TSubject>(actualValue); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Snapshooter.Xunit.TypedFluentAssertions/FluentSnapshotExtension.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,31 @@ | ||
using FluentAssertions; | ||
using System; | ||
|
||
namespace Snapshooter.Xunit; | ||
|
||
public static class FluentSnapshotExtension | ||
{ | ||
/// <summary> | ||
/// Creates a json snapshot of the given object and compares it with the | ||
/// already existing snapshot of the test. | ||
/// If no snapshot exists, a new snapshot will be created from the current result | ||
/// and saved under a certain file path, which will shown within the test message. | ||
/// </summary> | ||
/// <param name="currentResult">The object to match.</param> | ||
/// <param name="matchOptions"> | ||
/// Additional compare actions, which can be applied during the snapshot comparison | ||
/// </param> | ||
public static void MatchSnapshot<TSubject>( | ||
this TypedAssertions<TSubject> currentResult, | ||
Func<MatchOptions<TSubject>, MatchOptions<TSubject>>? matchOptions = null) | ||
{ | ||
var cleanedObject = currentResult.RemoveUnwantedWrappers(); | ||
|
||
Func<MatchOptions, MatchOptions>? chainedMatchOptions = | ||
matchOptions != null ? m => matchOptions(new MatchOptions<TSubject>(m)) : null; | ||
|
||
Snapshot.Match( | ||
cleanedObject, | ||
chainedMatchOptions); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Snapshooter.Xunit.TypedFluentAssertions/Snapshooter.Xunit.TypedFluentAssertions.csproj
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,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$(CCResourceProjectProps)" Condition="Exists('$(CCResourceProjectProps)')" /> | ||
|
||
<PropertyGroup> | ||
<AssemblyName>Snapshooter.Xunit.TypedFluentAssertions</AssemblyName> | ||
<RootNamespace>Snapshooter.Xunit.TypedFluentAssertions</RootNamespace> | ||
<PackageId>Snapshooter.Xunit.TypedFluentAssertions</PackageId> | ||
<Description> | ||
TypedFluentAssertions is an extention to FluentAssertions and Snapshooter.Xunit. | ||
It allows to configure snapshots in a type save and fluent way. | ||
</Description> | ||
<IsTestProject>false</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FluentAssertions" Version="6.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Snapshooter.Xunit\Snapshooter.Xunit.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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