From bc850d72037ccf5621d5edf462a87ada9d82c434 Mon Sep 17 00:00:00 2001 From: SzymonPobiega Date: Tue, 2 Jan 2018 13:55:23 +0100 Subject: [PATCH 1/2] Fix script location via AppDomain base dir for web applications --- src/SqlPersistence/ScriptLocation.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/SqlPersistence/ScriptLocation.cs b/src/SqlPersistence/ScriptLocation.cs index 87d7456d7..25c490df7 100644 --- a/src/SqlPersistence/ScriptLocation.cs +++ b/src/SqlPersistence/ScriptLocation.cs @@ -6,10 +6,12 @@ static class ScriptLocation { + const string ScriptFolder = "NServiceBus.Persistence.Sql"; + public static string FindScriptDirectory(ReadOnlySettings settings) { var currentDirectory = GetCurrentDirectory(settings); - return Path.Combine(currentDirectory, "NServiceBus.Persistence.Sql", settings.GetSqlDialect().Name); + return Path.Combine(currentDirectory, ScriptFolder, settings.GetSqlDialect().Name); } static string GetCurrentDirectory(ReadOnlySettings settings) @@ -21,7 +23,14 @@ static string GetCurrentDirectory(ReadOnlySettings settings) var entryAssembly = Assembly.GetEntryAssembly(); if (entryAssembly == null) { - return AppDomain.CurrentDomain.BaseDirectory; + var baseDir = AppDomain.CurrentDomain.BaseDirectory; + var scriptDir = Path.Combine(baseDir, ScriptFolder); + //if the app domain base dir contains the scripts folder, return it. Otherwise add "bin" to the base dir so that web apps work correctly + if (Directory.Exists(scriptDir)) + { + return baseDir; + } + return Path.Combine(baseDir, "bin"); } var codeBase = entryAssembly.CodeBase; return Directory.GetParent(new Uri(codeBase).LocalPath).FullName; From bfc6e05792dbec941482bfb0b82e41f35493089d Mon Sep 17 00:00:00 2001 From: SzymonPobiega Date: Wed, 3 Jan 2018 08:05:45 +0100 Subject: [PATCH 2/2] Fix tests --- ..._immediate_dispatch_using_scope_suppress.cs | 2 +- ..._immediate_dispatch_using_scope_suppress.cs | 9 +++++++++ ..._immediate_dispatch_using_scope_suppress.cs | 9 +++++++++ .../Saga/SagaPersisterTests.cs | 18 ++++++++++-------- 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 src/MsSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs create mode 100644 src/PostgreSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs diff --git a/src/AcceptanceTestsHolder/App_Packages/NSB.AcceptanceTests/Tx/ImmediateDispatch/When_requesting_immediate_dispatch_using_scope_suppress.cs b/src/AcceptanceTestsHolder/App_Packages/NSB.AcceptanceTests/Tx/ImmediateDispatch/When_requesting_immediate_dispatch_using_scope_suppress.cs index 64efab1f7..ce613a667 100644 --- a/src/AcceptanceTestsHolder/App_Packages/NSB.AcceptanceTests/Tx/ImmediateDispatch/When_requesting_immediate_dispatch_using_scope_suppress.cs +++ b/src/AcceptanceTestsHolder/App_Packages/NSB.AcceptanceTests/Tx/ImmediateDispatch/When_requesting_immediate_dispatch_using_scope_suppress.cs @@ -9,7 +9,7 @@ using NUnit.Framework; //note: this test will no longer be relevant in v7 - public class When_requesting_immediate_dispatch_using_scope_suppress : NServiceBusAcceptanceTest + public partial class When_requesting_immediate_dispatch_using_scope_suppress : NServiceBusAcceptanceTest { [Test] public async Task Should_dispatch_immediately() diff --git a/src/MsSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs b/src/MsSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs new file mode 100644 index 000000000..22c063bb4 --- /dev/null +++ b/src/MsSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs @@ -0,0 +1,9 @@ +namespace NServiceBus.AcceptanceTests.Tx +{ + using NUnit.Framework; + + [Explicit("SQL transport does not support immediate dispatch via scope suppress")] + public partial class When_requesting_immediate_dispatch_using_scope_suppress + { + } +} \ No newline at end of file diff --git a/src/PostgreSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs b/src/PostgreSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs new file mode 100644 index 000000000..22c063bb4 --- /dev/null +++ b/src/PostgreSqlAcceptanceTests/TestPartials/When_requesting_immediate_dispatch_using_scope_suppress.cs @@ -0,0 +1,9 @@ +namespace NServiceBus.AcceptanceTests.Tx +{ + using NUnit.Framework; + + [Explicit("SQL transport does not support immediate dispatch via scope suppress")] + public partial class When_requesting_immediate_dispatch_using_scope_suppress + { + } +} \ No newline at end of file diff --git a/src/SqlPersistence.Tests/Saga/SagaPersisterTests.cs b/src/SqlPersistence.Tests/Saga/SagaPersisterTests.cs index 566558c12..643c55cf1 100644 --- a/src/SqlPersistence.Tests/Saga/SagaPersisterTests.cs +++ b/src/SqlPersistence.Tests/Saga/SagaPersisterTests.cs @@ -1172,15 +1172,17 @@ public async Task UseConfiguredSchema() }; using (var connection = GetConnection()(null)) + using (var transaction = connection.BeginTransaction()) + using (var storageSession = new StorageSession(connection, transaction, false, null)) { - SagaWithNoCorrelation.SagaData result; - using (var transaction = connection.BeginTransaction()) - using (var storageSession = new StorageSession(connection, transaction, false, null)) - { - await defaultSchemaPersister.Save(sagaData, storageSession, null).ConfigureAwait(false); - result = (await schemaPersister.Get(id, storageSession).ConfigureAwait(false)).Data; - } - connection.ExecuteCommand(SagaScriptBuilder.BuildDropScript(definition, sqlDialect), endpointName, schema: null); + await defaultSchemaPersister.Save(sagaData, storageSession, null).ConfigureAwait(false); + } + + using (var connection = GetConnection()(schema)) + using (var transaction = connection.BeginTransaction()) + using (var storageSession = new StorageSession(connection, transaction, false, null)) + { + var result = (await schemaPersister.Get(id, storageSession).ConfigureAwait(false)).Data; Assert.IsNull(result); } }