public void WillRollbackAndDisposeTransactionIfFlushThrows() { SimpleObject obj = new SimpleObject(); obj.TwoCharactersMax = "This string is too big"; UnitOfWork.CurrentSession.Save(obj); IList <string> logMessages = With.Log(TransactionLog, delegate { try { UnitOfWork.Current.TransactionalFlush(); } catch { ; } }); bool hasRolledBack = false; foreach (string msg in logMessages) { if (msg.ToLower().Contains("rollback")) { hasRolledBack = true; } } Assert.IsTrue(hasRolledBack); }
public void WillNotStartTransactionIfAlreadyStarted() { UnitOfWork.Current.BeginTransaction(); IList <string> logMessages = With.Log(TransactionLog, delegate { UnitOfWork.Current.TransactionalFlush(); }); Assert.NotIn("begin", logMessages); }
public void NoOpWillReturnEmptyCollection() { bool called = false; ICollection <string> logMessages = With.Log("SomeLogger", delegate { called = true; }); Assert.IsTrue(called); Assert.IsTrue(logMessages.Count == 0); }
public void WillAcceptATypeAsTheLoggerParameter() { ILog log = LogManager.GetLogger(GetType()); string debugMessage = "Some debug message"; IList <string> logMessages = With.Log(GetType(), delegate { log.Debug(debugMessage); }); Assert.AreEqual(1, logMessages.Count); }
public void GotchaWillTurnOffLoggingAfterDispose() { ILog log = LogManager.GetLogger("SomeLog"); With.Log(log.Logger.Name, delegate { }); //wire up a new appender to listen to log entries InMemoryMessageAppender appender = new InMemoryMessageAppender(); ((Logger)log.Logger).AddAppender(appender); log.Info("This messgae will go into the blackhole"); Assert.IsTrue(appender.Messages.Count == 0); }
public void WillReturnDebugLogEntryMessagesAndAbove() { ILog log = LogManager.GetLogger("SomeLog"); string debugMessage = "Some debug message"; string fatalMessage = "Some fatal message"; IList <string> logMessages = With.Log(log.Logger.Name, delegate { log.Debug(debugMessage); log.Fatal(fatalMessage); }); Assert.AreEqual(2, logMessages.Count); Assert.AreEqual(debugMessage, logMessages[0]); Assert.AreEqual(fatalMessage, logMessages[1]); }
public void SafeToUseMultipleTimes() { ILog log = LogManager.GetLogger("SomeLog"); With.Log(log.Logger.Name, delegate { log.Debug("Some debug message"); }); string debugMessage = "Another debug message"; IList <string> logMessages = With.Log(log.Logger.Name, delegate { log.Debug(debugMessage); }); Assert.AreEqual(1, logMessages.Count); Assert.AreEqual(debugMessage, logMessages[0]); }
public void WillFlushToDatabaseWithinTransactionAndDisposeOfTransactionAtEnd() { UnitOfWork.CurrentSession.Save(new SimpleObject()); IList <string> logMessages = With.Log(TransactionLog, delegate { UnitOfWork.Current.TransactionalFlush(); }); bool hasCommited = false; foreach (string msg in logMessages) { if (msg.ToLower().Contains("commit")) { hasCommited = true; } } Assert.IsTrue(hasCommited); }