public void EventHandling() { LogsCollection logsCollection = new LogsCollection(); bool isCalled = false; logsCollection.OnAdd += (entry) => { isCalled = !isCalled; }; logsCollection.Add(new Entry("smth")); Assert.IsTrue(isCalled); logsCollection.Add(new Entry("smth2")); Assert.IsFalse(isCalled); logsCollection.Add(new Entry("smth3")); Assert.IsTrue(isCalled); LogsCollection logsCollection2 = new LogsCollection(); logsCollection.OnAdd += (entry) => { logsCollection2.Add(new Entry(entry.Text, entry.Time, entry.Level)); }; logsCollection.Add(new Entry ( "test2.0", new DateTime(1992, 6, 12, 12, 0, 0), EntryLevel.System) ); Entry expected = new Entry("test2.0", new DateTime(1992, 6, 12, 12, 0, 0), EntryLevel.System); Assert.AreEqual(expected, logsCollection2.LastAdded()); }
public void LastLog() { LogsCollection logsCollection = new LogsCollection(); Entry log1 = new Entry("smth", new DateTime(2203, 1, 1, 1, 1, 1)); Entry log2 = new Entry("smth2"); logsCollection.Add(log1); for (int i = 0; i < 10; ++i) { logsCollection.Add(new Entry("smth for " + i.ToString())); } logsCollection.Add(log2); Entry lastLog1 = logsCollection.LastByTime(); Entry lastLog2 = logsCollection.LastAdded(); Assert.AreEqual(log1, lastLog1); Assert.AreEqual(log2, lastLog2); }