public void GivenBufferListWhenInstantiateShouldBeEmptyAndNotReadOnly() { var list = new BufferList <int>(1000, TimeSpan.FromSeconds(10)); list.Should().NotBeNull(); list.Should().BeEmpty(); list.IsReadOnly.Should().BeFalse(); }
public void GivenBufferListWhenEmptyEventsShouldNotThrow() { var list = new BufferList <int>(1000, TimeSpan.FromSeconds(10)) { 1 }; list.Invoking(x => x.Clear()).Should().NotThrow(); list.Should().BeEmpty(); }
public void GivenBufferListWhenCapacityAchievedShouldClear() { var removedCount = 0; var list = new BufferList <int>(100, Timeout.InfiniteTimeSpan); var autoResetEvent = new AutoResetEvent(false); list.Cleared += removed => { removedCount = removed.Count; autoResetEvent.Set(); }; for (var i = 0; i <= 100; i++) { list.Add(i); } autoResetEvent.WaitOne(); removedCount.Should().Be(100); list.Should().HaveCount(1); }
public void GivenBufferListWhenTtlElapsedShouldClear() { var autoResetEvent = new AutoResetEvent(false); var removedCount = 0; var list = new BufferList <int>(1000, TimeSpan.FromSeconds(1)); list.Cleared += removed => { removedCount = removed.Count; autoResetEvent.Set(); }; for (var i = 0; i < 999; i++) { list.Add(i); } autoResetEvent.WaitOne(); removedCount.Should().Be(999); list.Should().BeEmpty(); }