Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: string
description: The version of the library
required: true
default: 2.2.0
default: 2.3.0
VersionSuffix:
type: string
description: The version suffix of the library (for example rc.1)
Expand Down
6 changes: 0 additions & 6 deletions CodeCoverage.runsettings
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@
</Exclude>
</Attributes>

<CompanyNames>
<Include>
<CompanyName>.*PosInformatique.*</CompanyName>
</Include>
</CompanyNames>

<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
Expand Down
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.SqlServer.DacFx" Version="162.1.172" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="PosInformatique.Testing.Databases.SqlServer.EntityFramework" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="coverlet.collector">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="PosInformatique.Testing.Databases.SqlServer.EntityFramework" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="FluentAssertions" Version="6.12.1" />
<PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="FluentAssertions" Version="7.2.0" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.0.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.9" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.9" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageVersion Include="Microsoft.SqlServer.DacFx" Version="161.6374.0" />
<PackageVersion Include="PosInformatique.Testing.Databases.SqlServer.EntityFramework" Version="2.1.0-rc.3" />
<PackageVersion Include="PosInformatique.Testing.Databases.SqlServer.EntityFramework" Version="2.3.0-rc.1" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.4" />
</ItemGroup>
</Project>
58 changes: 55 additions & 3 deletions src/Testing.Databases.SqlServer/Comparer/SqlObjectComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace PosInformatique.Testing.Databases.SqlServer
{
using System.Diagnostics.CodeAnalysis;

internal sealed class SqlObjectComparer : ISqlObjectVisitor<SqlObjectDifferences?>
{
private readonly SqlObject source;
Expand Down Expand Up @@ -73,7 +75,7 @@ public static IList<SqlTableDifferences> Compare(IReadOnlyList<SqlTable> source,
this.CompareProperty(column, t => t.Precision, nameof(column.Precision)),
this.CompareProperty(column, t => t.Scale, nameof(column.Scale)),
this.CompareProperty(column, t => t.IsNullable, nameof(column.IsNullable)),
this.CompareProperty(column, t => t.IsIdentity, nameof(column.IsIdentity)),
this.CompareProperty(column, t => t.Identity, nameof(column.Identity), equalityComparer: SqlColumnIdentityComparer.Instance),
this.CompareProperty(column, t => t.CollationName, nameof(column.CollationName)),
this.CompareProperty(column, t => t.IsComputed, nameof(column.IsComputed)),
this.CompareProperty(column, t => TsqlCodeHelper.RemoveNotUsefulCharacters(t.ComputedExpression), nameof(column.ComputedExpression), t => t.ComputedExpression));
Expand Down Expand Up @@ -331,7 +333,7 @@ private static IReadOnlyList<SqlObjectPropertyDifference> GetPropertyDifferences
return objects.SingleOrDefault(o => Equals(keySelector(o), value));
}

private SqlObjectPropertyDifference? CompareProperty<TSqlObject>(TSqlObject target, Func<TSqlObject, object?> propertyValueForComparison, string name, Func<TSqlObject, object?>? propertyValueToDisplay = null)
private SqlObjectPropertyDifference? CompareProperty<TSqlObject, TProperty>(TSqlObject target, Func<TSqlObject, TProperty?> propertyValueForComparison, string name, Func<TSqlObject, TProperty?>? propertyValueToDisplay = null, IEqualityComparer<TProperty?>? equalityComparer = null)
where TSqlObject : SqlObject
{
var source = (TSqlObject)this.source;
Expand All @@ -344,7 +346,12 @@ private static IReadOnlyList<SqlObjectPropertyDifference> GetPropertyDifferences
var sourceValue = propertyValueForComparison(source);
var targetValue = propertyValueForComparison(target);

if (!Equals(sourceValue, targetValue))
if (equalityComparer is null)
{
equalityComparer = EqualityComparer<TProperty?>.Default;
}

if (!equalityComparer.Equals(sourceValue, targetValue))
{
return new SqlObjectPropertyDifference(name, propertyValueToDisplay(source), propertyValueToDisplay(target));
}
Expand All @@ -364,5 +371,50 @@ private static IReadOnlyList<SqlObjectPropertyDifference> GetPropertyDifferences

return new SqlObjectDifferences<TSqlObject>((TSqlObject)this.source, target, SqlObjectDifferenceType.Different, properties!);
}

private sealed class SqlColumnIdentityComparer : IEqualityComparer<SqlColumnIdentity?>
{
private SqlColumnIdentityComparer()
{
}

public static SqlColumnIdentityComparer Instance { get; } = new SqlColumnIdentityComparer();

public bool Equals(SqlColumnIdentity? x, SqlColumnIdentity? y)
{
if (x is null)
{
if (y is null)
{
return true;
}

return false;
}

if (y is null)
{
return false;
}

if (x.Seed != y.Seed)
{
return false;
}

if (x.Increment != y.Increment)
{
return false;
}

return true;
}

[ExcludeFromCodeCoverage]
public int GetHashCode(SqlColumnIdentity? obj)
{
throw new NotImplementedException();
}
}
}
}
2 changes: 1 addition & 1 deletion src/Testing.Databases.SqlServer/ObjectModel/SqlColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal SqlColumn(
/// <summary>
/// Gets a value indicating whether if the column is identity.
/// </summary>
public bool IsIdentity { get; internal set; }
public SqlColumnIdentity? Identity { get; internal set; }

/// <summary>
/// Gets a value indicating whether if the column is computed.
Expand Down
42 changes: 42 additions & 0 deletions src/Testing.Databases.SqlServer/ObjectModel/SqlColumnIdentity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//-----------------------------------------------------------------------
// <copyright file="SqlColumnIdentity.cs" company="P.O.S Informatique">
// Copyright (c) P.O.S Informatique. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace PosInformatique.Testing.Databases
{
/// <summary>
/// Represents the <see cref="SqlColumn.Identity"/> information when
/// a <see cref="SqlColumn"/> is an <c>IDENTITY</c> column.
/// </summary>
public class SqlColumnIdentity
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlColumnIdentity"/> class.
/// </summary>
/// <param name="seed">Seed of the <c>IDENTITY</c> column.</param>
/// <param name="increment">Increment of the <c>IDENTITY</c> column.</param>
public SqlColumnIdentity(int seed, int increment)
{
this.Seed = seed;
this.Increment = increment;
}

/// <summary>
/// Gets the seed of the <c>IDENTITY</c> column.
/// </summary>
public int Seed { get; }

/// <summary>
/// Gets the increment of the <c>IDENTITY</c> column.
/// </summary>
public int Increment { get; }

/// <inheritdoc />
public override string ToString()
{
return $"(Seed: {this.Seed}, Increment: {this.Increment})";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,18 @@ private static async Task<ILookup<int, DataRow>> GetColumnsAsync(SqlServerDataba
[c].[collation_name] AS [CollationName],
[c].[is_nullable] AS [IsNullable],
[c].[is_identity] AS [IsIdentity],
[ic].[seed_value] AS [IdentitySeed],
[ic].[increment_value] AS [IdentityIncrement],
[c].[is_computed] AS [IsComputed],
[cc].[definition] AS [ComputedExpression]
FROM
[sys].[columns] AS [c]
LEFT OUTER JOIN
[sys].[computed_columns] AS [cc]
ON ([c].[object_id] = [cc].[object_id] AND [c].[column_id] = [cc].[column_id]),
ON ([c].[object_id] = [cc].[object_id] AND [c].[column_id] = [cc].[column_id])
LEFT OUTER JOIN
[sys].[identity_columns] AS [ic]
ON ([c].[object_id] = [ic].[object_id] AND [c].[column_id] = [ic].[column_id]),
[sys].[tables] AS [t],
[sys].[types] AS [ty]
WHERE
Expand Down Expand Up @@ -500,6 +505,13 @@ private static SqlCheckConstraint ToCheckConstraint(DataRow row)

private static SqlColumn ToColumn(DataRow row, DataRow? defaultConstraintRow)
{
SqlColumnIdentity? identity = null;

if ((bool)row["IsIdentity"] == true)
{
identity = new SqlColumnIdentity((int)row["IdentitySeed"], (int)row["IdentityIncrement"]);
}

return new SqlColumn(
(string)row["Name"],
Convert.ToInt32(row["Position"], CultureInfo.InvariantCulture),
Expand All @@ -512,7 +524,7 @@ private static SqlColumn ToColumn(DataRow row, DataRow? defaultConstraintRow)
ComputedExpression = NullIfDbNull<string>(row["ComputedExpression"]),
DefaultConstraint = defaultConstraintRow != null ? ToDefaultConstraint(defaultConstraintRow) : null,
IsComputed = (bool)row["IsComputed"],
IsIdentity = (bool)row["IsIdentity"],
Identity = identity,
IsNullable = (bool)row["IsNullable"],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[MaxLength] VARCHAR(50) NOT NULL,
[Precision] DECIMAL(10, 2) NOT NULL,
[Scale] DECIMAL(10, 2) NOT NULL,
[Identity] INT NOT NULL IDENTITY,
[Identity] INT NOT NULL IDENTITY (2, 3),
[ForeignKeyId] INT NULL,
[Computed] AS [Scale] + [Precision],
[SourceColumn] INT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE [dbo].[TableIdentical]
(
[Id] INT NOT NULL,
[Id] INT IDENTITY (4, 5) NOT NULL,
[ForeignKeyId] INT NOT NULL CONSTRAINT DF_TableIdentical_ForeignKeyId DEFAULT (1 + 2 + 3),
[IncludeColumn] INT NOT NULL,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE [dbo].[TableWithDifferentPrimaryKey]
(
[Id] INT NOT NULL,
[Id] INT IDENTITY (10, 20) NOT NULL,

CONSTRAINT [PK_TableWithDifferentPrimaryKey_Source] PRIMARY KEY CLUSTERED ([Id] ASC)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE [dbo].[TableWithNoPrimaryKey]
(
[Id] INT IDENTITY (10, 20) NOT NULL,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE [dbo].[TableDifference]
ADD CONSTRAINT [UniqueConstraintDifferenceMissingInTarget]
UNIQUE NONCLUSTERED ([Scale])
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,7 @@
<Build Include="Views\ViewDifference.sql" />
<Build Include="Tables\__EFMigrationsHistorySource.sql" />
<Build Include="Tables\TableWithDifferentPrimaryKey.sql" />
<Build Include="Tables\TableWithNoPrimaryKey.sql" />
<Build Include="Tables\UniqueConstraints\UniqueConstraintDifferenceMissingInTarget.sql" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CREATE TABLE [dbo].[TableWithDifferentPrimaryKey]
(
[Id] INT NOT NULL,
[Id] INT IDENTITY (1, 2) NOT NULL,

CONSTRAINT [PK_TableWithDifferentPrimaryKey_Target] PRIMARY KEY CLUSTERED ([Id] ASC)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE [dbo].[TableWithNoPrimaryKey]
(
[Id] INT IDENTITY (10, 30) NOT NULL,
)
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@
<Build Include="Tables\Triggers\TriggerIdentical.sql" />
<Build Include="Tables\__EFMigrationsHistoryTarget.sql" />
<Build Include="Tables\TableWithDifferentPrimaryKey.sql" />
<Build Include="Tables\TableWithNoPrimaryKey.sql" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//-----------------------------------------------------------------------
// <copyright file="SqlColumnIdentityTest.cs" company="P.O.S Informatique">
// Copyright (c) P.O.S Informatique. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace PosInformatique.Testing.Databases.Tests
{
public class SqlColumnIdentityTest
{
[Fact]
public void ToStringTest()
{
var column = new SqlColumnIdentity(1, 2);

column.ToString().Should().Be("(Seed: 1, Increment: 2)");
}
}
}
Loading
Loading