Skip to content

Commit

Permalink
Updated packages but removed FluentAssertions with custom asserts so …
Browse files Browse the repository at this point in the history
…we dont need this now commerial dependency

- Updated .editorconfig with new naming rules and styles for C# and VB.NET files.
- Made minor documentation changes in IDirectoryHelper.cs.
- Corrected a typo in a comment within Result.cs.
- Replaced FluentAssertions with Xunit assertions in multiple test files.
- Improved test method names and readability by using PascalCase and static methods.
  • Loading branch information
Retrodad0001 committed Jan 16, 2025
1 parent e8c2ecf commit 3b0b994
Show file tree
Hide file tree
Showing 15 changed files with 323 additions and 180 deletions.
144 changes: 144 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,147 @@ dotnet_style_coalesce_expression = false

# IDE0079: Remove unnecessary suppression
dotnet_diagnostic.IDE0079.severity = warning

[*.cs]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = warning
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = warning
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = warning
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
csharp_indent_labels = one_less_than_current
csharp_using_directive_placement = outside_namespace:error
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = false:silent
csharp_style_expression_bodied_local_functions = true:silent

# CA1707: Identifiers should not contain underscores
dotnet_diagnostic.CA1707.severity = warning

# IDE0059: Unnecessary assignment of a value
dotnet_diagnostic.IDE0059.severity = warning

[*.vb]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, friend, private, protected, protected_friend, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_coalesce_expression = false:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion
dotnet_style_prefer_conditional_expression_over_return = false:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = false:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
dotnet_style_namespace_match_folder = true:suggestion

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning
14 changes: 7 additions & 7 deletions EasyDbMigrator/EasyDbMigrator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>4.0.1</Version>
<Version>4.0.2</Version>
<PackageId>Retrodad.EasyDbMigrator</PackageId>
<Description>EasyDbMigrator is a database migration framework written in C#. It can be used for integration testing on your local machine or in CI/CD Pipelines or for manual migrations.</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -19,12 +19,12 @@ For help and release info see: https://github.com/Retrodad0001/EasyDbMigrator</P
<PackageIconUrl />
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<Authors>Retrodad0001</Authors>
<AssemblyVersion>4.0.1</AssemblyVersion>
<FileVersion>4.0.1</FileVersion>
<AssemblyVersion>4.0.2</AssemblyVersion>
<FileVersion>4.0.2</FileVersion>
<PackageProjectUrl>https://github.com/Retrodad0001/EasyDbMigrator</PackageProjectUrl>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<PackageVersion>4.0.1</PackageVersion>
<PackageVersion>4.0.2</PackageVersion>
<Title>Retrodad.EasyDbMigrator</Title>
</PropertyGroup>

Expand Down Expand Up @@ -53,10 +53,10 @@ For help and release info see: https://github.com/Retrodad0001/EasyDbMigrator</P
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.1" />
<PackageReference Include="Npgsql" Version="9.0.2" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="Polly" Version="8.5.1" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion EasyDbMigrator/IDirectoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace EasyDbMigrator;

/// <summary>
/// Interface for getting scripts from a directory.
/// Interface for getting scripts from a directory and mocking this stuff out.
/// </summary>
public interface IDirectoryHelper
{
Expand Down
2 changes: 1 addition & 1 deletion EasyDbMigrator/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace EasyDbMigrator;

//TODO when new union types are available in .net than use that instead of this custom Result type
//TODO when new union types are available in .NET than use that instead of this custom Result type
public sealed class Result<T>
{
public bool HasFailure => !WasSuccessful;
Expand Down
13 changes: 6 additions & 7 deletions EasyDbMigratorTests/EasyDbMigratorTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<PackageReference Include="coverlet.msbuild" Version="6.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Dapper" Version="2.1.44" />
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="TestEnvironment.Docker.Containers.Mssql" Version="2.1.8" />
<PackageReference Include="TestEnvironment.Docker.Containers.Postgres" Version="2.1.6" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PackageReference Include="coverlet.collector" Version="6.0.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

using Dapper;
using EasyDbMigratorTests.TestHelpers;
using FluentAssertions;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Text;

using Xunit;

namespace EasyDbMigratorTests.IntegrationTests.Helpers;

Expand All @@ -33,14 +32,21 @@ List<DbMigrationsRunRowSqlServer> expectedRows
FROM DbMigrationsRun")
.ToString());

_ = actual.Should().HaveSameCount(expectedRows);
_ = actual.Should().Contain(expectedRows);
Assert.Equal(expected: expectedRows.Count, actual: actual.Count);

for (int i = 0; i < actual.Count; i++)
{
Assert.Equal(expectedRows[i].Id, actual[i].Id);
Assert.Equal(expectedRows[i].Executed, actual[i].Executed);
Assert.Equal(expectedRows[i].Filename, actual[i].Filename);
Assert.Equal(expectedRows[i].Version, actual[i].Version);
}

return true;
}

public static bool CheckMigrationsTablePostgresSever(string connectionString,
List<DbMigrationsRunRowPostgresServer> expectedRows)
List<DbMigrationsRunRowPostgresServer> expectedRows)
{
using NpgsqlConnection connection = new(connectionString);
connection.Open();
Expand All @@ -51,15 +57,21 @@ public static bool CheckMigrationsTablePostgresSever(string connectionString,
FROM DbMigrationsRun")
.ToString());

_ = actual.Should().HaveSameCount(expectedRows);
_ = actual.Should().Contain(expectedRows);
Assert.Equal(expected: expectedRows.Count, actual: actual.Count);

for (int i = 0; i < actual.Count; i++)
{
Assert.Equal(expectedRows[i].Id, actual[i].Id);
Assert.Equal(expectedRows[i].Executed, actual[i].Executed);
Assert.Equal(expectedRows[i].Filename, actual[i].Filename);
Assert.Equal(expectedRows[i].Version, actual[i].Version);
}

return true;
}

