Commit 8f8c8a17 authored by CompileNix's avatar CompileNix

add Tests Folder and common integration test helper functions

parent a70d3972
......@@ -21,6 +21,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compilenix.HttpHeaderSurvey
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compilenix.HttpHeaderSurvey.Integration.Shared", "Source\Compilenix.HttpHeaderSurvey.Integration.Shared\Compilenix.HttpHeaderSurvey.Integration.Shared.csproj", "{FF08798B-A665-4687-92A8-23AB2868C9F0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{98F420B1-FD80-4A65-8A2D-059BFCC14FA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compilenix.HttpHeaderSurvey.Tests.Common", "Source\Compilenix.HttpHeaderSurvey.Tests.Common\Compilenix.HttpHeaderSurvey.Tests.Common.csproj", "{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -55,6 +59,10 @@ Global
{FF08798B-A665-4687-92A8-23AB2868C9F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF08798B-A665-4687-92A8-23AB2868C9F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF08798B-A665-4687-92A8-23AB2868C9F0}.Release|Any CPU.Build.0 = Release|Any CPU
{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -66,6 +74,7 @@ Global
{E9ACA8CB-41ED-4168-9742-0471AE8FF6AA} = {CAA6FE71-41D1-453B-BCB5-C1C6CD3A0DFC}
{010FCD06-1FFC-407C-8FB0-68CC6DB24512} = {43273581-1856-48BD-AB37-8BEEE09AEA82}
{FF08798B-A665-4687-92A8-23AB2868C9F0} = {CAA6FE71-41D1-453B-BCB5-C1C6CD3A0DFC}
{04F5C3F9-9D10-4413-8FB1-D2D839863DCF} = {98F420B1-FD80-4A65-8A2D-059BFCC14FA4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8E03FA21-BE17-4484-9BC8-6A7C85CF63D0}
......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.10.1\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04F5C3F9-9D10-4413-8FB1-D2D839863DCF}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Compilenix.HttpHeaderSurvey.Tests.Common</RootNamespace>
<AssemblyName>Compilenix.HttpHeaderSurvey.Tests.Common</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<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="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.10.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DatabaseUtils.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Compilenix.HttpHeaderSurvey.Implementation.DataAccess\Compilenix.HttpHeaderSurvey.Implementation.DataAccess.csproj">
<Project>{0971be82-e8ba-486d-a44b-9c0a8c9ff82f}</Project>
<Name>Compilenix.HttpHeaderSurvey.Implementation.DataAccess</Name>
</ProjectReference>
</ItemGroup>
<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\NUnit.3.10.1\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\NUnit.3.10.1\build\NUnit.props'))" />
</Target>
</Project>
\ No newline at end of file
using System.Data.Entity;
using System.Diagnostics;
using Compilenix.HttpHeaderSurvey.Implementation.DataAccess;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
namespace Compilenix.HttpHeaderSurvey.Tests.Common
{
public class DatabaseUtils
{
private static string _connectionString;
public static bool CleanUpDatabaseOnSucess(string connectionString)
{
if (TestContext.CurrentContext?.Result?.Outcome?.Equals(ResultState.Success) ?? false)
{
RemoveDatabase(connectionString);
return true;
}
return false;
}
public static string GetRandomConnectionString(string dataSource = "localhost")
{
var dbname = $"HttpHeaderSurvey_UnitTest_{new StackTrace().GetFrame(1)?.GetMethod()?.DeclaringType?.Name}_{TestContext.CurrentContext?.Test?.Name}_{TestContext.CurrentContext?.Random?.NextUInt(99)}";
if (dbname.Length >= 128)
{
dbname = $"HttpHeaderSurvey_UnitTest_{TestContext.CurrentContext?.Test?.Name}_{TestContext.CurrentContext?.Random?.NextUInt(99)}";
}
if (dbname.Length >= 128)
{
dbname = $"HttpHeaderSurvey_UnitTest_{TestContext.CurrentContext?.Random?.NextUInt(9999)}";
}
return $"Data Source={dataSource};Initial Catalog={dbname};Integrated Security=True;Encrypt=True;TrustServerCertificate=True;multipleactiveresultsets=True;application name=EntityFramework 6 Unit Testing";
}
public static void RemoveDatabase(string connectionString)
{
Database.Delete(connectionString);
}
public static void RestoreDefaultConnectionString()
{
if (_connectionString == null) return;
DataAccessContext.ConnectionString = _connectionString;
_connectionString = null;
}
public static void SetCustomConnectionString(string value)
{
if (_connectionString == null)
{
_connectionString = DataAccessContext.ConnectionString;
}
DataAccessContext.ConnectionString = value;
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Compilenix.HttpHeaderSurvey.Tests.Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Compilenix.HttpHeaderSurvey.Tests.Common")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("04f5c3f9-9d10-4413-8fb1-d2d839863dcf")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net47" />
<package id="NUnit" version="3.10.1" targetFramework="net47" />
</packages>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment