diff --git a/.github/workflows/github-actions-ci.yaml b/.github/workflows/github-actions-ci.yaml index dad5f40..05471de 100644 --- a/.github/workflows/github-actions-ci.yaml +++ b/.github/workflows/github-actions-ci.yaml @@ -23,26 +23,28 @@ jobs: volumes: - /tmp/other_databases_path:/tmp/other_databases_path steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Setup .NET - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v6 with: - dotnet-version: 8.0.x + dotnet-version: 11.0.x - name: Restore dependencies - run: dotnet restore PosInformatique.Testing.Databases.sln + run: dotnet restore PosInformatique.Testing.Databases.slnx - name: Build solution - run: dotnet build PosInformatique.Testing.Databases.sln --configuration Release --no-restore + run: dotnet build PosInformatique.Testing.Databases.slnx --configuration Release --no-restore - name: Install SQL Server command-line tools run: | - curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - - curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list + set -o pipefail + . /etc/os-release + curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/microsoft-prod.gpg + curl -fsSL "https://packages.microsoft.com/config/ubuntu/${VERSION_ID}/prod.list" | sudo tee /etc/apt/sources.list.d/msprod.list > /dev/null sudo apt-get update - sudo apt-get install -y mssql-tools - echo "/opt/mssql-tools/bin" >> $GITHUB_PATH + sudo ACCEPT_EULA=Y apt-get install -y mssql-tools18 + echo "/opt/mssql-tools18/bin" >> "$GITHUB_PATH" - name: Prepare SQL databases directory run: | @@ -51,10 +53,13 @@ jobs: - name: Run tests run: | - dotnet test PosInformatique.Testing.Databases.sln \ + dotnet test PosInformatique.Testing.Databases.slnx \ --configuration Release \ --no-build \ - --logger "trx;LogFileName=test_results.trx" \ + --coverage \ + --coverage-output-format cobertura \ + --coverage-settings CodeCoverage.runsettings \ + --report-trx \ --results-directory ./TestResults env: SQL_SERVER_UNIT_TESTS_CONNECTION_STRING: "Data Source=localhost,1433;Database=master;User Id=sa;Password=P@ssw0rd12345!;TrustServerCertificate=True;" @@ -70,16 +75,16 @@ jobs: build-samples: runs-on: windows-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Setup NuGet - uses: nuget/setup-nuget@v2 + uses: nuget/setup-nuget@v4 - name: Restore NuGet packages of the samples - run: nuget restore samples/PosInformatique.Testing.Databases.Samples.sln + run: nuget restore samples/PosInformatique.Testing.Databases.Samples.slnx - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + uses: microsoft/setup-msbuild@v3 - name: Build samples with Visual Studio - run: msbuild "samples/PosInformatique.Testing.Databases.Samples.sln" /p:Configuration=Debug + run: msbuild "samples/PosInformatique.Testing.Databases.Samples.slnx" /p:Configuration=Debug diff --git a/.github/workflows/github-actions-release.yml b/.github/workflows/github-actions-release.yaml similarity index 78% rename from .github/workflows/github-actions-release.yml rename to .github/workflows/github-actions-release.yaml index a3a1959..26a51b2 100644 --- a/.github/workflows/github-actions-release.yml +++ b/.github/workflows/github-actions-release.yaml @@ -7,7 +7,7 @@ on: type: string description: The version of the library required: true - default: 3.0.0 + default: 4.0.0 VersionSuffix: type: string description: The version suffix of the library (for example rc.1) @@ -17,13 +17,16 @@ run-name: ${{ inputs.VersionSuffix && format('{0}-{1}', inputs.VersionPrefix, in jobs: build: runs-on: ubuntu-latest + permissions: + id-token: write + contents: read steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v7 - name: Setup .NET 8.x - uses: actions/setup-dotnet@v4 + uses: actions/setup-dotnet@v6 with: - dotnet-version: '8.x' + dotnet-version: '11.x' - name: Build Testing.Databases.SqlServer run: dotnet pack @@ -53,5 +56,15 @@ jobs: --property:VersionSuffix=${{ github.event.inputs.VersionSuffix }} "src/Testing.Databases.SqlServer.SqlCmd/Testing.Databases.SqlServer.SqlCmd.csproj" + - name: NuGet login + uses: NuGet/login@v1 + id: nuget_login + with: + user: ${{ secrets.NUGET_USER }} + - name: Publish the package to nuget.org - run: dotnet nuget push "src/**/bin/Release/*.nupkg" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + run: | + dotnet nuget push "src/**/bin/Release/*.nupkg" \ + --api-key "${{steps.nuget_login.outputs.NUGET_API_KEY}}" \ + --source https://api.nuget.org/v3/index.json \ + --skip-duplicate diff --git a/CodeCoverage.runsettings b/CodeCoverage.runsettings index 0f42dd3..a40942c 100644 --- a/CodeCoverage.runsettings +++ b/CodeCoverage.runsettings @@ -1,5 +1,4 @@ - diff --git a/Directory.Packages.props b/Directory.Packages.props index f3d984f..c89a738 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,16 +3,17 @@ true - - - - - - - + + + + + + - - - + + + + + \ No newline at end of file diff --git a/PosInformatique.Testing.Databases.sln b/PosInformatique.Testing.Databases.sln deleted file mode 100644 index c19db51..0000000 --- a/PosInformatique.Testing.Databases.sln +++ /dev/null @@ -1,151 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.10.35201.131 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BFE7322A-DFBA-4CE1-A3D8-7EBB4CD6F586}" - ProjectSection(SolutionItems) = preProject - .editorconfig = .editorconfig - .gitignore = .gitignore - CodeCoverage.runsettings = CodeCoverage.runsettings - Directory.Build.props = Directory.Build.props - Directory.Packages.props = Directory.Packages.props - LICENSE = LICENSE - README.md = README.md - stylecop.json = stylecop.json - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer", "src\Testing.Databases.SqlServer\Testing.Databases.SqlServer.csproj", "{4CE1DA94-B254-45D3-8014-EB8055E38A01}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1E437195-1225-443D-BD19-8796F31B1E2B}" - ProjectSection(SolutionItems) = preProject - tests\.editorconfig = tests\.editorconfig - tests\Directory.Build.props = tests\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.Tests", "tests\Testing.Databases.SqlServer.Tests\Testing.Databases.SqlServer.Tests.csproj", "{C87E8F0D-D96D-4D77-9713-5564DC2E3597}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{49103176-7D08-4386-B445-76E9823503F8}" - ProjectSection(SolutionItems) = preProject - src\.editorconfig = src\.editorconfig - src\Directory.Build.props = src\Directory.Build.props - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.Tests.DacPac", "tests\Testing.Databases.SqlServer.Tests.DacPac\Testing.Databases.SqlServer.Tests.DacPac.csproj", "{5F618225-0E1C-46A7-BBCC-23A6243D5CEE}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{91BFD2B1-6AB6-4B07-9D2E-430C93F150D4}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{F8700AE9-9613-4CFE-B870-FAD786607D53}" - ProjectSection(SolutionItems) = preProject - .github\workflows\github-actions-ci.yaml = .github\workflows\github-actions-ci.yaml - .github\workflows\github-actions-release.yml = .github\workflows\github-actions-release.yml - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.Tests.Source", "tests\Testing.Databases.SqlServer.Tests.Source\Testing.Databases.SqlServer.Tests.Source.csproj", "{A261D4FF-9BEA-475C-8671-E9BACFDCE960}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.Tests.Target", "tests\Testing.Databases.SqlServer.Tests.Target\Testing.Databases.SqlServer.Tests.Target.csproj", "{6CD3F177-053F-4816-A37E-5CA6F293D34C}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.EntityFramework", "src\Testing.Databases.SqlServer.EntityFramework\Testing.Databases.SqlServer.EntityFramework.csproj", "{157DDF0D-9410-4646-94B9-9CEE4C140F5E}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.EntityFramework.Tests", "tests\Testing.Databases.SqlServer.EntityFramework.Tests\Testing.Databases.SqlServer.EntityFramework.Tests.csproj", "{04A7AE8F-FE77-435B-9250-600388BB8065}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{8500A9B6-CAA0-432C-BABB-DDC86CE08994}" - ProjectSection(SolutionItems) = preProject - docs\WriteDatabaseMigrationTest.md = docs\WriteDatabaseMigrationTest.md - docs\WriteTest.md = docs\WriteTest.md - EndProjectSection -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Testing.Databases.SqlServer.Dac", "src\Testing.Databases.SqlServer.Dac\Testing.Databases.SqlServer.Dac.csproj", "{8BE60460-EBA5-43DE-B85D-C756E2988DC8}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing.Databases.SqlServer.Dac.Tests", "tests\Testing.Databases.SqlServer.Dac.Tests\Testing.Databases.SqlServer.Dac.Tests.csproj", "{6751A585-1BB0-49A1-BF68-D7FBD3392DF6}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing.Databases.SqlServer.SqlCmd", "src\Testing.Databases.SqlServer.SqlCmd\Testing.Databases.SqlServer.SqlCmd.csproj", "{D3004122-CCDD-4EAD-BD9E-DA6DFF470943}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Testing.Databases.SqlServer.SqlCmd.Tests", "tests\Testing.Databases.SqlServer.SqlCmd.Tests\Testing.Databases.SqlServer.SqlCmd.Tests.csproj", "{F8E025D7-4E2F-437A-ABFA-C43A1368E15A}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Testing.Databases.SqlServer.Shared", "src\Testing.Databases.SqlServer.Shared\Testing.Databases.SqlServer.Shared.shproj", "{B9F8C52D-4652-4FC6-A695-DC2F61BA05C9}" -EndProject -Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Testing.Databases.SqlServer.Shared.Tests", "tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.shproj", "{1554EA1B-37C8-4F10-9770-BF4DD8A7E80C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {4CE1DA94-B254-45D3-8014-EB8055E38A01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4CE1DA94-B254-45D3-8014-EB8055E38A01}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4CE1DA94-B254-45D3-8014-EB8055E38A01}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4CE1DA94-B254-45D3-8014-EB8055E38A01}.Release|Any CPU.Build.0 = Release|Any CPU - {C87E8F0D-D96D-4D77-9713-5564DC2E3597}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C87E8F0D-D96D-4D77-9713-5564DC2E3597}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C87E8F0D-D96D-4D77-9713-5564DC2E3597}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C87E8F0D-D96D-4D77-9713-5564DC2E3597}.Release|Any CPU.Build.0 = Release|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Release|Any CPU.Build.0 = Release|Any CPU - {5F618225-0E1C-46A7-BBCC-23A6243D5CEE}.Release|Any CPU.Deploy.0 = Release|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Release|Any CPU.Build.0 = Release|Any CPU - {A261D4FF-9BEA-475C-8671-E9BACFDCE960}.Release|Any CPU.Deploy.0 = Release|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Release|Any CPU.Build.0 = Release|Any CPU - {6CD3F177-053F-4816-A37E-5CA6F293D34C}.Release|Any CPU.Deploy.0 = Release|Any CPU - {157DDF0D-9410-4646-94B9-9CEE4C140F5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {157DDF0D-9410-4646-94B9-9CEE4C140F5E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {157DDF0D-9410-4646-94B9-9CEE4C140F5E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {157DDF0D-9410-4646-94B9-9CEE4C140F5E}.Release|Any CPU.Build.0 = Release|Any CPU - {04A7AE8F-FE77-435B-9250-600388BB8065}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {04A7AE8F-FE77-435B-9250-600388BB8065}.Debug|Any CPU.Build.0 = Debug|Any CPU - {04A7AE8F-FE77-435B-9250-600388BB8065}.Release|Any CPU.ActiveCfg = Release|Any CPU - {04A7AE8F-FE77-435B-9250-600388BB8065}.Release|Any CPU.Build.0 = Release|Any CPU - {8BE60460-EBA5-43DE-B85D-C756E2988DC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8BE60460-EBA5-43DE-B85D-C756E2988DC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8BE60460-EBA5-43DE-B85D-C756E2988DC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8BE60460-EBA5-43DE-B85D-C756E2988DC8}.Release|Any CPU.Build.0 = Release|Any CPU - {6751A585-1BB0-49A1-BF68-D7FBD3392DF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6751A585-1BB0-49A1-BF68-D7FBD3392DF6}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6751A585-1BB0-49A1-BF68-D7FBD3392DF6}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6751A585-1BB0-49A1-BF68-D7FBD3392DF6}.Release|Any CPU.Build.0 = Release|Any CPU - {D3004122-CCDD-4EAD-BD9E-DA6DFF470943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D3004122-CCDD-4EAD-BD9E-DA6DFF470943}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D3004122-CCDD-4EAD-BD9E-DA6DFF470943}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D3004122-CCDD-4EAD-BD9E-DA6DFF470943}.Release|Any CPU.Build.0 = Release|Any CPU - {F8E025D7-4E2F-437A-ABFA-C43A1368E15A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F8E025D7-4E2F-437A-ABFA-C43A1368E15A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F8E025D7-4E2F-437A-ABFA-C43A1368E15A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F8E025D7-4E2F-437A-ABFA-C43A1368E15A}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {1E437195-1225-443D-BD19-8796F31B1E2B} = {BFE7322A-DFBA-4CE1-A3D8-7EBB4CD6F586} - {49103176-7D08-4386-B445-76E9823503F8} = {BFE7322A-DFBA-4CE1-A3D8-7EBB4CD6F586} - {91BFD2B1-6AB6-4B07-9D2E-430C93F150D4} = {BFE7322A-DFBA-4CE1-A3D8-7EBB4CD6F586} - {F8700AE9-9613-4CFE-B870-FAD786607D53} = {91BFD2B1-6AB6-4B07-9D2E-430C93F150D4} - {8500A9B6-CAA0-432C-BABB-DDC86CE08994} = {BFE7322A-DFBA-4CE1-A3D8-7EBB4CD6F586} - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {FAC64573-D665-48A8-AC75-7B82B692EC9E} - EndGlobalSection - GlobalSection(SharedMSBuildProjectFiles) = preSolution - tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.projitems*{04a7ae8f-fe77-435b-9250-600388bb8065}*SharedItemsImports = 5 - tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.projitems*{1554ea1b-37c8-4f10-9770-bf4dd8a7e80c}*SharedItemsImports = 13 - src\Testing.Databases.SqlServer.Shared\Testing.Databases.SqlServer.Shared.projitems*{157ddf0d-9410-4646-94b9-9cee4c140f5e}*SharedItemsImports = 5 - tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.projitems*{6751a585-1bb0-49a1-bf68-d7fbd3392df6}*SharedItemsImports = 5 - src\Testing.Databases.SqlServer.Shared\Testing.Databases.SqlServer.Shared.projitems*{8be60460-eba5-43de-b85d-c756e2988dc8}*SharedItemsImports = 5 - src\Testing.Databases.SqlServer.Shared\Testing.Databases.SqlServer.Shared.projitems*{b9f8c52d-4652-4fc6-a695-dc2f61ba05c9}*SharedItemsImports = 13 - tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.projitems*{c87e8f0d-d96d-4d77-9713-5564dc2e3597}*SharedItemsImports = 5 - src\Testing.Databases.SqlServer.Shared\Testing.Databases.SqlServer.Shared.projitems*{d3004122-ccdd-4ead-bd9e-da6dff470943}*SharedItemsImports = 5 - tests\Testing.Databases.SqlServer.Shared.Tests\Testing.Databases.SqlServer.Shared.Tests.projitems*{f8e025d7-4e2f-437a-abfa-c43a1368e15a}*SharedItemsImports = 5 - EndGlobalSection -EndGlobal diff --git a/PosInformatique.Testing.Databases.slnx b/PosInformatique.Testing.Databases.slnx new file mode 100644 index 0000000..70b1615 --- /dev/null +++ b/PosInformatique.Testing.Databases.slnx @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index 4b9ed3a..b211e90 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Before each test (`TestMethod` or `Fact` methods): 4. Assert the results of the executed code. - - If the tested method returns data (performs a SELECT query), assert the returned objects using your favorite assertion framework (e.g., FluentAssertions). + - If the tested method returns data (performs a SELECT query), assert the returned objects using your favorite assertion framework (e.g., AwesomeAssertions). - If the method inserts, updates, or deletes data, assert the content of the tables to check that all data is stored correctly. To write a test using this approach with the [PosInformatique.Testing.Databases](https://github.com/PosInformatique/PosInformatique.Testing.Databases) tools, see the [ Write tests to test the persistence layer](./docs/WriteTest.md) page. @@ -130,7 +130,7 @@ The [PosInformatique.Testing.Databases](https://github.com/PosInformatique/PosIn - [PosInformatique.Testing.Databases.SqlServer.SqlCmd](https://www.nuget.org/packages/PosInformatique.Testing.Databases.SqlServer.SqlCmd) NuGet package which contains: - Tools to execute T-SQL script using the SQL Server [sqlcmd utility](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility). This script can be use to deploy a - SQL Server database. + SQL Server database. The connection string's `TrustServerCertificate` option is forwarded to `sqlcmd` as `-C`. ## 🚀 Samples / Demo @@ -177,28 +177,23 @@ For Entity Framework migration: ## 📦 NuGet package dependency versions These tools rely on a minimal set of NuGet dependencies to ensure broad compatibility. -They are built for **.NET Core 6.0** and **.NET Framework 4.6.2** but also work seamlessly with newer versions of .NET: - -- .NET Framework 4.6.2 -- .NET Framework 4.7 -- .NET Framework 4.7.1 -- .NET Framework 4.7.2 -- .NET Framework 4.8 -- .NET Framework 4.8.1 -- .NET Core 6.0 -- .NET Core 7.0 -- .NET Core 8.0 -- .NET Core 9.0 -- .NET Core 10.0 +The library is now compatible with **.NET 8.0 and later versions**, including **Entity Framework Core 8.0 and later**: + +- .NET 8.0 +- .NET 9.0 +- .NET 10.0 +- .NET 11.0 + +The `Dac` and `SqlCmd` packages also provide a target for .NET Framework 4.6.2. ### Dependency versions All NuGet packages depend on **low baseline versions** of Microsoft libraries to remain compatible with any modern version: -- [Microsoft.Data.SqlClient](https://www.nuget.org/packages/microsoft.data.sqlclient) >= 5.0.1 -- [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/microsoft.entityframeworkcore) >= 6.0.0 -- [Microsoft.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/microsoft.entityframeworkcore.sqlserver) >= 6.0.0 -- [Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/microsoft.entityframeworkcore.tools) >= 6.0.0 +- [Microsoft.Data.SqlClient](https://www.nuget.org/packages/microsoft.data.sqlclient) >= 5.1.3 +- [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/microsoft.entityframeworkcore) >= 8.0.0 +- [Microsoft.EntityFrameworkCore.SqlServer](https://www.nuget.org/packages/microsoft.entityframeworkcore.sqlserver) >= 8.0.0 +- [Microsoft.EntityFrameworkCore.Tools](https://www.nuget.org/packages/microsoft.entityframeworkcore.tools) >= 8.0.0 - [Microsoft.SqlServer.DacFx](https://www.nuget.org/packages/microsoft.sqlserver.dacfx) >= 162.1.172 ### Recommendation diff --git a/docs/WriteDatabaseMigrationTest.md b/docs/WriteDatabaseMigrationTest.md index 7e17d6a..e555e5e 100644 --- a/docs/WriteDatabaseMigrationTest.md +++ b/docs/WriteDatabaseMigrationTest.md @@ -1,5 +1,7 @@ # Write tests to test database migration +> **Requirement:** The library supports **.NET 8.0 and later versions**, including Entity Framework Core 8.0 and later. + This section explain how to write an test to test the database migration. The code samples used here can be found in the [PosInformatique.Testing.Databases.Samples](../samples/PosInformatique.Testing.Databases.Samples.sln) solution inside the `samples` directory of the repository. @@ -123,7 +125,7 @@ The `IsIdentical` allows to determine if there is the database have the same sch Instead of querying recursively the difference between the two database using the `SqlDatabaseComparisonResults`, the `ToString()` method can be and contains a detailed report of the difference. This why in the previous code, we use in a `because` parameter of the -FluentAssertions `BeTrue()` assertion, to display the detailed report when the test has been failed. +AwesomeAssertions `BeTrue()` assertion, to display the detailed report when the test has been failed. ### Check the report details of the `SqlServerDatabaseComparer` tool. diff --git a/docs/WriteTest.md b/docs/WriteTest.md index 1be28db..c795033 100644 --- a/docs/WriteTest.md +++ b/docs/WriteTest.md @@ -1,5 +1,7 @@ # Write tests to test the persistence layer +> **Requirement:** The library supports **.NET 8.0 and later versions**, including Entity Framework Core 8.0 and later. + This section explain how to write the tests to test a persistence layer. The code samples used here can be found in the [PosInformatique.Testing.Databases.Samples](../samples/PosInformatique.Testing.Databases.Samples.sln) solution inside the `samples` directory of the repository. diff --git a/global.json b/global.json new file mode 100644 index 0000000..69536af --- /dev/null +++ b/global.json @@ -0,0 +1,8 @@ +{ + "sdk": { + "version": "11.0.100" + }, + "test": { + "runner": "Microsoft.Testing.Platform" + } +} diff --git a/samples/DemoApp.DataAccessLayer.Migrations.Tests/DatabaseMigrationTest.cs b/samples/DemoApp.DataAccessLayer.Migrations.Tests/DatabaseMigrationTest.cs index bb05aa4..796cb30 100644 --- a/samples/DemoApp.DataAccessLayer.Migrations.Tests/DatabaseMigrationTest.cs +++ b/samples/DemoApp.DataAccessLayer.Migrations.Tests/DatabaseMigrationTest.cs @@ -6,7 +6,7 @@ namespace PosInformatique.DemoApp.DataAccessLayer.Migrations.Tests { - using FluentAssertions; + using AwesomeAssertions; using Microsoft.EntityFrameworkCore; using PosInformatique.Testing.Databases; using PosInformatique.Testing.Databases.SqlServer; @@ -51,7 +51,7 @@ public async Task MigrationWithConsoleApp() }, }; - var differences = await SqlServerDatabaseComparer.CompareAsync(initialDatabase.Result, targetDatabase.Result, comparerOptions); + var differences = await SqlServerDatabaseComparer.CompareAsync(initialDatabase.Result, targetDatabase.Result, comparerOptions, TestContext.Current.CancellationToken); differences.IsIdentical.Should().BeTrue(differences.ToString()); } diff --git a/samples/DemoApp.DataAccessLayer.Migrations.Tests/DemoApp.DataAccessLayer.Migrations.Tests.csproj b/samples/DemoApp.DataAccessLayer.Migrations.Tests/DemoApp.DataAccessLayer.Migrations.Tests.csproj index 88e4e6d..ba76647 100644 --- a/samples/DemoApp.DataAccessLayer.Migrations.Tests/DemoApp.DataAccessLayer.Migrations.Tests.csproj +++ b/samples/DemoApp.DataAccessLayer.Migrations.Tests/DemoApp.DataAccessLayer.Migrations.Tests.csproj @@ -2,6 +2,7 @@ net8.0 + Exe enable enable @@ -10,18 +11,10 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/DemoApp.DataAccessLayer.Tests/CustomerRepositoryTest.cs b/samples/DemoApp.DataAccessLayer.Tests/CustomerRepositoryTest.cs index 7838f51..66777f9 100644 --- a/samples/DemoApp.DataAccessLayer.Tests/CustomerRepositoryTest.cs +++ b/samples/DemoApp.DataAccessLayer.Tests/CustomerRepositoryTest.cs @@ -6,7 +6,7 @@ namespace PosInformatique.DemoApp.DataAccessLayer.Tests { - using FluentAssertions; + using AwesomeAssertions; using PosInformatique.Testing.Databases.SqlServer; [Collection(DatabaseName)] diff --git a/samples/DemoApp.DataAccessLayer.Tests/DemoApp.DataAccessLayer.Tests.csproj b/samples/DemoApp.DataAccessLayer.Tests/DemoApp.DataAccessLayer.Tests.csproj index f0a6030..93ab16b 100644 --- a/samples/DemoApp.DataAccessLayer.Tests/DemoApp.DataAccessLayer.Tests.csproj +++ b/samples/DemoApp.DataAccessLayer.Tests/DemoApp.DataAccessLayer.Tests.csproj @@ -2,6 +2,7 @@ net8.0 + Exe enable enable @@ -20,18 +21,10 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/samples/Directory.Packages.props b/samples/Directory.Packages.props index c9ab5b4..8f03649 100644 --- a/samples/Directory.Packages.props +++ b/samples/Directory.Packages.props @@ -3,17 +3,15 @@ true - - + + - - + - - + \ No newline at end of file diff --git a/samples/PosInformatique.Testing.Databases.Samples.sln b/samples/PosInformatique.Testing.Databases.Samples.sln deleted file mode 100644 index 558d6d1..0000000 --- a/samples/PosInformatique.Testing.Databases.Samples.sln +++ /dev/null @@ -1,54 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.11.35219.272 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.DataAccessLayer.Tests", "DemoApp.DataAccessLayer.Tests\DemoApp.DataAccessLayer.Tests.csproj", "{2AEE329B-79EB-458B-9DD4-8CB0586AA574}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.DataAccessLayer", "DemoApp.DataAccessLayer\DemoApp.DataAccessLayer.csproj", "{EF2A10ED-4DF2-4648-9EFE-66DA26DF9AA3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.Domain", "DemoApp.Domain\DemoApp.Domain.csproj", "{49175770-6A17-4CB7-B72F-34A0840DF5E1}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.DataAccessLayer.Migrations", "DemoApp.DataAccessLayer.Migrations\DemoApp.DataAccessLayer.Migrations.csproj", "{16B7923A-22A1-4EFC-B574-F016969645D3}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DemoApp.DataAccessLayer.Migrations.Tests", "DemoApp.DataAccessLayer.Migrations.Tests\DemoApp.DataAccessLayer.Migrations.Tests.csproj", "{4F179D8D-B991-4D0D-93BC-FD04F9F0B43B}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{94271813-6C8A-4EA9-939F-5046A1D9D605}" - ProjectSection(SolutionItems) = preProject - Directory.Packages.props = Directory.Packages.props - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2AEE329B-79EB-458B-9DD4-8CB0586AA574}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2AEE329B-79EB-458B-9DD4-8CB0586AA574}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2AEE329B-79EB-458B-9DD4-8CB0586AA574}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2AEE329B-79EB-458B-9DD4-8CB0586AA574}.Release|Any CPU.Build.0 = Release|Any CPU - {EF2A10ED-4DF2-4648-9EFE-66DA26DF9AA3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF2A10ED-4DF2-4648-9EFE-66DA26DF9AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF2A10ED-4DF2-4648-9EFE-66DA26DF9AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF2A10ED-4DF2-4648-9EFE-66DA26DF9AA3}.Release|Any CPU.Build.0 = Release|Any CPU - {49175770-6A17-4CB7-B72F-34A0840DF5E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {49175770-6A17-4CB7-B72F-34A0840DF5E1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {49175770-6A17-4CB7-B72F-34A0840DF5E1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {49175770-6A17-4CB7-B72F-34A0840DF5E1}.Release|Any CPU.Build.0 = Release|Any CPU - {16B7923A-22A1-4EFC-B574-F016969645D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {16B7923A-22A1-4EFC-B574-F016969645D3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {16B7923A-22A1-4EFC-B574-F016969645D3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {16B7923A-22A1-4EFC-B574-F016969645D3}.Release|Any CPU.Build.0 = Release|Any CPU - {4F179D8D-B991-4D0D-93BC-FD04F9F0B43B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {4F179D8D-B991-4D0D-93BC-FD04F9F0B43B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {4F179D8D-B991-4D0D-93BC-FD04F9F0B43B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {4F179D8D-B991-4D0D-93BC-FD04F9F0B43B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {C74616F9-11DB-4DEF-BCAF-CE83CC7D690D} - EndGlobalSection -EndGlobal diff --git a/samples/PosInformatique.Testing.Databases.Samples.slnx b/samples/PosInformatique.Testing.Databases.Samples.slnx new file mode 100644 index 0000000..dd754aa --- /dev/null +++ b/samples/PosInformatique.Testing.Databases.Samples.slnx @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/src/.editorconfig b/src/.editorconfig index 59a276e..3b31f57 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -8,6 +8,9 @@ ### Visual Studio +# IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0060.severity = warning + # IDE0063: Use simple 'using' statement dotnet_diagnostic.IDE0063.severity = none diff --git a/src/Testing.Databases.SqlServer.Dac/Testing.Databases.SqlServer.Dac.csproj b/src/Testing.Databases.SqlServer.Dac/Testing.Databases.SqlServer.Dac.csproj index 4a68d3c..08beb35 100644 --- a/src/Testing.Databases.SqlServer.Dac/Testing.Databases.SqlServer.Dac.csproj +++ b/src/Testing.Databases.SqlServer.Dac/Testing.Databases.SqlServer.Dac.csproj @@ -1,7 +1,7 @@  - net6.0;net462 + net8.0;net462 Testing.Databases.SqlServer.Dac is a library that contains a set of tools for testing to deploy DAC (Data-tier Applications) packages (.dacpac files). testing;unittest;sqlserver;repository;tdd;dataaccesslayer;dacpac;dac diff --git a/src/Testing.Databases.SqlServer.EntityFramework/Testing.Databases.SqlServer.EntityFramework.csproj b/src/Testing.Databases.SqlServer.EntityFramework/Testing.Databases.SqlServer.EntityFramework.csproj index 0e5a336..4e5fcdb 100644 --- a/src/Testing.Databases.SqlServer.EntityFramework/Testing.Databases.SqlServer.EntityFramework.csproj +++ b/src/Testing.Databases.SqlServer.EntityFramework/Testing.Databases.SqlServer.EntityFramework.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 True Testing.Databases.SqlServer.EntityFramework is a library that contains a set of tools for testing Data Access Layer (repositories) based on Entity Framework and SQL Server. diff --git a/src/Testing.Databases.SqlServer.SqlCmd/SqlCmdCommandLineArgumentsBuilder.cs b/src/Testing.Databases.SqlServer.SqlCmd/SqlCmdCommandLineArgumentsBuilder.cs index 0e67e83..4852c35 100644 --- a/src/Testing.Databases.SqlServer.SqlCmd/SqlCmdCommandLineArgumentsBuilder.cs +++ b/src/Testing.Databases.SqlServer.SqlCmd/SqlCmdCommandLineArgumentsBuilder.cs @@ -20,6 +20,7 @@ public SqlCmdCommandLineArgumentsBuilder(SqlConnectionStringBuilder connectionSt this.Password = connectionString.Password; this.Server = connectionString.DataSource; this.TrustedConnection = connectionString.IntegratedSecurity; + this.TrustServerCertificate = connectionString.TrustServerCertificate; this.variables = new Dictionary(); } @@ -36,6 +37,8 @@ public SqlCmdCommandLineArgumentsBuilder(SqlConnectionStringBuilder connectionSt public bool TrustedConnection { get; set; } + public bool TrustServerCertificate { get; set; } + public IReadOnlyDictionary Variables => this.variables; public void AddVariable(string name, string value) @@ -72,6 +75,11 @@ public override string ToString() parameters.Append($"-E "); } + if (this.TrustServerCertificate) + { + parameters.Append($"-C "); + } + if (!string.IsNullOrEmpty(this.Server)) { parameters.Append($"-S \"{this.Server}\" "); diff --git a/src/Testing.Databases.SqlServer.SqlCmd/Testing.Databases.SqlServer.SqlCmd.csproj b/src/Testing.Databases.SqlServer.SqlCmd/Testing.Databases.SqlServer.SqlCmd.csproj index 1a4198c..f0407a8 100644 --- a/src/Testing.Databases.SqlServer.SqlCmd/Testing.Databases.SqlServer.SqlCmd.csproj +++ b/src/Testing.Databases.SqlServer.SqlCmd/Testing.Databases.SqlServer.SqlCmd.csproj @@ -1,7 +1,7 @@  - net6.0;net462 + net8.0;net462 True Testing.Databases.SqlServer.SqlCmd is a library that contains a set of tools for testing Data Access Layer using SQLCMD tool to initialize the database with a SQL script. diff --git a/src/Testing.Databases.SqlServer/SqlServerDatabaseExtensions.cs b/src/Testing.Databases.SqlServer/SqlServerDatabaseExtensions.cs index d70e371..6efdec3 100644 --- a/src/Testing.Databases.SqlServer/SqlServerDatabaseExtensions.cs +++ b/src/Testing.Databases.SqlServer/SqlServerDatabaseExtensions.cs @@ -18,11 +18,13 @@ public static class SqlServerDatabaseExtensions private static readonly Type[] AuthorizedNonStringTypes = [ + typeof(byte), + typeof(byte?), typeof(int), - typeof(double), - typeof(decimal), typeof(int?), + typeof(double), typeof(double?), + typeof(decimal), typeof(decimal?), ]; @@ -165,7 +167,7 @@ public static async Task ExecuteScriptAsync(this SqlServerDatabase database, str { using var stringReader = new StringReader(script); - await ExecuteScriptAsync(database, stringReader); + await ExecuteScriptAsync(database, stringReader, cancellationToken); } /// diff --git a/tests/.editorconfig b/tests/.editorconfig index 3132794..3e5abce 100644 --- a/tests/.editorconfig +++ b/tests/.editorconfig @@ -3,4 +3,9 @@ ### StyleCop # SA1118: Parameter should not span multiple lines -dotnet_diagnostic.SA1118.severity = none \ No newline at end of file +dotnet_diagnostic.SA1118.severity = none + +### Visual Studio + +# IDE0017: Simplify object initialization +dotnet_diagnostic.IDE0017.severity = none \ No newline at end of file diff --git a/tests/Directory.Build.props b/tests/Directory.Build.props index c02c472..cf91965 100644 --- a/tests/Directory.Build.props +++ b/tests/Directory.Build.props @@ -5,19 +5,20 @@ - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + - + diff --git a/tests/Testing.Databases.SqlServer.SqlCmd.Tests/SqlCmdCommandLineArgumentsBuilderTest.cs b/tests/Testing.Databases.SqlServer.SqlCmd.Tests/SqlCmdCommandLineArgumentsBuilderTest.cs index adaed43..e931930 100644 --- a/tests/Testing.Databases.SqlServer.SqlCmd.Tests/SqlCmdCommandLineArgumentsBuilderTest.cs +++ b/tests/Testing.Databases.SqlServer.SqlCmd.Tests/SqlCmdCommandLineArgumentsBuilderTest.cs @@ -18,6 +18,7 @@ public void Constructor() DataSource = "The data source", InitialCatalog = "The initial catalog", IntegratedSecurity = true, + TrustServerCertificate = true, Password = "The password", UserID = "The login", }; @@ -30,6 +31,7 @@ public void Constructor() argumentsBuilder.Password.Should().Be("The password"); argumentsBuilder.Server.Should().Be("The data source"); argumentsBuilder.TrustedConnection.Should().BeTrue(); + argumentsBuilder.TrustServerCertificate.Should().BeTrue(); argumentsBuilder.Variables.Should().BeEmpty(); } @@ -46,6 +48,7 @@ public void Constructor_WithEmptyConnnectionString() argumentsBuilder.Password.Should().BeEmpty(); argumentsBuilder.Server.Should().BeEmpty(); argumentsBuilder.TrustedConnection.Should().BeFalse(); + argumentsBuilder.TrustServerCertificate.Should().BeFalse(); argumentsBuilder.Variables.Should().BeEmpty(); } @@ -121,6 +124,18 @@ public void TrustedConnection_ValueChanged() argumentsBuilder.TrustedConnection.Should().BeTrue(); } + [Fact] + public void TrustServerCertificate_ValueChanged() + { + var connectionString = new SqlConnectionStringBuilder(); + + var argumentsBuilder = new SqlCmdCommandLineArgumentsBuilder(connectionString); + + argumentsBuilder.TrustServerCertificate = true; + + argumentsBuilder.TrustServerCertificate.Should().BeTrue(); + } + [Fact] public void AddVariable() { diff --git a/tests/Testing.Databases.SqlServer.Tests.DacPac/Testing.Databases.SqlServer.Tests.DacPac.csproj b/tests/Testing.Databases.SqlServer.Tests.DacPac/Testing.Databases.SqlServer.Tests.DacPac.csproj index 30ca847..0fc9588 100644 --- a/tests/Testing.Databases.SqlServer.Tests.DacPac/Testing.Databases.SqlServer.Tests.DacPac.csproj +++ b/tests/Testing.Databases.SqlServer.Tests.DacPac/Testing.Databases.SqlServer.Tests.DacPac.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Sql150 @@ -11,11 +11,12 @@ - - - - - + + + + + + diff --git a/tests/Testing.Databases.SqlServer.Tests.Source/Testing.Databases.SqlServer.Tests.Source.csproj b/tests/Testing.Databases.SqlServer.Tests.Source/Testing.Databases.SqlServer.Tests.Source.csproj index 30ca847..0fc9588 100644 --- a/tests/Testing.Databases.SqlServer.Tests.Source/Testing.Databases.SqlServer.Tests.Source.csproj +++ b/tests/Testing.Databases.SqlServer.Tests.Source/Testing.Databases.SqlServer.Tests.Source.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Sql150 @@ -11,11 +11,12 @@ - - - - - + + + + + + diff --git a/tests/Testing.Databases.SqlServer.Tests.Target/Testing.Databases.SqlServer.Tests.Target.csproj b/tests/Testing.Databases.SqlServer.Tests.Target/Testing.Databases.SqlServer.Tests.Target.csproj index c9df446..d889f47 100644 --- a/tests/Testing.Databases.SqlServer.Tests.Target/Testing.Databases.SqlServer.Tests.Target.csproj +++ b/tests/Testing.Databases.SqlServer.Tests.Target/Testing.Databases.SqlServer.Tests.Target.csproj @@ -1,4 +1,4 @@ - + netstandard2.1 Sql150 @@ -11,11 +11,12 @@ - - - - - + + + + + + diff --git a/tests/Testing.Databases.SqlServer.Tests/SqlServerDatabaseExtensionsTest.cs b/tests/Testing.Databases.SqlServer.Tests/SqlServerDatabaseExtensionsTest.cs index 5ca9f01..3020b12 100644 --- a/tests/Testing.Databases.SqlServer.Tests/SqlServerDatabaseExtensionsTest.cs +++ b/tests/Testing.Databases.SqlServer.Tests/SqlServerDatabaseExtensionsTest.cs @@ -26,13 +26,15 @@ Name VARCHAR(50) NOT NULL, Boolean BIT NOT NULL, BooleanNull BIT NULL, Binary VARBINARY(MAX) NULL, + TinyInt TINYINT NOT NULL, + TinyIntNull TINYINT NULL, )"); database.InsertInto( "TableTest", false, - new { Name = "Name 1", Boolean = true, BooleanNull = (bool?)true, Binary = new byte[] { 1, 2 } }, - new { Name = "Name 2", Boolean = false, BooleanNull = (bool?)null, Binary = (byte[])null }); + new { Name = "Name 1", Boolean = true, BooleanNull = (bool?)true, Binary = new byte[] { 1, 2 }, TinyInt = 15, TinyIntNull = (byte?)10 }, + new { Name = "Name 2", Boolean = false, BooleanNull = (bool?)null, Binary = (byte[])null, TinyInt = 30, TinyIntNull = (byte?)null }); var table = database.ExecuteQuery("SELECT * FROM [TableTest] ORDER BY [Id]"); @@ -43,12 +45,16 @@ Binary VARBINARY(MAX) NULL, table.Rows[0]["Binary"].As().Should().Equal([1, 2]); table.Rows[0]["Boolean"].As().Should().Be(true); table.Rows[0]["BooleanNull"].As().Should().Be(true); + table.Rows[0]["TinyInt"].As().Should().Be(15); + table.Rows[0]["TinyIntNull"].As().Should().Be(10); table.Rows[1]["Id"].Should().Be(2); table.Rows[1]["Name"].Should().Be("Name 2"); table.Rows[1]["Binary"].Should().Be(DBNull.Value); table.Rows[1]["Boolean"].As().Should().Be(false); table.Rows[1]["BooleanNull"].Should().Be(DBNull.Value); + table.Rows[1]["TinyInt"].As().Should().Be(30); + table.Rows[1]["TinyIntNull"].Should().Be(DBNull.Value); } [Fact] @@ -61,18 +67,20 @@ public void InsertInto_DisableIdentity() database.ExecuteNonQuery(@" CREATE TABLE TableTest ( - Id INT NOT NULL IDENTITY(1, 1), - Name VARCHAR(50) NOT NULL, - Boolean BIT NOT NULL, - BooleanNull BIT NULL, - Binary VARBINARY(MAX) NULL, + Id INT NOT NULL IDENTITY(1, 1), + Name VARCHAR(50) NOT NULL, + Boolean BIT NOT NULL, + BooleanNull BIT NULL, + Binary VARBINARY(MAX) NULL, + TinyInt TINYINT NOT NULL, + TinyIntNull TINYINT NULL, )"); database.InsertInto( "TableTest", true, - new { Id = 10, Name = "Name 1", Boolean = true, BooleanNull = (bool?)true, Binary = new byte[] { 1, 2 } }, - new { Id = 20, Name = "Name 2", Boolean = false, BooleanNull = (bool?)null, Binary = (byte[])null }); + new { Id = 10, Name = "Name 1", Boolean = true, BooleanNull = (bool?)true, Binary = new byte[] { 1, 2 }, TinyInt = 15, TinyIntNull = (byte?)10 }, + new { Id = 20, Name = "Name 2", Boolean = false, BooleanNull = (bool?)null, Binary = (byte[])null, TinyInt = 30, TinyIntNull = (byte?)null }); var table = database.ExecuteQuery("SELECT * FROM [TableTest] ORDER BY [Id]"); @@ -83,12 +91,16 @@ Binary VARBINARY(MAX) NULL, table.Rows[0]["Binary"].As().Should().Equal([1, 2]); table.Rows[0]["Boolean"].As().Should().Be(true); table.Rows[0]["BooleanNull"].As().Should().Be(true); + table.Rows[0]["TinyInt"].As().Should().Be(15); + table.Rows[0]["TinyIntNull"].As().Should().Be(10); table.Rows[1]["Id"].Should().Be(20); table.Rows[1]["Name"].Should().Be("Name 2"); table.Rows[1]["Binary"].Should().Be(DBNull.Value); table.Rows[1]["Boolean"].As().Should().Be(false); table.Rows[1]["BooleanNull"].Should().Be(DBNull.Value); + table.Rows[1]["TinyInt"].As().Should().Be(30); + table.Rows[1]["TinyIntNull"].Should().Be(DBNull.Value); } [Fact]