/// <summary> /// Initializes a new instance of the <see cref="LogMessageCollectionFilteringAccessor{TMessage}"/> class. /// </summary> /// <param name="collection">The unfiltered collection the accessor should work on.</param> /// <param name="filter"> /// The filter the accessor should apply (<c>null</c> to create an accessor without filtering capabilities). /// </param> internal LogMessageCollectionFilteringAccessor( LogMessageCollection <TMessage> collection, ILogMessageCollectionFilter <TMessage> filter) { mCollection = collection ?? throw new ArgumentNullException(nameof(collection)); mFilter = filter; }
/// <summary> /// Checks whether properties of the specified collection have the expected default values and /// whether the collection contains the expected amount of log messages. /// </summary> /// <param name="collection">Collection to check.</param> /// <param name="expectedCount">Expected number of log messages in the collection.</param> private void TestCollectionPropertyDefaults(LogMessageCollection <LogMessage> collection, long expectedCount) { using (var eventWatcher = collection.AttachEventWatcher()) { // check collection specific properties Assert.Equal(expectedCount, collection.Count); // check properties exposed by IList implementation { var list = collection as IList; Assert.Equal(expectedCount, list.Count); Assert.Equal(CollectionIsReadOnly, list.IsReadOnly); Assert.Equal(CollectionIsFixedSize, list.IsFixedSize); Assert.Equal(CollectionIsSynchronized, list.IsSynchronized); Assert.NotSame(collection, list.SyncRoot); // sync root must not be the same as the collection to avoid deadlocks } // check properties exposed by IList<T> implementation { var list = collection as IList <LogMessage>; Assert.False(list.IsReadOnly); Assert.Equal(expectedCount, list.Count); } // no events should have been raised eventWatcher.CheckInvocations(); } }
private void Create_WithMessages(int count) { var messages = LoggingTestHelpers.GetTestMessages <LogMessage>(count, 1); var collection = new LogMessageCollection <LogMessage>(messages); TestCollectionPropertyDefaults(collection, count); Assert.Equal(messages, collection.ToArray()); }
/// <summary> /// Initializes a new instance of the <see cref="LogMessageCollection{TMessage}"/> class. /// </summary> /// <param name="unfiltered">Collection containing the unfiltered message set.</param> /// <param name="filter">Filter to apply to the unfiltered message set.</param> internal FilteredLogMessageCollection( LogMessageCollection <TMessage> unfiltered, ILogMessageCollectionFilter <TMessage> filter) : base(unfiltered) { Filter = filter ?? throw new ArgumentNullException(nameof(filter)); }
private void Create_Empty() { var collection = new LogMessageCollection <LogMessage>(); TestCollectionPropertyDefaults(collection, 0); }