From 0f708d6365e9ea40092e17eaba4fca7a51105a69 Mon Sep 17 00:00:00 2001 From: Mathias Johansson Date: Thu, 4 Jan 2018 23:53:43 +0100 Subject: [PATCH] Fixing issue with applicationhost.config not being re-generated at build by automatically generating any t4 template in codeRR.Server.Web.Tests upon build. Refactoring and some cleanup of integration/ui tests. --- .../Helpers/DatabaseManager.cs | 4 +- .../Helpers/TestDataManager.cs | 1 - .../IntegrationTest.cs | 1 - .../Helpers/IisExpressHelper.cs | 8 +- src/Server/Coderr.Server.Web.Tests/WebTest.cs | 14 +- .../applicationhost.config | 1042 ----------------- .../codeRR.Server.Web.Tests.csproj | 11 + 7 files changed, 24 insertions(+), 1057 deletions(-) delete mode 100644 src/Server/Coderr.Server.Web.Tests/applicationhost.config diff --git a/src/Server/Coderr.Server.SqlServer.Tests/Helpers/DatabaseManager.cs b/src/Server/Coderr.Server.SqlServer.Tests/Helpers/DatabaseManager.cs index 85216dbb..d9abc98a 100644 --- a/src/Server/Coderr.Server.SqlServer.Tests/Helpers/DatabaseManager.cs +++ b/src/Server/Coderr.Server.SqlServer.Tests/Helpers/DatabaseManager.cs @@ -22,7 +22,7 @@ public class DatabaseManager : IDisposable public DatabaseManager(string databaseName = null) { var instanceId = Interlocked.Increment(ref InstanceCounter); - _databaseName = databaseName ?? $"coderTest{DateTime.Now:MMddHHmmss}_{instanceId}"; + _databaseName = databaseName ?? $"coderrTest{DateTime.Now:MMddHHmmss}_{instanceId}"; Console.WriteLine("DBNMAE: " + _databaseName); ConnectionString = ConnectionStringHelper.GetConnectionString().ConnectionString .Replace("{databaseName}", _databaseName); @@ -46,8 +46,6 @@ public void Dispose() public void CreateEmptyDatabase() { Debug.WriteLine("*****DBNAME: " + ConnectionString); - var builder = new SqlConnectionStringBuilder(ConnectionString); - Environment.SetEnvironmentVariable("coderr_ConnectionString", $"Data Source={builder.DataSource}"); using (var con = OpenConnection(_masterConString)) { diff --git a/src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs b/src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs index 47c62574..a6bef543 100644 --- a/src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs +++ b/src/Server/Coderr.Server.SqlServer.Tests/Helpers/TestDataManager.cs @@ -66,7 +66,6 @@ public void ActivateAccount(int accountId) } } - /// /// Creates an incident and a report. /// diff --git a/src/Server/Coderr.Server.SqlServer.Tests/IntegrationTest.cs b/src/Server/Coderr.Server.SqlServer.Tests/IntegrationTest.cs index f1e8e4ca..8047f1c1 100644 --- a/src/Server/Coderr.Server.SqlServer.Tests/IntegrationTest.cs +++ b/src/Server/Coderr.Server.SqlServer.Tests/IntegrationTest.cs @@ -1,5 +1,4 @@ using System; -using codeRR.Server.Api.Core.Incidents.Queries; using codeRR.Server.SqlServer.Core.Accounts; using codeRR.Server.SqlServer.Tests.Helpers; using Griffin.Data; diff --git a/src/Server/Coderr.Server.Web.Tests/Helpers/IisExpressHelper.cs b/src/Server/Coderr.Server.Web.Tests/Helpers/IisExpressHelper.cs index 2da95d99..8581722d 100644 --- a/src/Server/Coderr.Server.Web.Tests/Helpers/IisExpressHelper.cs +++ b/src/Server/Coderr.Server.Web.Tests/Helpers/IisExpressHelper.cs @@ -60,11 +60,10 @@ public void Start(string site) SetDefaultsWhereNecessary(); if (!File.Exists(ExePath)) - throw new FileNotFoundException("Path to IIS Express executable is invalid: '" + ExePath + "'."); + throw new FileNotFoundException($"Path to IIS Express executable is invalid: '{ExePath}'."); if (string.IsNullOrEmpty(ConfigPath) || !File.Exists(ConfigPath)) - throw new FileNotFoundException("Path to IIS Express configuration file is invalid: '" + ConfigPath + - "'."); + throw new FileNotFoundException($"Path to IIS Express configuration file is invalid: '{ConfigPath}'."); var iisExpressThread = new Thread(() => StartIisExpress(p => _process = p, site)) {IsBackground = true}; iisExpressThread.Start(); @@ -76,9 +75,9 @@ public void Start(string site) Thread.Sleep(200); attemptsLeft--; } + if (_process == null) throw new InvalidOperationException("Failed to start IIS express"); - } /// @@ -155,7 +154,6 @@ private void StartIisExpress(Action action, string site) if (!isRunning) throw new InvalidOperationException("Failed to receive data from IIS ex"); - action(process); } } diff --git a/src/Server/Coderr.Server.Web.Tests/WebTest.cs b/src/Server/Coderr.Server.Web.Tests/WebTest.cs index 51f60507..11d8dc69 100644 --- a/src/Server/Coderr.Server.Web.Tests/WebTest.cs +++ b/src/Server/Coderr.Server.Web.Tests/WebTest.cs @@ -1,10 +1,12 @@ using System; using System.Collections.Generic; using System.IO; +using codeRR.Server.SqlServer.Core.Accounts; using codeRR.Server.SqlServer.Tests.Helpers; using codeRR.Server.Web.Tests.Helpers; using codeRR.Server.Web.Tests.Helpers.Selenium; using codeRR.Server.Web.Tests.Helpers.xUnit; +using Griffin.Data.Mapper; using OpenQA.Selenium; using OpenQA.Selenium.Support.Extensions; using Xunit; @@ -21,6 +23,10 @@ public abstract class WebTest static WebTest() { + var mapper = new AssemblyScanningMappingProvider(); + mapper.Scan(typeof(AccountRepository).Assembly); + EntityMappingProvider.Provider = mapper; + _databaseManager.CreateEmptyDatabase(); _databaseManager.InitSchema(); @@ -35,12 +41,12 @@ static WebTest() _iisExpress = new IisExpressHelper { ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "applicationhost.config"), - EnvironmentVariables = - new Dictionary { { "coderr_ConnectionString", _databaseManager.ConnectionString } } + + // Pass on connectionstring to codeRR.Server.Web during testing, overriding connectionstring in web.config + EnvironmentVariables = new Dictionary { { "coderr_ConnectionString", _databaseManager.ConnectionString } } }; _iisExpress.Start("codeRR.Server.Web"); - TestData = new TestDataManager(_databaseManager.OpenConnection); } @@ -52,14 +58,12 @@ protected WebTest() TestData.ResetDatabase(_iisExpress.BaseUrl); } - public string ServerUrl => _iisExpress.BaseUrl; public static TestDataManager TestData { get; } public IWebDriver WebDriver { get; private set; } - public void Dispose() { if (_disposed) diff --git a/src/Server/Coderr.Server.Web.Tests/applicationhost.config b/src/Server/Coderr.Server.Web.Tests/applicationhost.config deleted file mode 100644 index 3c8e22b4..00000000 --- a/src/Server/Coderr.Server.Web.Tests/applicationhost.config +++ /dev/null @@ -1,1042 +0,0 @@ - - - - - - - -
-
-
-
-
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
- -
-
-
-
-
-
- -
-
-
-
-
- -
-
-
- -
-
- -
-
- -
-
-
- - -
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Server/Coderr.Server.Web.Tests/codeRR.Server.Web.Tests.csproj b/src/Server/Coderr.Server.Web.Tests/codeRR.Server.Web.Tests.csproj index a7ab556b..aab70e06 100644 --- a/src/Server/Coderr.Server.Web.Tests/codeRR.Server.Web.Tests.csproj +++ b/src/Server/Coderr.Server.Web.Tests/codeRR.Server.Web.Tests.csproj @@ -37,4 +37,15 @@ + + True + True + + + + +