-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the UnitTests.Databases.SqlServer.Dac project.
- Loading branch information
1 parent
e4d9835
commit 75398d0
Showing
13 changed files
with
126 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
<Project> | ||
|
||
<!-- Imports the parent Directory.Build.props if exist --> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
<!-- Imports the parent Directory.Build.props if exist --> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
||
<PropertyGroup> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Nullable>enable</Nullable> | ||
|
||
<PackageIcon>Icon.png</PackageIcon> | ||
<PackageProjectUrl>https://github.com/PosInformatique/PosInformatique.UnitTests.Databases</PackageProjectUrl> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageLicenseExpression>MIT</PackageLicenseExpression> | ||
<PackageReleaseNotes> | ||
1.0.1 | ||
- Fix the documentation | ||
|
||
1.0.0 | ||
- Initial version | ||
</PackageReleaseNotes> | ||
</PropertyGroup> | ||
|
||
<!-- Add the InternalsVisibleToAttribute for the unit tests --> | ||
<ItemGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> | ||
<_Parameter1>$(AssemblyName).Tests</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> | ||
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
<ItemGroup Condition="'$(Configuration)' == 'Debug'"> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> | ||
<_Parameter1>$(AssemblyName).Tests</_Parameter1> | ||
</AssemblyAttribute> | ||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> | ||
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1> | ||
</AssemblyAttribute> | ||
</ItemGroup> | ||
</Project> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions
51
src/UnitTests.Databases.SqlServer.Dac/SqlServerDacDatabaseInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="SqlServerDacDatabaseInitializer.cs" company="P.O.S Informatique"> | ||
// Copyright (c) P.O.S Informatique. All rights reserved. | ||
// </copyright> | ||
//----------------------------------------------------------------------- | ||
|
||
namespace PosInformatique.UnitTests.Databases.SqlServer | ||
{ | ||
using Microsoft.Data.SqlClient; | ||
|
||
/// <summary> | ||
/// Initializer used to initialize the database for the unit tests. | ||
/// Call the <see cref="Initialize(SqlServerDatabaseInitializer, string, string)"/> method to initialize a database from | ||
/// a DACPAC file. | ||
/// </summary> | ||
/// <remarks>The database will be created the call of the <see cref="Initialize(string, string)"/> method. For the next calls | ||
/// the database is preserved but all the data are deleted.</remarks> | ||
public static class SqlServerDacDatabaseInitializer | ||
{ | ||
/// <summary> | ||
/// Initialize a SQL Server database from a DACPAC file. | ||
/// </summary> | ||
/// <param name="initializer"><see cref="SqlServerDatabaseInitializer"/> which the initialization will be perform on.</param> | ||
/// <param name="packageName">Full path of the DACPAC file.</param> | ||
/// <param name="connectionString">Connection string to the SQL Server with administrator rights.</param> | ||
/// <returns>An instance of the <see cref="SqlServerDatabase"/> which allows to perform query to initialize the data.</returns> | ||
public static SqlServerDatabase Initialize(this SqlServerDatabaseInitializer initializer, string packageName, string connectionString) | ||
{ | ||
var connectionStringBuilder = new SqlConnectionStringBuilder(connectionString); | ||
|
||
var server = new SqlServer(connectionString); | ||
|
||
SqlServerDatabase database; | ||
|
||
if (!initializer.IsInitialized) | ||
{ | ||
database = server.DeployDacPackage(packageName, connectionStringBuilder.InitialCatalog); | ||
|
||
initializer.IsInitialized = true; | ||
} | ||
else | ||
{ | ||
database = server.GetDatabase(connectionStringBuilder.InitialCatalog); | ||
} | ||
|
||
database.ClearAllData(); | ||
|
||
return database; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/UnitTests.Databases.SqlServer.Dac/UnitTests.Databases.SqlServer.Dac.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<Description>UnitTests.Databases.SqlServer.Dac is a library that contains a set of tools for unit testing to deploy DAC (Data-tier Applications) packages (.dacpac files).</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="..\..\README.md" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="Icon.png" Pack="true" PackagePath="" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.SqlServer.DacFx" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\UnitTests.Databases.SqlServer\UnitTests.Databases.SqlServer.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters