Skip to content

Commit

Permalink
Fixed cherry picked commits for previous NSB version
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdstelt committed Oct 23, 2020
1 parent bfaa5bf commit d578961
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace NServiceBus.AcceptanceTests.UnitOfWork
using System.Threading.Tasks;
using AcceptanceTesting;
using EndpointTemplates;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus.UnitOfWork;
using NUnit.Framework;

Expand Down Expand Up @@ -41,7 +40,7 @@ public EndpointWithCustomUnitOfWork()
{
EndpointSetup<DefaultServer>((c, r) =>
{
c.RegisterComponents(services => services.AddSingleton<IManageUnitsOfWork, CustomUnitOfWork>());
c.RegisterComponents(container => container.ConfigureComponent<CustomUnitOfWork>(DependencyLifecycle.InstancePerCall));
});
}

Expand All @@ -55,14 +54,14 @@ public CustomUnitOfWork(Context testContext)
public Task Begin()
{
testContext.BeginCalled = true;
return Task.CompletedTask;
return Task.FromResult(0);
}

public Task End(Exception ex = null)
{
testContext.EndCalled = true;
testContext.EndException = ex;
return Task.CompletedTask;
return Task.FromResult(0);
}

Context testContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace NServiceBus.AcceptanceTests.UnitOfWork
using System.Threading.Tasks;
using AcceptanceTesting;
using EndpointTemplates;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus.UnitOfWork;
using NUnit.Framework;

Expand Down Expand Up @@ -37,7 +36,7 @@ public EndpointWithCustomUnitOfWork()
{
EndpointSetup<DefaultServer>((c, r) =>
{
c.RegisterComponents(services => services.AddSingleton<IManageUnitsOfWork, CustomUnitOfWork>());
c.RegisterComponents(container => container.ConfigureComponent<CustomUnitOfWork>(DependencyLifecycle.InstancePerCall));
});
}

Expand All @@ -51,14 +50,14 @@ public CustomUnitOfWork(Context testContext)
public Task Begin()
{
testContext.BeginCalled = true;
return Task.CompletedTask;
return Task.FromResult(0);
}

public Task End(Exception ex = null)
{
testContext.EndCalled = true;
testContext.EndException = ex;
return Task.CompletedTask;
return Task.FromResult(0);
}

Context testContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NServiceBus.AcceptanceTests.UnitOfWork
using System.Transactions;
using AcceptanceTesting;
using EndpointTemplates;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus.UnitOfWork;
using NUnit.Framework;

Expand Down Expand Up @@ -41,7 +40,7 @@ public EndpointWithCustomUnitOfWork()
{
c.UnitOfWork().WrapHandlersInATransactionScope();
c.RegisterComponents(services => services.AddSingleton<IManageUnitsOfWork, CustomUnitOfWork>());
c.RegisterComponents(container => container.ConfigureComponent<CustomUnitOfWork>(DependencyLifecycle.InstancePerCall));
});
}

Expand All @@ -52,19 +51,19 @@ public Task Begin()
{
// this only works because we are not using the async state machine
transactionScope = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled);
return Task.CompletedTask;
return Task.FromResult(0);
}

public Task End(Exception ex = null)
{
transactionScope.Complete();
return Task.CompletedTask;
return Task.FromResult(0);
}
}

class MyMessageHandler : IHandleMessages<MyMessage>
{
Context testContext;
readonly Context testContext;

public MyMessageHandler(Context testContext)
{
Expand All @@ -74,7 +73,7 @@ public MyMessageHandler(Context testContext)
public Task Handle(MyMessage message, IMessageHandlerContext context)
{
testContext.ShouldNeverBeCalled = true;
return Task.CompletedTask;
return Task.FromResult(0);
}
}
}
Expand Down

0 comments on commit d578961

Please sign in to comment.