public static string GenerateRandomDatabaseName()
{
// string result = Guid.NewGuid().ToString().Replace("-", "");
string result = new StringBuilder().Append("test").Append(new Random().Next(100000, 999999)).ToString();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using EasyDbMigratorTests.IntegrationTests.Helpers;
using EasyDbMigratorTests.TestHelpers;
using ExampleTestLibWithPostGreSQLServerScripts;
using FluentAssertions;
using Microsoft.Extensions.Logging;
using Moq;
using System;
Expand All @@ -26,7 +25,7 @@ public class PostgresServerIntegrationTests
{
[Fact]
[Trait("Category", "IntegrationTest")]
public async Task When_nothing_goes_wrong_with_running_all_postgres_migrations_on_an_empty_database()
public async Task WhenNothingGoesWrongWithRunningAllPostgresMigrationsOnAnEmptyDatabase()
{
string databaseName = IntegrationTestHelper.GenerateRandomDatabaseName();
DockerEnvironment? dockerPostgresServerEnvironment = SetupPostgresServerTestEnvironment(databaseName);
Expand Down Expand Up @@ -61,14 +60,14 @@ public async Task When_nothing_goes_wrong_with_running_all_postgres_migrations_o

bool succeededDeleteDatabase = await migrator.TryDeleteDatabaseIfExistAsync(config
, CancellationToken.None);
_ = succeededDeleteDatabase.Should().BeTrue();
Assert.True(succeededDeleteDatabase);

Type? type = typeof(HereThePostgreSQLServerScriptsCanBeFound);

bool succeededRunningMigrations = await migrator.TryApplyMigrationsAsync(type
, config
, CancellationToken.None);
_ = succeededRunningMigrations.Should().BeTrue();
Assert.True(succeededRunningMigrations);

_ = loggerMock
.CheckIfLoggerWasCalled("DeleteDatabaseIfExistAsync has executed", LogLevel.Information, Times.Exactly(1), false)
Expand Down Expand Up @@ -99,7 +98,7 @@ public async Task When_nothing_goes_wrong_with_running_all_postgres_migrations_o

[Fact]
[Trait("Category", "IntegrationTest")]
public async Task Can_skip_postgres_scripts_if_they_already_run_before()
public async Task CanSkipPostgresScriptsIfTheyAlreadyRunBefore()
{
string databaseName = IntegrationTestHelper.GenerateRandomDatabaseName();
DockerEnvironment? dockerPostgresServerEnvironment = SetupPostgresServerTestEnvironment(databaseName);
Expand Down Expand Up @@ -133,14 +132,14 @@ public async Task Can_skip_postgres_scripts_if_they_already_run_before()

bool succeededDeleteDatabase = await migrator1.TryDeleteDatabaseIfExistAsync(config
, CancellationToken.None);
_ = succeededDeleteDatabase.Should().BeTrue();
Assert.True(succeededDeleteDatabase);

Type? type = typeof(HereThePostgreSQLServerScriptsCanBeFound);

bool succeededRunningMigrations = await migrator1.TryApplyMigrationsAsync(type
, config
, CancellationToken.None);
_ = succeededRunningMigrations.Should().BeTrue();
Assert.True(succeededRunningMigrations);

// now run the migrations again
var loggerMockSecondRun = new Mock<ILogger<DbMigrator>>();
Expand All @@ -159,7 +158,7 @@ public async Task Can_skip_postgres_scripts_if_they_already_run_before()
bool succeeded = await migrator2.TryApplyMigrationsAsync(type
, config
, CancellationToken.None);
_ = succeeded.Should().BeTrue();
Assert.True(succeeded);

_ = loggerMockSecondRun
.CheckIfLoggerWasCalled("setup database executed successfully", LogLevel.Information, Times.Exactly(1), false)
Expand Down Expand Up @@ -191,7 +190,7 @@ public async Task Can_skip_postgres_scripts_if_they_already_run_before()

[Fact]
[Trait("Category", "IntegrationTest")]
public async Task Can_cancel_the_postgres_migration_process()
public async Task CanCancelThePostgresMigrationProcess()
{
string databaseName = IntegrationTestHelper.GenerateRandomDatabaseName();
DockerEnvironment? dockerPostgresServerEnvironment = SetupPostgresServerTestEnvironment(databaseName);
Expand Down Expand Up @@ -226,7 +225,7 @@ public async Task Can_cancel_the_postgres_migration_process()

bool succeededDeleteDatabase = await migrator.TryDeleteDatabaseIfExistAsync(config
, token);
_ = succeededDeleteDatabase.Should().BeTrue();
Assert.True(succeededDeleteDatabase);

Type? type = typeof(HereThePostgreSQLServerScriptsCanBeFound);

Expand All @@ -235,7 +234,7 @@ public async Task Can_cancel_the_postgres_migration_process()
bool succeededRunningMigrations = await migrator.TryApplyMigrationsAsync(type
, config
, token);
_ = succeededRunningMigrations.Should().BeTrue();
Assert.True(succeededRunningMigrations);

_ = loggerMock
.CheckIfLoggerWasCalled("migration process was canceled from the outside", LogLevel.Warning, Times.Exactly(1), false);
Expand Down
Loading

0 comments on commit 3b0b994

Please sign in to comment.