Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
587 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace SIM.Base.FileSystem | ||
{ | ||
using JetBrains.Annotations; | ||
using System.IO; | ||
|
||
public sealed class FilePath | ||
{ | ||
[NotNull] | ||
public string FullName { get; } | ||
|
||
public FilePath([NotNull] string fullname) | ||
{ | ||
FullName = Path.GetFullPath(fullname); | ||
} | ||
|
||
[NotNull] | ||
public string Extension => Path.GetExtension(FullName); | ||
|
||
[NotNull] | ||
public static implicit operator string([NotNull] FilePath filePath) | ||
{ | ||
return filePath.FullName; | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
return FullName; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace SIM.Base.Services | ||
{ | ||
using JetBrains.Annotations; | ||
|
||
public abstract class ConnectionString | ||
{ | ||
[NotNull] | ||
public string Value { get; } | ||
|
||
protected ConnectionString([NotNull] string value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
[NotNull] | ||
public static implicit operator string([NotNull] ConnectionString connectionString) | ||
{ | ||
return connectionString.Value; | ||
} | ||
} | ||
} |
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,17 @@ | ||
namespace SIM.Base.Services | ||
{ | ||
using System.Data.SqlClient; | ||
using JetBrains.Annotations; | ||
|
||
public sealed class SqlConnectionString : ConnectionString | ||
{ | ||
[NotNull] | ||
public SqlConnectionStringBuilder Builder { get; } | ||
|
||
public SqlConnectionString([NotNull] string value) | ||
: base(value) | ||
{ | ||
Builder = new SqlConnectionStringBuilder(value); | ||
} | ||
} | ||
} |
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
Binary file added
BIN
+3.41 KB
src/SIM.Foundation.SqlAdapter.IntegrationTests/Adapters/SqlAdapter_Database.dacpac
Binary file not shown.
84 changes: 84 additions & 0 deletions
84
src/SIM.Foundation.SqlAdapter.IntegrationTests/Adapters/SqlAdapter_Tests.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,84 @@ | ||
namespace SIM.Adapters | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using SIM.Base.Services; | ||
using SIM.IO.Real; | ||
|
||
[TestClass] | ||
public class SqlAdapter_Tests | ||
{ | ||
private const string DefaultEnvSqlPath = @"C:\Sitecore\etc\sim2\env\default\SqlServer.txt"; | ||
|
||
[NotNull] | ||
private SqlAdapter Adapter { get; } = new SqlAdapter(new SqlConnectionString(File.ReadAllText(DefaultEnvSqlPath))); | ||
|
||
[TestMethod] | ||
public void DeleteDatabase_MissingDatabase() | ||
{ | ||
Adapter.DeleteDatabase(GetRandomDatabaseName()); | ||
} | ||
|
||
[TestMethod] | ||
public void GetDatabaseFilePath_MissingDatabase() | ||
{ | ||
var databaseName = GetRandomDatabaseName(); | ||
|
||
try | ||
{ | ||
Adapter.GetDatabaseFilePath(databaseName); | ||
} | ||
catch (DatabaseDoesNotExistException ex) | ||
{ | ||
Assert.AreEqual(databaseName, ex.DatabaseName); | ||
Assert.AreEqual($"Failed to perform an operation with SqlServer. The requested '{databaseName}' database does not exist", ex.Message); | ||
|
||
return; | ||
} | ||
|
||
Assert.Fail(); | ||
} | ||
|
||
[TestMethod] | ||
[DeploymentItem("Adapters\\SqlAdapter_Database.dacpac")] | ||
public void Deploy_Check_Delete_Check() | ||
{ | ||
var fileSystem = new RealFileSystem(); | ||
var databaseName = GetRandomDatabaseName(); | ||
var dacpac = fileSystem.ParseFile("SqlAdapter_Database.dacpac"); | ||
Assert.AreEqual(true, dacpac.Exists); | ||
|
||
int count; | ||
try | ||
{ | ||
Adapter.DeployDatabase(databaseName, dacpac); | ||
Assert.AreEqual(true, Adapter.DatabaseExists(databaseName)); | ||
Assert.AreEqual(true, !string.IsNullOrEmpty(Adapter.GetDatabaseFilePath(databaseName))); | ||
|
||
var databases = Adapter.GetDatabases(); | ||
Assert.AreEqual(true, databases.Contains(databaseName)); | ||
|
||
count = databases.Count; | ||
Assert.AreEqual(true, count >= 1); | ||
} | ||
finally | ||
{ | ||
Adapter.DeleteDatabase(databaseName); | ||
} | ||
|
||
Assert.AreEqual(false, Adapter.DatabaseExists(databaseName)); | ||
|
||
var newCount = Adapter.GetDatabases().Count; | ||
Assert.AreEqual(count - 1, newCount); | ||
} | ||
|
||
[NotNull] | ||
private static string GetRandomDatabaseName() | ||
{ | ||
return Guid.NewGuid().ToString("N"); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/SIM.Foundation.SqlAdapter.IntegrationTests/Properties/AssemblyInfo.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,15 @@ | ||
#region Global | ||
|
||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: AssemblyProduct("SIM")] | ||
[assembly: ComVisible(false)] | ||
|
||
[assembly: AssemblyVersion("0.0.0.0")] | ||
[assembly: AssemblyFileVersion("0.0.0.0")] | ||
[assembly: AssemblyInformationalVersion("0.0.0.0")] | ||
|
||
#endregion | ||
|
||
[assembly: AssemblyTitle("SIM.Foundation.SqlAdapter.IntegrationTests")] |
88 changes: 88 additions & 0 deletions
88
....Foundation.SqlAdapter.IntegrationTests/SIM.Foundation.SqlAdapter.IntegrationTests.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,88 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{293D8E00-5C24-4E62-9BF7-4E0FB224D1BA}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>SIM</RootNamespace> | ||
<AssemblyName>SIM.Foundation.SqlAdapter.IntegrationTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath> | ||
<IsCodedUITest>False</IsCodedUITest> | ||
<TestProjectType>UnitTest</TestProjectType> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="JetBrains.Annotations, Version=10.4.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\JetBrains.Annotations.10.4.0\lib\net\JetBrains.Annotations.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\MSTest.TestFramework.1.1.17\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\MSTest.TestFramework.1.1.17\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Adapters\SqlAdapter_Tests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Adapters\SqlAdapter_Database.dacpac"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\SIM.Base\SIM.Base.csproj"> | ||
<Project>{CA9339A0-9A7D-4900-839E-F21B7269BDAA}</Project> | ||
<Name>SIM.Base</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\SIM.FileSystem\SIM.FileSystem.csproj"> | ||
<Project>{02B6C2D7-3083-4DF3-B86D-B6D4728C4EF2}</Project> | ||
<Name>SIM.FileSystem</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\SIM.Foundation.SqlAdapter\SIM.Foundation.SqlAdapter.csproj"> | ||
<Project>{3748B30C-ABF5-4DEE-9F22-74E4F69FFF78}</Project> | ||
<Name>SIM.Foundation.SqlAdapter</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.props'))" /> | ||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets'))" /> | ||
</Target> | ||
<Import Project="..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.17\build\net45\MSTest.TestAdapter.targets')" /> | ||
</Project> |
6 changes: 6 additions & 0 deletions
6
src/SIM.Foundation.SqlAdapter.IntegrationTests/packages.config
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="JetBrains.Annotations" version="10.4.0" targetFramework="net45" /> | ||
<package id="MSTest.TestAdapter" version="1.1.17" targetFramework="net45" /> | ||
<package id="MSTest.TestFramework" version="1.1.17" targetFramework="net45" /> | ||
</packages> |
16 changes: 16 additions & 0 deletions
16
src/SIM.Foundation.SqlAdapter/Adapters/DatabaseDoesNotExistException.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,16 @@ | ||
namespace SIM.Adapters | ||
{ | ||
using JetBrains.Annotations; | ||
|
||
public class DatabaseDoesNotExistException : SqlAdapterException | ||
{ | ||
[NotNull] | ||
public string DatabaseName { get; } | ||
|
||
public DatabaseDoesNotExistException([NotNull] string databaseName) | ||
: base($"The requested '{databaseName}' database does not exist") | ||
{ | ||
DatabaseName = databaseName; | ||
} | ||
} | ||
} |
Oops, something went wrong.