public void VerifyTransactionClosedDoomedFalse() { ITranEvSink mock = mockRepository.CreateMock <ITranEvSink>(); Expect.Call(() => mock.Handle(null, null)) .Constraints(RhinoIs.Null(), RhinoIs.Matching <TransactionClosedEventArgs>(args => args.IsDoomed == false)); GlobalTransactionManager.TransactionClosed += mock.Handle; ExecuteAtTheEndOfTest(() => GlobalTransactionManager.TransactionClosed -= mock.Handle); mockRepository.ReplayAll(); GlobalTransactionManager.BeginTransaction().Dispose(); }
/// <summary> /// Ensures, that all interface methods delegate to Write() with correct level + arguments /// and that arguments are still not evaluated up to this point (e.g. calling ToString()) /// </summary> private static void WriteIsCalledWithCorrectLogLevel(string levelName) { MockRepository mocks = new MockRepository(); AbstractTestLogger log = (AbstractTestLogger)mocks.PartialMock(typeof(AbstractTestLogger)); Exception ex = (Exception)mocks.StrictMock(typeof(Exception)); object messageObject = mocks.StrictMock(typeof(object)); object formatArg = mocks.StrictMock(typeof(object)); FormatMessageCallback failCallback = TestFormatMessageCallback.FailCallback(); MethodInfo[] logMethods = GetLogMethodSignatures(levelName); LogLevel logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), levelName); using (mocks.Ordered()) { log.Log(logLevel, null, null); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); log.Log(logLevel, null, ex); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); log.Log(logLevel, null, null); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); log.Log(logLevel, null, ex); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); log.Log(logLevel, null, null); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); log.Log(logLevel, null, ex); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); log.Log(logLevel, null, null); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); log.Log(logLevel, null, ex); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); log.Log(logLevel, null, null); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Null()); log.Log(logLevel, null, ex); LastCall.Constraints(Is.Equal(logLevel), Is.Anything(), Is.Same(ex)); } mocks.ReplayAll(); Invoke(log, logMethods[0], messageObject); Invoke(log, logMethods[1], messageObject, ex); Invoke(log, logMethods[2], "format", new object[] { formatArg }); Invoke(log, logMethods[3], "format", ex, new object[] { formatArg }); Invoke(log, logMethods[4], CultureInfo.InvariantCulture, "format", new object[] { formatArg }); Invoke(log, logMethods[5], CultureInfo.InvariantCulture, "format", ex, new object[] { formatArg }); Invoke(log, logMethods[6], failCallback); Invoke(log, logMethods[7], failCallback, ex); Invoke(log, logMethods[8], CultureInfo.InvariantCulture, failCallback); Invoke(log, logMethods[9], CultureInfo.InvariantCulture, failCallback, ex); mocks.VerifyAll(); }
public void VerifyTransactionClosingDoomedTrue() { ITranEvSink mock = mockRepository.CreateMock <ITranEvSink>(); Expect.Call(() => mock.Handle(null, null)) .Constraints(RhinoIs.Null(), RhinoIs.Matching <TransactionClosingEventArgs>(args => args.IsDoomed == true)); GlobalTransactionManager.TransactionClosing += mock.Handle; ExecuteAtTheEndOfTest(() => GlobalTransactionManager.TransactionClosing -= mock.Handle); mockRepository.ReplayAll(); using (GlobalTransactionManager.BeginTransaction()) { GlobalTransactionManager.DoomCurrentTransaction(); } }