Skip to content
Permalink
Browse files

tests: Added Postgres support for UserRepositoryTests including Npg p…

…ackage and PostgresConnectionFactory
  • Loading branch information...
Chris S
Chris S committed Sep 17, 2016
1 parent a66f430 commit c9c5279c8127ef3f4f1a3c5538a7277dda7f1947
Showing with 311 additions and 61 deletions.
  1. +190 −0 lib/Test-databases/roadkill-postgres.sql
  2. +20 −0 src/Roadkill.Core/Database/Repositories/Dapper/PostgresConnectionFactory.cs
  3. +4 −2 src/Roadkill.Core/Roadkill.Core.csproj
  4. +1 −0 src/Roadkill.Core/packages.config
  5. +4 −0 src/Roadkill.Plugins/app.config
  6. +2 −2 src/Roadkill.Tests/Acceptance/Headless/RestApi/WebApiTestBase.cs
  7. BIN src/Roadkill.Tests/Acceptance/Webdriver/InstallerTests.cs
  8. BIN src/Roadkill.Tests/Acceptance/Webdriver/LocalizationTests.cs
  9. +1 −1 src/Roadkill.Tests/Acceptance/Webdriver/SettingsTests.cs
  10. +2 −2 src/Roadkill.Tests/Integration/Import/ScrewturnImporterTests.cs
  11. +6 −10 src/Roadkill.Tests/Integration/Repository/Dapper/DapperUserRepositoryTests.cs
  12. +1 −1 src/Roadkill.Tests/Integration/Repository/LightSpeed/LightSpeedInstallerRepositoryTests.cs
  13. +1 −1 src/Roadkill.Tests/Integration/Repository/LightSpeed/LightSpeedPageRepositoryTests.cs
  14. +1 −1 src/Roadkill.Tests/Integration/Repository/LightSpeed/LightSpeedSettingsRepositoryTests.cs
  15. +1 −7 src/Roadkill.Tests/Integration/Repository/LightSpeed/LightSpeedUserRepositoryTests.cs
  16. +0 −6 src/Roadkill.Tests/Integration/Repository/MongoDb/MongoDbUserRepositoryTests.cs
  17. +0 −1 src/Roadkill.Tests/Integration/Repository/UserRepositoryTests.cs
  18. +4 −0 src/Roadkill.Tests/Roadkill.Tests.csproj
  19. +7 −6 src/Roadkill.Tests/TestConstants.cs
  20. +42 −2 src/Roadkill.Tests/TestHelpers.cs
  21. +4 −0 src/Roadkill.Tests/app.config
  22. +1 −0 src/Roadkill.Tests/packages.config
  23. +19 −19 src/Roadkill.Web/web.config
@@ -0,0 +1,190 @@
-- SQL Manager Lite for PostgreSQL 5.7.1.47382
-- ---------------------------------------
-- Host : localhost
-- Database : roadkill
-- Version : PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit



SET search_path = public, pg_catalog;
DROP TABLE IF EXISTS public.roadkill_siteconfiguration;
DROP TABLE IF EXISTS public.roadkill_users;
DROP TABLE IF EXISTS public.roadkill_pagecontent;
DROP TABLE IF EXISTS public.roadkill_pages;
SET check_function_bodies = false;
--
-- Structure for table roadkill_pages (OID = 16387) :
--
CREATE TABLE public.roadkill_pages (
id serial NOT NULL,
title text NOT NULL,
tags text NOT NULL,
createdby text NOT NULL,
createdon timestamp(6) without time zone NOT NULL,
islocked boolean NOT NULL,
modifiedby text,
modifiedon timestamp(6) without time zone
)
WITH (oids = false);
--
-- Structure for table roadkill_pagecontent (OID = 16396) :
--
CREATE TABLE public.roadkill_pagecontent (
id uuid NOT NULL,
editedby text NOT NULL,
editedon timestamp without time zone NOT NULL,
versionnumber integer NOT NULL,
text text,
pageid integer NOT NULL
)
WITH (oids = false);
--
-- Structure for table roadkill_users (OID = 16404) :
--
CREATE TABLE public.roadkill_users (
id uuid NOT NULL,
activationkey text,
email text NOT NULL,
firstname text,
lastname text,
iseditor boolean NOT NULL,
isadmin boolean NOT NULL,
isactivated boolean NOT NULL,
password text NOT NULL,
passwordresetkey text,
salt text NOT NULL,
username text NOT NULL
)
WITH (oids = false);
--
-- Structure for table roadkill_siteconfiguration (OID = 16412) :
--
CREATE TABLE public.roadkill_siteconfiguration (
id uuid NOT NULL,
version text NOT NULL,
content text NOT NULL
)
WITH (oids = false);
--
-- Data for table public.roadkill_users (OID = 16404) (LIMIT 0,2)
--
INSERT INTO roadkill_users (id, activationkey, email, firstname, lastname, iseditor, isadmin, isactivated, password, passwordresetkey, salt, username)
VALUES ('aabd5468-1c0e-4277-ae10-a0ce00d2fefc', '', 'admin@localhost', 'Chris', 'Admin', false, true, true, 'C882A7933951FCC4197718B104AECC53564FC205', '', 'J::]T!>k5LR|.{U9', 'admin');

INSERT INTO roadkill_users (id, activationkey, email, firstname, lastname, iseditor, isadmin, isactivated, password, passwordresetkey, salt, username)
VALUES ('4d0bc016-1d47-4ad3-a6fe-a11a013ef9c8', '3d12daea-16d0-4bd6-9e0c-347f14e0d97d', 'editor@localhost', '', '', true, false, true, '7715C929E99254C117657B0937E97926443FDAF6', '', 'fO)M`*QU:eH''Xl_%', 'editor');

--
-- Data for table public.roadkill_siteconfiguration (OID = 16412) (LIMIT 0,8)
--
INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('b960e8e5-529f-4f7c-aee4-28eb23e13dbd', '2.0.0.0', '{
"AllowedFileTypes": "jpg,png,gif,zip,xml,pdf",
"AllowUserSignup": true,
"IsRecaptchaEnabled": false,
"MarkupType": "Creole",
"RecaptchaPrivateKey": "recaptcha-private-key",
"RecaptchaPublicKey": "recaptcha-public-key",
"SiteUrl": "http://localhost:9876",
"SiteName": "Acceptance Tests",
"Theme": "Responsive",
"OverwriteExistingFiles": false,
"HeadContent": "",
"MenuMarkup": "* %mainpage%\\r\\n* %categories%\\r\\n* %allpages%\\r\\n* %newpage%\\r\\n* %managefiles%\\r\\n* %sitesettings%\\r\\n\\r\\n",
"PluginLastSaveDate": "2013-12-28T16:00:54.408505Z"
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('8050978c-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "ClickableImages",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('208af9dc-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "ResizeImages",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('b35f5545-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "ExternalLinksInNewWindow",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('b20d067e-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "Jumbotron",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('b970504f-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "MathJax",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('598fdb04-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "ToC",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

INSERT INTO roadkill_siteconfiguration (id, version, content)
VALUES ('92e641c4-80fb-0000-0000-000000000000', '1.0', '{
"PluginId": "SyntaxHighlighter",
"Version": "1.0",
"IsEnabled": false,
"Values": []
}');

--
-- Definition for index roadkill_pages_pkey (OID = 16394) :
--
ALTER TABLE ONLY roadkill_pages
ADD CONSTRAINT roadkill_pages_pkey
PRIMARY KEY (id);
--
-- Definition for index roadkill_pagecontent_pkey (OID = 16402) :
--
ALTER TABLE ONLY roadkill_pagecontent
ADD CONSTRAINT roadkill_pagecontent_pkey
PRIMARY KEY (id);
--
-- Definition for index roadkill_users_pkey (OID = 16410) :
--
ALTER TABLE ONLY roadkill_users
ADD CONSTRAINT roadkill_users_pkey
PRIMARY KEY (id);
--
-- Definition for index roadkill_siteconfiguration_pkey (OID = 16418) :
--
ALTER TABLE ONLY roadkill_siteconfiguration
ADD CONSTRAINT roadkill_siteconfiguration_pkey
PRIMARY KEY (id);
--
-- Definition for index roadkill_siteconfiguration_content_key (OID = 16420) :
--
ALTER TABLE ONLY roadkill_siteconfiguration
ADD CONSTRAINT roadkill_siteconfiguration_content_key
UNIQUE (content);
--
-- Data for sequence public.roadkill_pages_id_seq (OID = 16385)
--
SELECT pg_catalog.setval('roadkill_pages_id_seq', 1, false);
--
-- Comments
--
COMMENT ON SCHEMA public IS 'standard public schema';
@@ -0,0 +1,20 @@
using System.Data;
using Npgsql;

namespace Roadkill.Core.Database.Repositories.Dapper
{
public class PostgresConnectionFactory : IDbConnectionFactory
{
private readonly string _connectionString;

public PostgresConnectionFactory(string connectionString)
{
_connectionString = connectionString;
}

public IDbConnection CreateConnection()
{
return new NpgsqlConnection(_connectionString);
}
}
}
@@ -252,8 +252,9 @@
<HintPath>..\..\packages\NLog.4.2.0\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Npgsql">
<HintPath>..\..\lib\LightSpeed\Providers\Npgsql.dll</HintPath>
<Reference Include="Npgsql, Version=3.1.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\..\packages\Npgsql.3.1.7\lib\net45\Npgsql.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL">
<HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
@@ -363,6 +364,7 @@
<Compile Include="Database\IRepositoryFactory.cs" />
<Compile Include="Database\Repositories\Dapper\DapperUserRepository.cs" />
<Compile Include="Database\Repositories\Dapper\IDbConnectionFactory.cs" />
<Compile Include="Database\Repositories\Dapper\PostgresConnectionFactory.cs" />
<Compile Include="Database\Repositories\Dapper\SqlDbConnectionFactory.cs" />
<Compile Include="Database\Repositories\IDatabaseTester.cs" />
<Compile Include="Database\Repositories\IInstallerRepository.cs" />
@@ -33,6 +33,7 @@
<package id="MySql.Data" version="6.9.8" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NLog" version="4.2.0" targetFramework="net45" />
<package id="Npgsql" version="3.1.7" targetFramework="net45" />
<package id="Owin" version="1.0" targetFramework="net45" />
<package id="recaptcha" version="1.0.5.0" />
<package id="SharpZipLib" version="0.86.0" />
@@ -34,6 +34,10 @@
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.7.0" newVersion="3.1.7.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
@@ -41,11 +41,11 @@ protected IPageRepository GetRepository()
{
ApplicationSettings appSettings = new ApplicationSettings();
appSettings.DatabaseName = "SqlServer2008";
appSettings.ConnectionString = TestConstants.CONNECTION_STRING;
appSettings.ConnectionString = TestConstants.SQLSERVER_CONNECTION_STRING;
appSettings.UseBrowserCache = false;

var context = new LightSpeedContext();
context.ConnectionString = TestConstants.CONNECTION_STRING;
context.ConnectionString = TestConstants.SQLSERVER_CONNECTION_STRING;
context.DataProvider = DataProvider.SqlServer2008;

LightSpeedPageRepository repository = new LightSpeedPageRepository(context.CreateUnitOfWork());
Binary file not shown.
Binary file not shown.
@@ -20,7 +20,7 @@ public void configuration_page_shows_all_settings()
// Assert
Assert.That(Driver.ElementValue("#SiteName"), Is.EqualTo("Acceptance Tests"));
Assert.That(Driver.ElementValue("#SiteUrl"), Is.EqualTo(TestConstants.WEB_BASEURL));
Assert.That(Driver.ElementValue("#ConnectionString"), Is.StringStarting(TestConstants.CONNECTION_STRING));
Assert.That(Driver.ElementValue("#ConnectionString"), Is.StringStarting(TestConstants.SQLSERVER_CONNECTION_STRING));
Assert.That(Driver.ElementValue("#RecaptchaPrivateKey"), Is.EqualTo("recaptcha-private-key"));
Assert.That(Driver.ElementValue("#RecaptchaPublicKey"), Is.EqualTo("recaptcha-public-key"));
Assert.That(Driver.ElementValue("#EditorRoleName"), Is.EqualTo("Editor"));
@@ -17,7 +17,7 @@ namespace Roadkill.Tests.Integration.Import
[Category("Integration")]
public class ScrewturnImporterTests
{
private string _connectionString = TestConstants.CONNECTION_STRING;
private string _connectionString = TestConstants.SQLSERVER_CONNECTION_STRING;

[SetUp]
public void Setup()
@@ -65,7 +65,7 @@ public void should_import_all_pages_categories_and_usernames()
ScrewTurnImporter importer = new ScrewTurnImporter(applicationSettings, pageRepository, userRepository);

// Act
importer.ImportFromSqlServer(TestConstants.CONNECTION_STRING);
importer.ImportFromSqlServer(TestConstants.SQLSERVER_CONNECTION_STRING);

// Assert
User user = userRepository.GetUserByUsername("user2");
@@ -1,7 +1,6 @@
using System;
using NUnit.Framework;
using Roadkill.Core.Database;
using Roadkill.Core.Database.LightSpeed;
using Roadkill.Core.Database.Repositories.Dapper;

namespace Roadkill.Tests.Integration.Repository.Dapper
@@ -10,24 +9,21 @@ namespace Roadkill.Tests.Integration.Repository.Dapper
[Category("Integration")]
public class DapperUserRepositoryTests : UserRepositoryTests
{
protected override string ConnectionString => TestConstants.CONNECTION_STRING;
protected override string ConnectionString => TestConstants.POSTGRES_CONNECTION_STRING;

protected override IUserRepository GetRepository()
{
var factory = new SqlConnectionFactory(ConnectionString);
var factory = new PostgresConnectionFactory(ConnectionString);
return new DapperUserRepository(factory);
}

protected override void Clearup()
{
TestHelpers.SqlServerSetup.RecreateTables();
TestHelpers.SqlServerSetup.ClearDatabase();
}
//TestHelpers.SqlServerSetup.RecreateTables();
//TestHelpers.SqlServerSetup.ClearDatabase();

protected override void CheckDatabaseProcessIsRunning()
{
if (TestHelpers.IsSqlServerRunning() == false)
Assert.Fail("A local Sql Server (sqlservr.exe) is not running");
TestHelpers.PostgresSetup.RecreateTables();
TestHelpers.PostgresSetup.ClearDatabase();
}
}
}
@@ -14,7 +14,7 @@ public class LightSpeedInstallerRepositoryTests : InstallerRepositoryTests
{
protected override string ConnectionString
{
get { return TestConstants.CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override string InvalidConnectionString
@@ -31,7 +31,7 @@ public LightSpeedContext Context

protected override string ConnectionString
{
get { return TestConstants.CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override IPageRepository GetRepository()
@@ -31,7 +31,7 @@ public LightSpeedContext Context

protected override string ConnectionString
{
get { return TestConstants.CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override string InvalidConnectionString
@@ -31,7 +31,7 @@ public LightSpeedContext Context

protected override string ConnectionString
{
get { return TestConstants.CONNECTION_STRING; }
get { return TestConstants.SQLSERVER_CONNECTION_STRING; }
}

protected override IUserRepository GetRepository()
@@ -43,11 +43,5 @@ protected override void Clearup()
{
TestHelpers.SqlServerSetup.ClearDatabase();
}

protected override void CheckDatabaseProcessIsRunning()
{
if (TestHelpers.IsSqlServerRunning() == false)
Assert.Fail("A local Sql Server (sqlservr.exe) is not running");
}
}
}
@@ -22,11 +22,5 @@ protected override void Clearup()
{
new MongoDBUserRepository(ConnectionString).Wipe();
}

protected override void CheckDatabaseProcessIsRunning()
{
if (TestHelpers.IsMongoDBRunning() == false)
Assert.Fail("A local MongoDB (mongod.exe) server is not running");
}
}
}
Oops, something went wrong.

0 comments on commit c9c5279

Please sign in to comment.
You can’t perform that action at this time.