public static void TestExtraObjParams() { LogMessage message = new LogMessage("Hi: {0} ", LogLevel.Error, typeof(LogMessageTests), 2, 3, 4, "TestingBlah"); Console.WriteLine(message.BuildMessage()); Assert.IsTrue(message.BuildMessage().Contains("Hi: 2")); Assert.IsFalse(message.BuildMessage().Contains("TestingBlah")); }
public static void TestBuildMessageNoParams() { LogMessage message = new LogMessage("Hi: Blah", LogLevel.Error, typeof(LogMessageTests)); Console.WriteLine(message.BuildMessage()); Assert.IsTrue(message.BuildMessage().Contains("Hi: Blah")); Assert.IsTrue(message.BuildMessage().Contains(typeof(LogMessageTests).ToString())); Assert.IsTrue(message.BuildMessage().Contains(message.Level.ToString())); }
public static void TestConstruction() { LogMessage message = new LogMessage("Hi: {0}", LogLevel.Error, typeof(LogMessageTests), 2); Assert.AreEqual(message.CallingType, typeof(LogMessageTests)); Assert.AreEqual(message.Level, LogLevel.Error); Assert.IsNotNull(message.MainMessageObject); Assert.IsTrue(message.ObjParams != null && message.ObjParams.Count() == 1); }
public static void MessagePreparer_ICollection_Functionality_Test() { IMessagePreparer preparer = new MessagePreparer(new StringBuilderContainer()); if (!TestContainerSize(0, preparer)) throw new Exception("MessagePreparer count is invalid."); ILogMessage message = new LogMessage("Test", LogLevel.Debug, typeof(MessagePreparerTest)); preparer.Add(message); if (!preparer.Contains(message)) throw new Exception("Failed to find a message that was added in the collection via contains."); if (!TestContainerSize(1, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Remove(message); if (!TestContainerSize(0, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Add(message); if (!TestContainerSize(1, preparer)) throw new Exception("MessagePreparer count is invalid."); if(preparer.Remove(null)) { throw new Exception("Preparer said it removed a null."); } preparer.Remove(new LogMessage("Test", LogLevel.Debug, typeof(MessagePreparerTest))); if (!TestContainerSize(1, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Add(new LogMessage("Test", LogLevel.Debug, typeof(MessagePreparerTest))); int count = 0; foreach(var l in preparer) { if (l == null) throw new Exception("Preparer's enumerator didn't work."); count++; } if (count != 2) throw new Exception("Didn't iterate over the whole collection."); if (!TestContainerSize(2, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Remove(message); if (!TestContainerSize(1, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Remove(message); if (!TestContainerSize(1, preparer)) throw new Exception("MessagePreparer count is invalid."); preparer.Clear(); if (!TestContainerSize(0, preparer)) throw new Exception("MessagePreparer count is invalid."); }
public static void TestInvalidSizeOfObjParams() { LogMessage message = new LogMessage("Hi: {0} {1}", LogLevel.Error, typeof(LogMessageTests), 2); Console.WriteLine(message.BuildMessage()); }
public static void TestBuildMessageWithoutParamsButExpectingParams() { LogMessage message = new LogMessage("Hi: {0}", LogLevel.Error, typeof(LogMessageTests)); Console.WriteLine(message.BuildMessage()); }