Skip to content

Commit 3418f6c

Browse files
author
Jason Valdez
committed
Issue-2 Added test framework to verify that each implementation test assembly has matching test classes and methods.
1 parent 5199342 commit 3418f6c

23 files changed

+445
-62
lines changed

src/IntegrationPostgreSqlTests/BulkLoading/BulkLoaderForPrimaryKeyTests.cs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Linq;
1+
using System.Linq;
32
using FluentAssertions;
43
using ivaldez.Sql.IntegrationPostgreSqlTests.Data;
54
using ivaldez.SqlBulkLoader.PostgreSql;
@@ -108,40 +107,5 @@ public void ShouldNotInsertPrimaryKeyWhenKeepIdentityOptionIsFalse()
108107
secondDto.IntValue.Should().Be(999);
109108
secondDto.DecimalValue.Should().Be(123.45m);
110109
}
111-
112-
[Fact]
113-
public void ShouldThrowErrorIfIdentityValueIsNotSupplied()
114-
{
115-
var testingDatabaseService = new TestingDatabaseService();
116-
testingDatabaseService.CreateTestDatabase();
117-
118-
var dataGateway = new TestingDataGateway(testingDatabaseService);
119-
120-
dataGateway.DropTable();
121-
dataGateway.CreateSingleSurrogateKeyTable();
122-
123-
var dtos = new[]
124-
{
125-
new SampleSurrogateKey
126-
{
127-
Pk = 100,
128-
TextValue = "JJ",
129-
IntValue = 100,
130-
DecimalValue = 100.99m
131-
}
132-
};
133-
134-
var exception = Assert.Throws<ArgumentException>(() =>
135-
{
136-
dataGateway.ExecuteWithConnection(conn =>
137-
{
138-
BulkLoaderFactory.Create()
139-
.InsertWithOptions("sample", conn, true, dtos)
140-
.Execute();
141-
});
142-
});
143-
144-
exception.Message.Should().Contain(@"must be called when ""keepIdentityColumnValue"" is True.");
145-
}
146110
}
147111
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using FluentAssertions;
3+
using ivaldez.Sql.IntegrationPostgreSqlTests.Data;
4+
using ivaldez.SqlBulkLoader.PostgreSql;
5+
using SharedTestFramework;
6+
using Xunit;
7+
8+
namespace ivaldez.Sql.IntegrationPostgreSqlTests.ImplementationSpecific.BulkLoading
9+
{
10+
[ImplementationSpecificTest]
11+
public class BulkLoaderForPrimaryKeyTests
12+
{
13+
[Fact]
14+
public void ShouldThrowErrorIfIdentityValueIsNotSupplied()
15+
{
16+
var testingDatabaseService = new TestingDatabaseService();
17+
testingDatabaseService.CreateTestDatabase();
18+
19+
var dataGateway = new TestingDataGateway(testingDatabaseService);
20+
21+
dataGateway.DropTable();
22+
dataGateway.CreateSingleSurrogateKeyTable();
23+
24+
var dtos = new[]
25+
{
26+
new SampleSurrogateKey
27+
{
28+
Pk = 100,
29+
TextValue = "JJ",
30+
IntValue = 100,
31+
DecimalValue = 100.99m
32+
}
33+
};
34+
35+
var exception = Assert.Throws<ArgumentException>(() =>
36+
{
37+
dataGateway.ExecuteWithConnection(conn =>
38+
{
39+
BulkLoaderFactory.Create()
40+
.InsertWithOptions("sample", conn, true, dtos)
41+
.Execute();
42+
});
43+
});
44+
45+
exception.Message.Should().Contain(@"must be called when ""keepIdentityColumnValue"" is True.");
46+
}
47+
}
48+
}

