/// <summary> /// Disposes this <see cref="CachedPageStorage"/>, sending any cached write operations /// to the base <see cref="PageStorage"/>. /// </summary> /// <remarks> /// <para> /// This method will result in a call to <see cref="Flush"/> to ensure that any cached write /// operations are sent to the base <see cref="PageStorage"/>. /// </para> /// <para> /// If <see cref="WillLeaveBasePageStorageOpen"/> is false, then this method will dispose the /// base <see cref="PageStorage"/>. /// </para> /// </remarks> /// <seealso cref="IsDisposed"/> public void Dispose() { lock (locker) { if (!IsDisposed) { //Send any cached writes to the base IPageStorage Flush(); if (!WillLeaveBasePageStorageOpen) { PageStorage.Dispose(); } IsDisposed = true; } } }
public void Dispose_ThreePagesRequested_AllThreePagesDisposed() { // Arrange var page = Substitute.For <IPage <int> >(); page.ReturnsForAll(69); var sut = new PageStorage <int>( 10, 10000, (_, __, ___) => page, _ => Observable.Never <IReadOnlyList <int> >()); // Act var i = sut[69]; var i1 = sut[23]; var i2 = sut[3]; sut.Dispose(); // Assert page.Received(Quantity.Exactly(3)).Dispose(); }