public void CapacityTest() { using (var ms = new NativeMemoryStream(10, 10, 20)) { Assert.That(ms.Capacity, Is.EqualTo(10)); ms.Write(Guid.NewGuid()); Assert.That(ms.Capacity, Is.EqualTo(20)); Assert.That(ms.Length, Is.EqualTo(16)); Assert.That(() => ms.EnsureCapacity(-100), Throws.TypeOf <ArgumentOutOfRangeException>()); Assert.That(() => ms.EnsureCapacity(40), Throws.TypeOf <ArgumentOutOfRangeException>()); } }
public void PropTest() { using (var m = new SafeHGlobalHandle(1000)) using (var ms = new NativeMemoryStream((IntPtr)m, m.Size)) { Assert.That(ms.Capacity, Is.EqualTo(1000)); Assert.That(ms.CanWrite, Is.False); Assert.That(ms.CanSeek, Is.True); Assert.That(ms.CanRead, Is.True); Assert.That(ms.Length, Is.EqualTo(0)); Assert.That(() => ms.EnsureCapacity(2000), Throws.InvalidOperationException); } }