Fixed isses with NewEmpty* integration tests

Signed-off-by: Bjarke Berg <mail@bergmania.dk>
This commit is contained in:
Bjarke Berg
2020-10-28 14:54:16 +01:00
parent 8c5daec967
commit cfaa353dff
5 changed files with 63 additions and 42 deletions

View File

@@ -92,6 +92,7 @@ namespace Umbraco.Tests.Integration.Testing
[SetUp]
public virtual void Setup()
{
InMemoryConfiguration[Constants.Configuration.ConfigGlobal + ":" + nameof(GlobalSettings.InstallEmptyDatabase)] = "true";
var hostBuilder = CreateHostBuilder();
var host = hostBuilder.Start();
@@ -143,8 +144,10 @@ namespace Umbraco.Tests.Integration.Testing
.ConfigureAppConfiguration((context, configBuilder) =>
{
context.HostingEnvironment = TestHelper.GetWebHostEnvironment();
Configuration = context.Configuration;
configBuilder.Sources.Clear();
configBuilder.AddInMemoryCollection(InMemoryConfiguration);
Configuration = configBuilder.Build();
})
.ConfigureServices((hostContext, services) =>
{
@@ -392,12 +395,21 @@ namespace Umbraco.Tests.Integration.Testing
break;
case UmbracoTestOptions.Database.NewEmptyPerTest:
var newEmptyDbId = db.AttachEmpty();
// Add teardown callback
OnTestTearDown(() => db.Detach(newEmptyDbId));
// We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings
if (!databaseFactory.Configured)
{
databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer);
}
// re-run the runtime level check
runtimeState.DetermineRuntimeLevel();
Assert.AreEqual(RuntimeLevel.Install, runtimeState.Level);
break;
case UmbracoTestOptions.Database.NewSchemaPerFixture:
@@ -424,11 +436,23 @@ namespace Umbraco.Tests.Integration.Testing
break;
case UmbracoTestOptions.Database.NewEmptyPerFixture:
// Only attach schema once per fixture
// Doing it more than once will block the process since the old db hasn't been detached
// and it would be the same as NewSchemaPerTest even if it didn't block
if (FirstTestInFixture)
{
// New DB + Schema
var newEmptyFixtureDbId = db.AttachEmpty();
throw new NotImplementedException();
// Add teardown callback
OnFixtureTearDown(() => db.Detach(newEmptyFixtureDbId));
}
//// Add teardown callback
//integrationTest.OnFixtureTearDown(() => db.Detach());
// We must re-configure our current factory since attaching a new LocalDb from the pool changes connection strings
if (!databaseFactory.Configured)
{
databaseFactory.Configure(db.ConnectionString, Constants.DatabaseProviders.SqlServer);
}
break;
default:

View File

@@ -14,7 +14,7 @@ using Umbraco.Tests.Testing;
using Umbraco.Tests.Integration.Testing;
using FileSystems = Umbraco.Core.IO.FileSystems;
namespace Umbraco.Tests.Scoping
namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Scoping
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)]
@@ -44,7 +44,7 @@ namespace Umbraco.Tests.Scoping
TestHelper.DeleteDirectory(ioHelper.MapPath("FileSysTests"));
TestHelper.DeleteDirectory(ioHelper.MapPath(Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "ShadowFs"));
}
[Test]
public void test_MediaFileSystem_does_not_write_to_physical_file_system_when_scoped_if_scope_does_not_complete()
{
@@ -61,7 +61,7 @@ namespace Umbraco.Tests.Scoping
mediaFileSystem.AddFile("f1.txt", ms);
Assert.IsTrue(mediaFileSystem.FileExists("f1.txt"));
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
Assert.IsTrue(mediaFileSystem.FileExists("f1.txt"));
Assert.IsFalse(physMediaFileSystem.FileExists("f1.txt"));
}

View File

