Skip to content

Commit

Permalink
Merge branch 'hotfix-2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Mar 27, 2015
2 parents 16362f8 + 57752f2 commit da8ecde
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\Audit\When_a_replymessage_is_audited.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\ScenarioDescriptors\AllTransactionSettings.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\ScenarioDescriptors\TransactionSettings.cs" />
<Compile Include="When_processing_messages.cs" />
<Compile Include="When_using_non_standard_schema.cs" />
<Compile Include="When_callback_receiver_is_disabled.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\Audit\When_a_message_is_audited.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace NServiceBus.AcceptanceTests.Basic
{
using System;
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NServiceBus.Transports.SQLServer;
using NUnit.Framework;

public class When_processing_messages : NServiceBusAcceptanceTest
{
[Test]
public void Should_allow_injecting_the_storage_context()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<Endpoint>(b => b.Given(bus => bus.SendLocal(new TestMessage())))
.Done(c => c.Done)
.Run();

Assert.True(context.ContextInjected);
}

public class Context : ScenarioContext
{
public bool Done { get; set; }
public bool ContextInjected { get; set; }
}


[Serializable]
public class TestMessage : IMessage { }

public class Endpoint : EndpointConfigurationBuilder
{
public Endpoint()
{
EndpointSetup<DefaultServer>(b => b.Transactions().DisableDistributedTransactions());
}

class Handler : IHandleMessages<TestMessage>
{
public Context Context { get; set; }
public SqlServerStorageContext StorageContext { get; set; }

public void Handle(TestMessage message)
{
Context.ContextInjected = StorageContext != null && StorageContext.Connection != null && StorageContext.Transaction != null;
Context.Done = true;
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected override void Configure(FeatureConfigurationContext context, string co
context.Container.ConfigureComponent(b => new ReceiveStrategyFactory(b.Build<PipelineExecutor>(), b.Build<LocalConnectionParams>(), errorQueue), DependencyLifecycle.InstancePerCall);

context.Container.ConfigureComponent<SqlServerPollingDequeueStrategy>(DependencyLifecycle.InstancePerCall);
context.Container.ConfigureComponent<SqlServerStorageContext>(DependencyLifecycle.InstancePerUnitOfWork);
context.Container.ConfigureComponent(b => new SqlServerStorageContext(b.Build<PipelineExecutor>(), b.Build<LocalConnectionParams>()), DependencyLifecycle.InstancePerUnitOfWork);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/NServiceBus.SqlServer/SqlServerStorageContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace NServiceBus.Transports.SQLServer
public class SqlServerStorageContext
{
readonly PipelineExecutor pipelineExecutor;
readonly string connectionString;
readonly LocalConnectionParams localConnectionParams;

internal SqlServerStorageContext(PipelineExecutor pipelineExecutor, string connectionString)
internal SqlServerStorageContext(PipelineExecutor pipelineExecutor, LocalConnectionParams localConnectionParams)
{
this.pipelineExecutor = pipelineExecutor;
this.connectionString = connectionString;
this.localConnectionParams = localConnectionParams;
}

/// <summary>
Expand All @@ -26,7 +26,7 @@ public IDbConnection Connection
get
{
SqlConnection connection;
return pipelineExecutor.TryGetConnection(connectionString, out connection)
return pipelineExecutor.TryGetConnection(localConnectionParams.ConnectionString, out connection)
? connection
: null;
}
Expand All @@ -40,7 +40,7 @@ public SqlTransaction Transaction
get
{
SqlTransaction transaction;
return pipelineExecutor.TryGetTransaction(connectionString, out transaction)
return pipelineExecutor.TryGetTransaction(localConnectionParams.ConnectionString, out transaction)
? transaction
: null;
}
Expand Down

0 comments on commit da8ecde

Please sign in to comment.