src/IntegrationPostgreSqlTests/IntegrationPostgreSqlTests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
<Compile Include="BulkLoading\BulkLoaderForFieldOptionsTests.cs" />
107107
<Compile Include="BulkLoading\BulkLoaderForPrimaryKeyTests.cs" />
108108
<Compile Include="BulkLoading\BulkLoaderForDefaultBulkCopyUtilityTests.cs" />
109+
<Compile Include="ImplementationSpecific\BulkLoading\BulkLoaderForPrimaryKeyTests.cs" />
109110
<Compile Include="BulkLoading\BulkLoaderGeneralTests.cs" />
110111
<Compile Include="BulkLoading\SqlBulkCopyUtilitySpy.cs" />
111112
<Compile Include="Data\SampleSurrogateKeyDifferentNamesDto.cs" />
@@ -126,10 +127,15 @@
126127
<Project>{3caf26e8-067f-4d30-a895-d9295a208735}</Project>
127128
<Name>ivaldez.SqlBulkLoader.PostgreSql</Name>
128129
</ProjectReference>
130+
<ProjectReference Include="..\SharedTestFramework\SharedTestFramework.csproj">
131+
<Project>{692D1C7C-4403-468B-B2E8-51DA8EF0C654}</Project>
132+
<Name>SharedTestFramework</Name>
133+
</ProjectReference>
129134
</ItemGroup>
130135
<ItemGroup>
131136
<WCFMetadata Include="Connected Services\" />
132137
</ItemGroup>
138+
<ItemGroup />
133139
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
134140
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
135141
<PropertyGroup>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Reflection;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using FluentAssertions;
8+
using Xunit;
9+
using Xunit.Abstractions;
10+
11+
namespace IntegrationShared
12+
{
13+
public class ConfirmMatchingTests
14+
{
15+
private ITestOutputHelper _output;
16+
17+
public ConfirmMatchingTests(ITestOutputHelper output)
18+
{
19+
_output = output;
20+
}
21+
22+
[Fact(DisplayName = "Should find matching tests for all shared features between implementations")]
23+
public void TestClassesMatchingTests()
24+
{
25+
var sourceClass1 = typeof(ivaldez.Sql.IntegrationPostgreSqlTests.BulkLoading.BulkLoaderForBatchSizeTests)
26+
.Assembly;
27+
var sourceClass2 = typeof(ivaldez.Sql.IntegrationSqlServerTests.BulkLoading.BulkLoaderForBatchSizeTests)
28+
.Assembly;
29+
30+
var allTestMethods1 = sourceClass1.GetTypes().Where(x => x.Name.ToLower().EndsWith("tests")).Select(x => x.Name).ToArray();
31+
var allTestMethods2 = sourceClass2.GetTypes().Where(x => x.Name.ToLower().EndsWith("tests")).Select(x => x.Name).ToArray();
32+
33+
var testsMIssingIn1 = allTestMethods1.Except(allTestMethods2).ToArray();
34+
var testsMIssingIn2 = allTestMethods2.Except(allTestMethods1).ToArray();
35+
36+
_output.WriteLine($"Test classes missing in: {sourceClass1}");
37+
foreach (var missing in testsMIssingIn1)
38+
{
39+
_output.WriteLine($"Test classes missing: {missing}");
40+
}
41+
42+
_output.WriteLine($"Test classes missing in: {sourceClass2}");
43+
foreach (var missing in testsMIssingIn2)
44+
{
45+
_output.WriteLine($"Test classes missing: {missing}");
46+
}
47+
48+
testsMIssingIn1.Length.Should().Be(0);
49+
testsMIssingIn2.Length.Should().Be(0);
50+
}
51+
52+
[Fact(DisplayName = "Should find matching test methods for all shared features between implementations")]
53+
public void TestMethodMatchingTests()
54+
{
55+
var sourceClass1 = typeof(ivaldez.Sql.IntegrationPostgreSqlTests.BulkLoading.BulkLoaderForBatchSizeTests)
56+
.Assembly;
57+
var sourceClass2 = typeof(ivaldez.Sql.IntegrationSqlServerTests.BulkLoading.BulkLoaderForBatchSizeTests)
58+
.Assembly;
59+
60+
var allTestClasses1 = sourceClass1.GetTypes().Where(x => x.IsClass && x.Name.ToLower().EndsWith("tests")).ToArray();
61+
var allTestClasses2 = sourceClass2.GetTypes().Where(x => x.IsClass && x.Name.ToLower().EndsWith("tests")).ToArray();
62+
63+
var errorCount = 0;
64+
foreach (var classDefinition in allTestClasses1)
65+
{
66+
var matchingType = allTestClasses2.First(x => x.Name == classDefinition.Name);
67+
68+
var allTestMethods1 = classDefinition.GetMethods().Select(x => x.Name).ToArray();
69+
var allTestMethods2 = matchingType.GetMethods().Select(x => x.Name).ToArray();
70+
71+
var testsMIssingIn1 = allTestMethods1.Except(allTestMethods2).ToArray();
72+
var testsMIssingIn2 = allTestMethods2.Except(allTestMethods1).ToArray();
73+
74+
_output.WriteLine($"Test class: {classDefinition}");
75+
foreach (var missing in testsMIssingIn1)
76+
{
77+
errorCount++;
78+
_output.WriteLine($"***missing method: {missing}");
79+
}
80+
81+
_output.WriteLine($"Test class: {matchingType}");
82+
foreach (var missing in testsMIssingIn2)
83+
{
84+
errorCount++;
85+
_output.WriteLine($"***missing method: {missing}");
86+
}
87+
88+
_output.WriteLine($"");
89+
_output.WriteLine($"-----------------------");
90+
}
91+
92+
errorCount.Should().Be(0);
93+
}
94+
}
95+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{C15AA0BA-7C38-4CCA-9BC1-2F530C051445}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>IntegrationShared</RootNamespace>
12+
<AssemblyName>IntegrationShared</AssemblyName>
13+
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<Deterministic>true</Deterministic>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<DebugSymbols>true</DebugSymbols>
21+
<DebugType>full</DebugType>
22+
<Optimize>false</Optimize>
23+
<OutputPath>bin\Debug\</OutputPath>
24+
<DefineConstants>DEBUG;TRACE</DefineConstants>
25+
<ErrorReport>prompt</ErrorReport>
26+
<WarningLevel>4</WarningLevel>
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29+
<DebugType>pdbonly</DebugType>
30+
<Optimize>true</Optimize>
31+
<OutputPath>bin\Release\</OutputPath>
32+
<DefineConstants>TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<Reference Include="FluentAssertions, Version=5.9.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
38+
<HintPath>..\packages\FluentAssertions.5.9.0\lib\net47\FluentAssertions.dll</HintPath>
39+
</Reference>
40+
<Reference Include="System" />
41+
<Reference Include="System.Configuration" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
50+
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
51+
</Reference>
52+
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
53+
<HintPath>..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath>
54+
</Reference>
55+
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
56+
<HintPath>..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath>
57+
</Reference>
58+
<Reference Include="xunit.execution.desktop, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
59+
<HintPath>..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath>
60+
</Reference>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Include="ConfirmMatchingTests.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<None Include="app.config" />
68+
<None Include="packages.config" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Analyzer Include="..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<ProjectReference Include="..\IntegrationPostgreSqlTests\IntegrationPostgreSqlTests.csproj">
75+
<Project>{4ede707b-d415-41ce-8903-7a25b43d5898}</Project>
76+
<Name>IntegrationPostgreSqlTests</Name>
77+
</ProjectReference>
78+
<ProjectReference Include="..\IntegrationSqlServerTests\IntegrationSqlServerTests.csproj">
79+
<Project>{2570e931-33d4-4d86-b49d-d27f7ed29265}</Project>
80+
<Name>IntegrationSqlServerTests</Name>
81+
</ProjectReference>
82+
</ItemGroup>
83+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
84+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
85+
<PropertyGroup>
86+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
87+
</PropertyGroup>
88+
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.props'))" />
89+
<Error Condition="!Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" />
90+
</Target>
91+
<Import Project="..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\packages\xunit.core.2.3.1\build\xunit.core.targets')" />
92+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("IntegrationShared")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("IntegrationShared")]
13+
[assembly: AssemblyCopyright("Copyright © 2021")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c15aa0ba-7c38-4cca-9bc1-2f530c051445")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

src/IntegrationShared/app.config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<runtime>
4+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
5+
<dependentAssembly>
6+
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
7+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
8+
</dependentAssembly>
9+
<dependentAssembly>
10+
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
11+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
12+
</dependentAssembly>
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.2" newVersion="5.0.0.2" />
16+
</dependentAssembly>
17+
<dependentAssembly>
18+
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
19+
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
20+
</dependentAssembly>
21+
<dependentAssembly>
22+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
23+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
24+
</dependentAssembly>
25+
</assemblyBinding>
26+
</runtime>
27+
</configuration>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="FluentAssertions" version="5.9.0" targetFramework="net47" />
4+
<package id="xunit" version="2.3.1" targetFramework="net47" />
5+
<package id="xunit.abstractions" version="2.0.1" targetFramework="net47" />
6+
<package id="xunit.analyzers" version="0.7.0" targetFramework="net47" />
7+
<package id="xunit.assert" version="2.3.1" targetFramework="net47" />
8+
<package id="xunit.core" version="2.3.1" targetFramework="net47" />
9+
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net47" />
10+
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net47" />
11+
</packages>

0 commit comments

Comments
 (0)