Skip to content

Commit 2c6c9de

Browse files
Add a property in the comparison results to indicate if the two databases are identical.
1 parent 99a832a commit 2c6c9de

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

src/UnitTests.Databases.SqlServer/Comparer/SqlDatabaseComparisonResults.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace PosInformatique.UnitTests.Databases
88
{
99
using System.Collections.ObjectModel;
10-
using PosInformatique.UnitTests.Databases.SqlServer;
1110

1211
/// <summary>
1312
/// Represents the differences between 2 databases.
@@ -38,6 +37,37 @@ internal SqlDatabaseComparisonResults()
3837
/// </summary>
3938
public required ReadOnlyCollection<SqlObjectDifferences<SqlView>> Views { get; init; }
4039

40+
/// <summary>
41+
/// Gets a value indicating whether if the two database compared have the same schema.
42+
/// </summary>
43+
public bool IsIdentical
44+
{
45+
get
46+
{
47+
if (this.StoredProcedures.Count > 0)
48+
{
49+
return false;
50+
}
51+
52+
if (this.Tables.Count > 0)
53+
{
54+
return false;
55+
}
56+
57+
if (this.UserTypes.Count > 0)
58+
{
59+
return false;
60+
}
61+
62+
if (this.Views.Count > 0)
63+
{
64+
return false;
65+
}
66+
67+
return true;
68+
}
69+
}
70+
4171
/// <summary>
4272
/// Returns a textual representation of the result comparison.
4373
/// </summary>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//-----------------------------------------------------------------------
2+
// <copyright file="SqlDatabaseComparisonResultsTest.cs" company="P.O.S Informatique">
3+
// Copyright (c) P.O.S Informatique. All rights reserved.
4+
// </copyright>
5+
//-----------------------------------------------------------------------
6+
7+
namespace PosInformatique.UnitTests.Databases.Tests
8+
{
9+
using System.Collections.ObjectModel;
10+
11+
public class SqlDatabaseComparisonResultsTest
12+
{
13+
[Fact]
14+
public void IsIdentical()
15+
{
16+
var results = new SqlDatabaseComparisonResults()
17+
{
18+
StoredProcedures = new ReadOnlyCollection<SqlObjectDifferences<SqlStoredProcedure>>([null]),
19+
Tables = new ReadOnlyCollection<SqlTableDifferences>([null]),
20+
UserTypes = new ReadOnlyCollection<SqlObjectDifferences<SqlUserType>>([null]),
21+
Views = new ReadOnlyCollection<SqlObjectDifferences<SqlView>>([null]),
22+
};
23+
24+
results.IsIdentical.Should().BeFalse();
25+
}
26+
27+
[Fact]
28+
public void IsIdentical_StoredProcedure()
29+
{
30+
var results = new SqlDatabaseComparisonResults()
31+
{
32+
StoredProcedures = new ReadOnlyCollection<SqlObjectDifferences<SqlStoredProcedure>>([null]),
33+
Tables = new ReadOnlyCollection<SqlTableDifferences>([]),
34+
UserTypes = new ReadOnlyCollection<SqlObjectDifferences<SqlUserType>>([]),
35+
Views = new ReadOnlyCollection<SqlObjectDifferences<SqlView>>([]),
36+
};
37+
38+
results.IsIdentical.Should().BeFalse();
39+
}
40+
41+
[Fact]
42+
public void IsIdentical_Tables()
43+
{
44+
var results = new SqlDatabaseComparisonResults()
45+
{
46+
StoredProcedures = new ReadOnlyCollection<SqlObjectDifferences<SqlStoredProcedure>>([]),
47+
Tables = new ReadOnlyCollection<SqlTableDifferences>([null]),
48+
UserTypes = new ReadOnlyCollection<SqlObjectDifferences<SqlUserType>>([]),
49+
Views = new ReadOnlyCollection<SqlObjectDifferences<SqlView>>([]),
50+
};
51+
52+
results.IsIdentical.Should().BeFalse();
53+
}
54+
55+
[Fact]
56+
public void IsIdentical_UserTypes()
57+
{
58+
var results = new SqlDatabaseComparisonResults()
59+
{
60+
StoredProcedures = new ReadOnlyCollection<SqlObjectDifferences<SqlStoredProcedure>>([]),
61+
Tables = new ReadOnlyCollection<SqlTableDifferences>([]),
62+
UserTypes = new ReadOnlyCollection<SqlObjectDifferences<SqlUserType>>([null]),
63+
Views = new ReadOnlyCollection<SqlObjectDifferences<SqlView>>([]),
64+
};
65+
66+
results.IsIdentical.Should().BeFalse();
67+
}
68+
69+
[Fact]
70+
public void IsIdentical_Views()
71+
{
72+
var results = new SqlDatabaseComparisonResults()
73+
{
74+
StoredProcedures = new ReadOnlyCollection<SqlObjectDifferences<SqlStoredProcedure>>([]),
75+
Tables = new ReadOnlyCollection<SqlTableDifferences>([]),
76+
UserTypes = new ReadOnlyCollection<SqlObjectDifferences<SqlUserType>>([]),
77+
Views = new ReadOnlyCollection<SqlObjectDifferences<SqlView>>([null]),
78+
};
79+
80+
results.IsIdentical.Should().BeFalse();
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)