public void UsingConnection() { IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connection); IConnection con1 = scf.CreateConnection(); con1.Start(); con1.Stop(); // should be ignored con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Stop(); // should be ignored con2.Close(); // should be ignored. scf.Dispose(); mocks.VerifyAll(); }
public void UsingConnectionFactory() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once(); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); IConnection con1 = scf.CreateConnection(); con1.Start(); con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Close(); //should be ignored scf.Dispose(); //should trigger actual close mocks.VerifyAll(); }
public void UsingConnection() { IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connection); IConnection con1 = scf.CreateConnection(); con1.Start(); con1.Stop(); // should be ignored con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Stop(); // should be ignored con2.Close(); // should be ignored. scf.Dispose(); mocks.VerifyAll(); }
public void UsingConnectionFactoryAndExceptionListenerAndReconnectOnException() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); TestConnection con = new TestConnection(); TestExceptionListener listener = new TestExceptionListener(); Expect.Call(connectionFactory.CreateConnection()).Return(con).Repeat.Twice(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); scf.ExceptionListener = listener; scf.ReconnectOnException = true; IConnection con1 = scf.CreateConnection(); //Assert.AreSame(listener, ); con1.Start(); con.FireExcpetionEvent(new EMSException("")); IConnection con2 = scf.CreateConnection(); con2.Start(); scf.Dispose(); mocks.VerifyAll(); Assert.AreEqual(2, con.StartCount); Assert.AreEqual(2, con.CloseCount); Assert.AreEqual(1, listener.Count); }
public void UsingConnectionFactoryAndExceptionListener() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); IExceptionListener listener = new ChainedExceptionListener(); Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once(); connection.ExceptionListener = listener; LastCall.On(connection).IgnoreArguments(); Expect.Call(connection.ExceptionListener).Return(listener).Repeat.Once(); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); scf.ExceptionListener = listener; IConnection con1 = scf.CreateConnection(); Assert.AreEqual(listener, connection.ExceptionListener); con1.Start(); con1.Stop(); // should be ignored con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Stop(); con2.Close(); scf.Dispose(); mocks.VerifyAll(); }
public void UsingConnectionFactory() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once(); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); IConnection con1 = scf.CreateConnection(); con1.Start(); con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Close(); //should be ignored scf.Dispose(); //should trigger actual close mocks.VerifyAll(); }
public void UsingConnectionFactoryAndExceptionListenerAndReconnectOnException() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); TestConnection con = new TestConnection(); TestExceptionListener listener = new TestExceptionListener(); Expect.Call(connectionFactory.CreateConnection()).Return(con).Repeat.Twice(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); scf.ExceptionListener = listener; scf.ReconnectOnException = true; IConnection con1 = scf.CreateConnection(); //Assert.AreSame(listener, ); con1.Start(); con.FireExcpetionEvent(new EMSException("")); IConnection con2 = scf.CreateConnection(); con2.Start(); scf.Dispose(); mocks.VerifyAll(); Assert.AreEqual(2, con.StartCount); Assert.AreEqual(2, con.CloseCount); Assert.AreEqual(1, listener.Count); }
public void UsingConnectionFactoryAndExceptionListener() { IConnectionFactory connectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory)); IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection)); IExceptionListener listener = new ChainedExceptionListener(); Expect.Call(connectionFactory.CreateConnection()).Return(connection).Repeat.Once(); connection.ExceptionListener = listener; LastCall.On(connection).IgnoreArguments(); Expect.Call(connection.ExceptionListener).Return(listener).Repeat.Once(); connection.Start(); LastCall.On(connection).Repeat.Twice(); connection.Stop(); LastCall.On(connection).Repeat.Once(); connection.Close(); LastCall.On(connection).Repeat.Once(); mocks.ReplayAll(); SingleConnectionFactory scf = new SingleConnectionFactory(connectionFactory); scf.ExceptionListener = listener; IConnection con1 = scf.CreateConnection(); Assert.AreEqual(listener, connection.ExceptionListener); con1.Start(); con1.Stop(); // should be ignored con1.Close(); // should be ignored IConnection con2 = scf.CreateConnection(); con2.Start(); con2.Stop(); con2.Close(); scf.Dispose(); mocks.VerifyAll(); }
public void SessionCallbackWithinSynchronizedTransaction() { SingleConnectionFactory scf = new SingleConnectionFactory(mockConnectionFactory); EmsTemplate template = CreateTemplate(); template.ConnectionFactory = scf; mockConnection.Start(); LastCall.On(mockConnection).Repeat.Times(2); Expect.Call(mockSession.Transacted).Return(UseTransactedSession).Repeat.Twice(); if (UseTransactedTemplate) { mockSession.Commit(); LastCall.On(mockSession).Repeat.Once(); } mockSession.Close(); LastCall.On(mockSession).Repeat.Once(); mockConnection.Stop(); LastCall.On(mockConnection).Repeat.Once(); mockConnection.Close(); LastCall.On(mockConnection).Repeat.Once(); mocks.ReplayAll(); TransactionSynchronizationManager.InitSynchronization(); try { template.Execute(delegate(ISession session) { bool b = session.Transacted; return null; }); template.Execute(delegate(ISession session) { bool b = session.Transacted; return null; }); Assert.AreSame(mockSession, ConnectionFactoryUtils.GetTransactionalSession(scf, null, false)); Assert.AreSame(mockSession, ConnectionFactoryUtils.GetTransactionalSession(scf, scf.CreateConnection(), false)); //In Java this test was doing 'double-duty' and testing TransactionAwareConnectionFactoryProxy, which has //not been implemented in .NET template.Execute(delegate(ISession session) { bool b = session.Transacted; return null; }); IList synchs = TransactionSynchronizationManager.Synchronizations; Assert.AreEqual(1, synchs.Count); ITransactionSynchronization synch = (ITransactionSynchronization) synchs[0]; synch.BeforeCommit(false); synch.BeforeCompletion(); synch.AfterCommit(); synch.AfterCompletion(TransactionSynchronizationStatus.Unknown); } finally { TransactionSynchronizationManager.ClearSynchronization(); //Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0); //Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive); scf.Dispose(); } Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0); mocks.VerifyAll(); }