@@ -3,20 +3,20 @@ using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Persistence;
using Umbraco.Core.Scoping;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Integration.Testing;
using Umbraco.Tests.Testing;
namespace Umbraco.Tests.Scoping
namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Scoping
{
[TestFixture]
[UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerTest)]
public class ScopeTests : TestWithDatabaseBase
[UmbracoTest(Database = UmbracoTestOptions.Database.NewEmptyPerFixture)]
public class ScopeTests : UmbracoIntegrationTest
{
// setup
public override void SetUp()
{
base.SetUp();
private new ScopeProvider ScopeProvider => (ScopeProvider) base.ScopeProvider;
[SetUp]
public void SetUp()
{
Assert.IsNull(ScopeProvider.AmbientScope); // gone
}
@@ -25,7 +25,7 @@ namespace Umbraco.Tests.Scoping
{
var scopeProvider = ScopeProvider;
Assert.IsNull(scopeProvider.AmbientScope);
Assert.IsNull(ScopeProvider.AmbientScope);
using (var scope = scopeProvider.CreateScope())
{
Assert.IsInstanceOf<Scope>(scope);
@@ -241,32 +241,32 @@ namespace Umbraco.Tests.Scoping
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("CREATE TABLE tmp (id INT, name NVARCHAR(64))");
scope.Database.Execute("CREATE TABLE tmp3 (id INT, name NVARCHAR(64))");
scope.Complete();
}
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
scope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp3 WHERE id=1");
Assert.AreEqual("a", n);
}
using (var scope = scopeProvider.CreateScope())
{
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp3 WHERE id=1");
Assert.IsNull(n);
}
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')");
scope.Database.Execute("INSERT INTO tmp3 (id, name) VALUES (1, 'a')");
scope.Complete();
}
using (var scope = scopeProvider.CreateScope())
{
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp3 WHERE id=1");
Assert.AreEqual("a", n);
}
}
@@ -278,24 +278,24 @@ namespace Umbraco.Tests.Scoping
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("CREATE TABLE tmp (id INT, name NVARCHAR(64))");
scope.Database.Execute($"CREATE TABLE tmp1 (id INT, name NVARCHAR(64))");
scope.Complete();
}
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
scope.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp1 WHERE id=1");
Assert.AreEqual("a", n);
using (var nested = scopeProvider.CreateScope())
{
nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')");
var nn = nested.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
nested.Database.Execute("INSERT INTO tmp1 (id, name) VALUES (2, 'b')");
var nn = nested.Database.ExecuteScalar<string>("SELECT name FROM tmp1 WHERE id=2");
Assert.AreEqual("b", nn);
}
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp1 WHERE id=2");
Assert.AreEqual("b", n);
scope.Complete();
@@ -303,9 +303,9 @@ namespace Umbraco.Tests.Scoping
using (var scope = scopeProvider.CreateScope())
{
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp1 WHERE id=1");
Assert.IsNull(n);
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp1 WHERE id=2");
Assert.IsNull(n);
}
}
@@ -317,33 +317,33 @@ namespace Umbraco.Tests.Scoping
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("CREATE TABLE tmp (id INT, name NVARCHAR(64))");
scope.Database.Execute("CREATE TABLE tmp2 (id INT, name NVARCHAR(64))");
scope.Complete();
}
using (var scope = scopeProvider.CreateScope())
{
scope.Database.Execute("INSERT INTO tmp (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
scope.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (1, 'a')");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp2 WHERE id=1");
Assert.AreEqual("a", n);
using (var nested = scopeProvider.CreateScope())
{
nested.Database.Execute("INSERT INTO tmp (id, name) VALUES (2, 'b')");
var nn = nested.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
nested.Database.Execute("INSERT INTO tmp2 (id, name) VALUES (2, 'b')");
var nn = nested.Database.ExecuteScalar<string>("SELECT name FROM tmp2 WHERE id=2");
Assert.AreEqual("b", nn);
nested.Complete();
}
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp2 WHERE id=2");
Assert.AreEqual("b", n);
}
using (var scope = scopeProvider.CreateScope())
{
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=1");
var n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp2 WHERE id=1");
Assert.IsNull(n);
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp WHERE id=2");
n = scope.Database.ExecuteScalar<string>("SELECT name FROM tmp2 WHERE id=2");
Assert.IsNull(n);
}
}

View File

@@ -44,8 +44,6 @@ namespace Umbraco.Tests.Integration.Umbraco.Infrastructure.Services
CreateTestData();
}
protected override string TestDBConnectionString => base.TestDBConnectionString + "default lock timeout=60000;";
private const int MaxThreadCount = 20;

View File

@@ -144,7 +144,6 @@
<Compile Include="Routing\BaseUrlProviderTest.cs" />
<Compile Include="Routing\UrlProviderWithHideTopLevelNodeFromPathTests.cs" />
<Compile Include="Scoping\ScopeEventDispatcherTests.cs" />
<Compile Include="Scoping\ScopeTests.cs" />
<Compile Include="Security\OwinDataProtectorTokenProviderTests.cs" />
<Compile Include="Services\TestWithSomeContentBase.cs" />
<Compile Include="TestHelpers\Entities\MockedContent.cs" />