Skip to content

Commit 5e332ec

Browse files
authored
refactor: add separate project for parity tests (#1219)
Also get rid of the [Snapshooter.NUnit](https://www.nuget.org/packages/Snapshooter.NUnit) dependency.
1 parent ecadf25 commit 5e332ec

File tree

37 files changed

+62
-25
lines changed

37 files changed

+62
-25
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageVersion Include="System.IO.FileSystem.AccessControl" Version="5.0.0" />
7+
<PackageVersion Include="System.Text.Json" Version="9.0.2"/>
78
<PackageVersion Include="IsExternalInit" Version="1.0.3" />
89
<PackageVersion Include="Nullable" Version="1.3.1" />
910
<PackageVersion Include="Testably.Abstractions.FileSystem.Interface" Version="9.0.0" />
@@ -17,7 +18,6 @@
1718
<PackageVersion Include="NUnit" Version="4.3.2" />
1819
<PackageVersion Include="NUnit.Analyzers" Version="4.6.0" />
1920
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
20-
<PackageVersion Include="Snapshooter.NUnit" Version="1.0.1" />
2121
<PackageVersion Include="PublicApiGenerator" Version="11.4.2"/>
2222
<PackageVersion Include="aweXpect" Version="1.0.1"/>
2323
</ItemGroup>

System.IO.Abstractions.sln

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{B66A0B3F-6A0
4444
ProjectSection(SolutionItems) = preProject
4545
src\Directory.Build.props = src\Directory.Build.props
4646
EndProjectSection
47+
EndProject
4748
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{10F39E91-97F2-4812-9D2F-79BE18EC6B08}"
4849
EndProject
4950
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestableIO.System.IO.Abstractions.Api.Tests", "tests\TestableIO.System.IO.Abstractions.Api.Tests\TestableIO.System.IO.Abstractions.Api.Tests.csproj", "{7DE6AD74-E2B3-498E-90C5-DDF3188F333A}"
@@ -53,6 +54,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{5971F640
5354
tests\Directory.Build.props = tests\Directory.Build.props
5455
EndProjectSection
5556
EndProject
57+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestableIO.System.IO.Abstractions.Parity.Tests", "tests\TestableIO.System.IO.Abstractions.Parity.Tests\TestableIO.System.IO.Abstractions.Parity.Tests.csproj", "{93B79631-E220-414B-8F0D-3885825DE1AC}"
58+
EndProject
5659
Global
5760
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5861
Debug|Any CPU = Debug|Any CPU
@@ -95,6 +98,10 @@ Global
9598
{7DE6AD74-E2B3-498E-90C5-DDF3188F333A}.Debug|Any CPU.Build.0 = Debug|Any CPU
9699
{7DE6AD74-E2B3-498E-90C5-DDF3188F333A}.Release|Any CPU.ActiveCfg = Release|Any CPU
97100
{7DE6AD74-E2B3-498E-90C5-DDF3188F333A}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{93B79631-E220-414B-8F0D-3885825DE1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{93B79631-E220-414B-8F0D-3885825DE1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{93B79631-E220-414B-8F0D-3885825DE1AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{93B79631-E220-414B-8F0D-3885825DE1AC}.Release|Any CPU.Build.0 = Release|Any CPU
98105
EndGlobalSection
99106
GlobalSection(SolutionProperties) = preSolution
100107
HideSolutionNode = FALSE
@@ -111,6 +118,7 @@ Global
111118
{015B3812-E01D-479C-895D-BDDF16E798CA} = {10F39E91-97F2-4812-9D2F-79BE18EC6B08}
112119
{7DE6AD74-E2B3-498E-90C5-DDF3188F333A} = {BCEC61BD-4941-41EC-975A-ACEFC7AC1780}
113120
{5971F640-8BBA-4264-BCD6-60A97DD54B4A} = {BBF7AD8D-5522-48C0-A906-00CBB72308A0}
121+
{93B79631-E220-414B-8F0D-3885825DE1AC} = {BCEC61BD-4941-41EC-975A-ACEFC7AC1780}
114122
EndGlobalSection
115123
GlobalSection(ExtensibilityGlobals) = postSolution
116124
SolutionGuid = {8885C59C-F6A0-4C2F-A3BC-B720E9BD161F}

tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/ApiParityTests.cs renamed to tests/TestableIO.System.IO.Abstractions.Parity.Tests/ApiParityTests.cs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Collections.Generic;
22
using System.Linq;
3+
using System.Text.Json;
4+
using System.Threading.Tasks;
5+
using aweXpect;
36
using NUnit.Framework;
4-
using Snapshooter;
5-
using Snapshooter.NUnit;
67
using static System.Reflection.BindingFlags;
78

89
namespace System.IO.Abstractions.Tests
@@ -11,62 +12,62 @@ namespace System.IO.Abstractions.Tests
1112
public class ApiParityTests
1213
{
1314
[Test]
14-
public void File() =>
15-
AssertParity(
15+
public async Task File() =>
16+
await AssertParity(
1617
typeof(System.IO.File),
1718
typeof(System.IO.Abstractions.FileBase)
1819
);
1920

2021
[Test]
21-
public void FileInfo() =>
22-
AssertParity(
22+
public async Task FileInfo() =>
23+
await AssertParity(
2324
typeof(System.IO.FileInfo),
2425
typeof(System.IO.Abstractions.FileInfoBase)
2526
);
2627

2728
[Test]
28-
public void FileVersionInfo() =>
29-
AssertParity(
29+
public async Task FileVersionInfo() =>
30+
await AssertParity(
3031
typeof(System.Diagnostics.FileVersionInfo),
3132
typeof(System.IO.Abstractions.FileVersionInfoBase)
3233
);
3334

3435
[Test]
35-
public void Directory() =>
36-
AssertParity(
36+
public async Task Directory() =>
37+
await AssertParity(
3738
typeof(System.IO.Directory),
3839
typeof(System.IO.Abstractions.DirectoryBase)
3940
);
4041

4142
[Test]
42-
public void DirectoryInfo() =>
43-
AssertParity(
43+
public async Task DirectoryInfo() =>
44+
await AssertParity(
4445
typeof(System.IO.DirectoryInfo),
4546
typeof(System.IO.Abstractions.DirectoryInfoBase)
4647
);
4748

4849
[Test]
49-
public void DriveInfo() =>
50-
AssertParity(
50+
public async Task DriveInfo() =>
51+
await AssertParity(
5152
typeof(System.IO.DriveInfo),
5253
typeof(System.IO.Abstractions.DriveInfoBase)
5354
);
5455

5556
[Test]
56-
public void Path() =>
57-
AssertParity(
57+
public async Task Path() =>
58+
await AssertParity(
5859
typeof(System.IO.Path),
5960
typeof(System.IO.Abstractions.PathBase)
6061
);
6162

6263
[Test]
63-
public void FileSystemWatcher() =>
64-
AssertParity(
64+
public async Task FileSystemWatcher() =>
65+
await AssertParity(
6566
typeof(System.IO.FileSystemWatcher),
6667
typeof(System.IO.Abstractions.FileSystemWatcherBase)
6768
);
6869

69-
private void AssertParity(Type referenceType, Type abstractionType)
70+
private async Task AssertParity(Type referenceType, Type abstractionType)
7071
{
7172
static IEnumerable<string> GetMembers(Type type) => type
7273
.GetMembers(bindingAttr: Instance | Static | Public | FlattenHierarchy)
@@ -89,9 +90,23 @@ static IEnumerable<string> GetMembers(Type type) => type
8990
extraMembers: abstractionMembers.Except(referenceMembers),
9091
missingMembers: referenceMembers.Except(abstractionMembers)
9192
);
92-
Snapshot.Match(diff, SnapshotNameExtension.Create(snapshotSuffix));
93+
94+
var serializedDiff = JsonSerializer.Serialize(diff, SerializerOptions);
95+
96+
var snapshotPath = IO.Path.GetFullPath("../../../__snapshots__/");
97+
var fileName = $"ApiParityTests.{referenceType.Name}_{snapshotSuffix}.snap";
98+
var fileContent = IO.File.ReadAllText(IO.Path.Combine(snapshotPath, fileName));
99+
100+
await Expect.That(fileContent).IsEqualTo(serializedDiff)
101+
.IgnoringNewlineStyle()
102+
.IgnoringTrailingWhiteSpace();
93103
}
94104

105+
private static JsonSerializerOptions SerializerOptions = new()
106+
{
107+
WriteIndented = true
108+
};
109+
95110
private readonly struct ApiDiff
96111
{
97112
public ApiDiff(IEnumerable<string> extraMembers, IEnumerable<string> missingMembers)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<Description>The unit tests for our the parity checks</Description>
5+
<AssemblyName>System.IO.Abstractions.Parity.Tests</AssemblyName>
6+
<RootNamespace>System.IO.Abstractions.Parity.Tests</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\src\TestableIO.System.IO.Abstractions.Wrappers\TestableIO.System.IO.Abstractions.Wrappers.csproj" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<PackageReference Include="aweXpect"/>
15+
<PackageReference Include="System.Text.Json"/>
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)