public UnitOfWorkBehaviorTestsFixture() { UnitsOfWork = new List <Mock <IUnitOfWork> > { new Mock <IUnitOfWork>(), new Mock <IUnitOfWork>(), new Mock <IUnitOfWork>() }; UnitOfWorkBehavior = new UnitOfWorkBehavior(); Builder = new FakeBuilder(); Context = new TestableIncomingLogicalMessageContext { Builder = Builder }; NextTask = new Mock <Func <Task> >(); Builder.Register(UnitsOfWork.Select(u => u.Object).Concat(new[] { new NServiceBus.Features.ClientOutbox.Pipeline.UnitOfWork(null, null, null, null) }).ToArray()); NextTask.Setup(n => n()).Returns(Task.CompletedTask).Callback(() => { if (CommittedUnitsOfWork > 0) { throw new Exception("Next invoked too late"); } }); UnitsOfWork.ForEach(u => u.Setup(u2 => u2.CommitAsync(It.IsAny <Func <Task> >())).Returns <Func <Task> >(t => { CommittedUnitsOfWork++; return(t()); })); }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); var context = new IncomingContext(new RootContext(builder), new TransportMessage()); runner.Invoke(context, () => { }); }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); var context = new ReceivePhysicalMessageContext(new RootContext(builder), new TransportMessage(), false); runner.Invoke(context, () => { }); }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); var context = new ReceivePhysicalMessageContext(new RootContext(builder), new TransportMessage(), false); runner.Invoke(context, () => { }); }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); using (var context = new BehaviorContext(builder, new TransportMessage(), new BehaviorContextStacker())) { runner.Invoke(context, () => { }); } }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); using (var context = new BehaviorContext(builder, new TransportMessage(), new BehaviorContextStacker())) { runner.Invoke(context, () => { }); } }
public void InvokeBehavior(IBuilder builder) { var runner = new UnitOfWorkBehavior(); var context = new IncomingContext(new RootContext(builder), new TransportMessage()); runner.Invoke(context, () => { }); }
static Task InvokeBehavior(FakeBuilder builder, Exception toThrow = null) { var runner = new UnitOfWorkBehavior(); var context = new TestableIncomingPhysicalMessageContext(); context.Builder = builder; return(runner.Invoke(context, ctx => { if (toThrow != null) { throw toThrow; } return TaskEx.CompletedTask; })); }
public async Task Should_not_call_Begin_or_End_when_hasUnitsOfWork_is_false() { var services = new ServiceCollection(); var behavior = new UnitOfWorkBehavior(); await InvokeBehavior(services, behavior : behavior); var unitOfWork = new UnitOfWork(); services.AddTransient <IManageUnitsOfWork>(sp => unitOfWork); await InvokeBehavior(services, behavior : behavior); Assert.IsFalse(unitOfWork.BeginCalled); Assert.IsFalse(unitOfWork.EndCalled); }
public async Task Should_not_call_Begin_or_End_when_hasUnitsOfWork_is_false() { var builder = new FakeBuilder(); var behavior = new UnitOfWorkBehavior(); await InvokeBehavior(builder, behavior : behavior); var unitOfWork = new UnitOfWork(); builder.Register <IManageUnitsOfWork>(unitOfWork); await InvokeBehavior(builder, behavior : behavior); Assert.IsFalse(unitOfWork.BeginCalled); Assert.IsFalse(unitOfWork.EndCalled); }
public void SetUp() { Nails.Configure() .IoC.Container <NullIoCContainer>() .Initialize(); workContextProvider = MockRepository.GenerateMock <IWorkContextProvider>(); var persistenceContext = MockRepository.GenerateMock <IPersistenceContext>(); var transactionalContext = MockRepository.GenerateMock <ITransactionalContext>(); persistenceContext.Expect(x => x.CreateTransactionalContext()).Return(transactionalContext); workContextProvider.Expect(x => x.CurrentContext).Return(new WorkContext(persistenceContext)); UnitOfWorkBehavior.ContextProvider = workContextProvider; behavior = new UnitOfWorkBehavior(); }
public UnitOfWorkBehaviorTestsFixture() { Behavior = new UnitOfWorkBehavior(); Builder = new FakeBuilder(); Db = new Mock <IDb>(); UnitOfWorkContext = new Mock <IUnitOfWorkContext>(); Context = new TestableIncomingLogicalMessageContext { Builder = Builder }; Events = new List <Event> { new FooEvent(), new BarEvent() }; UnitOfWorkContext.Setup(c => c.GetEvents()).Returns(() => { if (!NextTaskInvoked) { throw new Exception("GetEvents called too early"); } return(Events); }); Db.Setup(d => d.SaveChangesAsync()).Returns(Task.CompletedTask).Callback(() => { if (!NextTaskInvoked) { throw new Exception("SaveChanges called too early"); } }); Builder.Register(UnitOfWorkContext.Object); Builder.Register(Db.Object); }
static Task InvokeBehavior(IServiceCollection services, Exception toThrow = null, UnitOfWorkBehavior behavior = null) { var runner = behavior ?? new UnitOfWorkBehavior(); var context = new TestableIncomingPhysicalMessageContext { Services = services }; return(runner.Invoke(context, ctx => { if (toThrow != null) { throw toThrow; } return Task.CompletedTask; })); }
static Task InvokeBehavior(FakeBuilder builder, Exception toThrow = null, bool hasUnitsOfWork = true) { var runner = new UnitOfWorkBehavior(hasUnitsOfWork); var context = new TestableIncomingPhysicalMessageContext(); context.Builder = builder; return runner.Invoke(context, ctx => { if (toThrow != null) { throw toThrow; } return TaskEx.CompletedTask; }); }
public Task Invoke() { return(UnitOfWorkBehavior.Invoke(Context, NextTask.Object)); }