public void Test_WithParentTransactionStrategy() { var strategy = CreateScopedTransactionStrategy(true, OuterTransactionStrategyMock); var expectedObjects = new[] { new object() }; InvokeOnExecutionPlay(strategy); using (MockRepository.Ordered()) { ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); TransactionMock.Expect(mock => mock.Commit()); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(expectedObjects); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(expectedObjects)); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); } MockRepository.ReplayAll(); strategy.OnExecutionStop(Context, ExecutionListenerStub); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_EnsureCompatibility_ThrowsBecauseOfIncompatibleOutParameters() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var invalidOperationException = new InvalidOperationException("Completely bad objects!"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => strategy.OnExecutionStop(Context, ExecutionListenerStub), Throws .TypeOf <WxeException> () .With.Message.EqualTo( "One or more of the output parameters returned from the WxeFunction are incompatible with the function's parent transaction. " + "Completely bad objects!") .And.InnerException.SameAs(invalidOperationException)); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }
public void Test_ReleaseThrows() { var strategy = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null); var innerException = new Exception("Release Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()).Throw(innerException); MockRepository.ReplayAll(); try { strategy.OnExecutionStop(Context, ExecutionListenerStub); Assert.Fail("Expected Exception"); } catch (WxeFatalExecutionException actualException) { Assert.That(actualException.InnerException, Is.SameAs(innerException)); } MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_WithScope() { var object1 = new object(); var object2 = new object(); InvokeOnExecutionPlay(_strategy); TransactionMock.BackToRecord(); TransactionFactoryMock.BackToRecord(); var newScopeMock = MockRepository.StrictMock <ITransactionScope>(); using (MockRepository.Ordered()) { ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); TransactionFactoryMock.Expect(mock => mock.Create()).Return(_newTransactionMock); _newTransactionMock.Expect(mock => mock.EnterScope()).Return(newScopeMock); ExecutionContextMock.Expect(mock => mock.GetVariables()).Return(new[] { object1, object2 }); _newTransactionMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))); } Assert.That(_strategy.Scope, Is.SameAs(ScopeMock)); MockRepository.ReplayAll(); _strategy.Reset(); MockRepository.VerifyAll(); Assert.That(_strategy.Scope, Is.SameAs(newScopeMock)); }
public void Test_WithIncompatibleVariables() { var object1 = new object(); var object2 = new object(); var invalidOperationException = new InvalidOperationException("Oh nos!"); TransactionMock.BackToRecord(); TransactionFactoryMock.BackToRecord(); TransactionMock.Stub(mock => mock.Release()); TransactionFactoryMock.Stub(mock => mock.Create()).Return(_newTransactionMock); ExecutionContextMock.Stub(mock => mock.GetVariables()).Return(new[] { object1, object2 }); _newTransactionMock .Stub(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))) .Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => _strategy.Reset(), Throws .TypeOf <WxeException>() .With.Message.EqualTo( "One or more of the variables of the WxeFunction are incompatible with the new transaction after the Reset. Oh nos! " + "(To avoid this exception, clear the Variables collection from incompatible objects before calling Reset and repopulate it " + "afterwards.)") .And.InnerException.SameAs(invalidOperationException)); Assert.That(_strategy.Scope, Is.Null); Assert.That(_strategy.Transaction, Is.SameAs(_newTransactionMock)); }
public static async Task <Guid> CreateMeetingAsync( IMeetingsModule meetingsModule, ExecutionContextMock executionContext) { var proposalId = await meetingsModule.ExecuteCommandAsync( new ProposeMeetingGroupCommand( "Amazing group", "Absolutely amazing meeting group.", "London", "UK")); await meetingsModule.ExecuteCommandAsync( new CreateNewMeetingGroupCommand( Guid.NewGuid(), new MeetingGroupProposalId(proposalId))); var meetingGroups = await meetingsModule.ExecuteQueryAsync(new GetAllMeetingGroupsQuery()); var meetingGroup = meetingGroups.Single(); await meetingsModule.ExecuteCommandAsync( new SetMeetingGroupExpirationDateCommand( Guid.NewGuid(), meetingGroup.Id, SystemClock.Now.AddMonths(1))); var meetingId = await meetingsModule.ExecuteCommandAsync( new CreateMeetingCommand( meetingGroup.Id, "Some meeting", DateTime.UtcNow.AddDays(1), DateTime.UtcNow.AddDays(10), "Some very nice meeting.", "UK", "Baker street", "W2 2SZ", "London", 25, 1, null, null, null, null, new List <Guid> { executionContext.UserId })); return(meetingId); }
public void TestInit() { _context = new ExecutionContextMock(); _testCommand = new EmptyCommand(); _testCommand.UserInfo = new UserInfoEmbedded { MessageGuid = "guid", MessageText = "text" }; Logging.Logging log = new Logging.Logging(); _logger = new ExecutionLoggerMock(); log.AddLogger(_logger); _context.Log = log; }
public void Test_WithNullValue() { var object1 = new object(); var object2 = new object(); using (MockRepository.Ordered()) { ExecutionContextMock.Expect(mock => mock.GetInParameters()).Return(new[] { object1, null, object2 }); TransactionMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1, object2 }))); } MockRepository.ReplayAll(); new RootTransactionStrategy(false, () => TransactionMock, NullTransactionStrategy.Null, ExecutionContextMock); MockRepository.VerifyAll(); }
public override void SetUp() { base.SetUp(); ExecutionContextMock.BackToRecord(); ExecutionContextMock.Stub(stub => stub.GetInParameters()).Return(new object[0]).Repeat.Any(); ExecutionContextMock.Replay(); TransactionMock.BackToRecord(); TransactionMock.Stub(stub => stub.EnsureCompatibility(Arg <IEnumerable> .Is.NotNull)); TransactionMock.Replay(); _strategy = MockRepository.PartialMock <ScopedTransactionStrategyBase> ( true, (Func <ITransaction>)(() => TransactionMock), OuterTransactionStrategyMock, ExecutionContextMock); _strategy.Replay(); ExecutionContextMock.BackToRecord(); TransactionMock.BackToRecord(); }
public void Test_WithIncompatibleInParameters() { var object1 = new object(); var invalidOperationException = new InvalidOperationException("Objects no good!"); ExecutionContextMock.Stub(mock => mock.GetInParameters()).Return(new[] { object1 }); TransactionMock .Stub(mock => mock.EnsureCompatibility(Arg <IEnumerable> .List.ContainsAll(new[] { object1 }))) .Throw(invalidOperationException); MockRepository.ReplayAll(); Assert.That( () => new RootTransactionStrategy(false, () => TransactionMock, NullTransactionStrategy.Null, ExecutionContextMock), Throws .TypeOf <WxeException>() .With.Message.EqualTo( "One or more of the input parameters passed to the WxeFunction are incompatible with the function's transaction. Objects no good!") .And.InnerException.SameAs(invalidOperationException)); }
public void Test_WithoutAutoCommit() { var strategy = CreateScopedTransactionStrategy(false, NullTransactionStrategy.Null); InvokeOnExecutionPlay(strategy); using (MockRepository.Ordered()) { ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); ScopeMock.Expect(mock => mock.Leave()); TransactionMock.Expect(mock => mock.Release()); } MockRepository.ReplayAll(); strategy.OnExecutionStop(Context, ExecutionListenerStub); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.Null); }
public void Test_EnsureCompatibilityThrowsUnexpected_GetsBubbledOut() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var innerException = new ApplicationException("GetOutParameters Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Return(new object[0]); OuterTransactionStrategyMock.Expect(mock => mock.EnsureCompatibility(Arg <IEnumerable> .Is.Anything)).Throw(innerException); MockRepository.ReplayAll(); Assert.That( () => strategy.OnExecutionStop(Context, ExecutionListenerStub), Throws.Exception.SameAs(innerException)); MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }
public void Test_GetOutParameterThrows() { var strategy = CreateScopedTransactionStrategy(false, OuterTransactionStrategyMock); var innerException = new ApplicationException("GetOutParameters Exception"); InvokeOnExecutionPlay(strategy); ChildTransactionStrategyMock.Expect(mock => mock.OnExecutionStop(Context, ExecutionListenerStub)); ExecutionContextMock.Expect(mock => mock.GetOutParameters()).Throw(innerException); MockRepository.ReplayAll(); try { strategy.OnExecutionStop(Context, ExecutionListenerStub); Assert.Fail("Expected Exception"); } catch (ApplicationException actualException) { Assert.That(actualException, Is.SameAs(innerException)); } MockRepository.VerifyAll(); Assert.That(strategy.Scope, Is.SameAs(ScopeMock)); }