private static void AssertEquivalent(MemoryStream standard, SmallBlockMemoryStream subject) { // length and position should be identical to standard subject.Length.Should().Be(standard.Length); subject.Position.Should().Be(standard.Position); // allocations should never exceed LOH limit var allocationSizes = subject.GetAllocationSizes(); allocationSizes.Any(x => x > SmallBlockMemoryStream.MaxBlockSize) .Should().BeFalse(); // capacity should match allocations var calculatedCapacity = allocationSizes.Sum(x => (long)Math.Max(0, x)); subject.Capacity.Should().Be(calculatedCapacity); // total allocation should be identical to the standard until the LOH limit // is exceeded... if (standard.Capacity < SmallBlockMemoryStream.MaxBlockSize) { calculatedCapacity.Should().Be(standard.Capacity); } // contents of the stream should be identical to the standard Assert.AreEqual(standard, subject); }
public void Dispose_LeavesSafePropertiesInTheCorrectState() { var subject = new SmallBlockMemoryStream(); subject.Dispose(); subject.ShouldBeEquivalentTo(new { CanRead = false, CanSeek = false, CanWrite = false, }, EqOpts); subject.GetAllocationSizes().ShouldBeEquivalentTo(NoAllocations); }