示例#1
0
        public static void UmaCtors()
        {
            using (FakeSafeBuffer fakeBuffer = new FakeSafeBuffer(99))
                using (var uma = new UnmanagedMemoryAccessor(fakeBuffer, 0, 0))
                {
                    Assert.True(uma.CanRead);
                    Assert.False(uma.CanWrite);
                    Assert.Equal(0, uma.Capacity);
                }

            using (FakeSafeBuffer fakeBuffer = new FakeSafeBuffer(99))
                using (var duma = new DerivedUnmanagedMemoryAccessor())
                {
                    Assert.False(duma.CanRead);
                    Assert.False(duma.CanWrite);
                    Assert.Equal(0, duma.Capacity);
                    Assert.False(duma.IsOpen);
                    duma.Initialize(fakeBuffer, 0, (long)fakeBuffer.ByteLength, FileAccess.ReadWrite);
                    Assert.True(duma.IsOpen);
                    Assert.Throws <InvalidOperationException>(() => duma.Initialize(fakeBuffer, 0, (long)fakeBuffer.ByteLength, FileAccess.ReadWrite));
                }
        }
示例#2
0
        public static void UmaCtors()
        {
            using (FakeSafeBuffer fakeBuffer = new FakeSafeBuffer(99))
            using (var uma = new UnmanagedMemoryAccessor(fakeBuffer, 0, 0))
            {
                Assert.True(uma.CanRead);
                Assert.False(uma.CanWrite);
                Assert.Equal(0, uma.Capacity);
            }

            using (FakeSafeBuffer fakeBuffer = new FakeSafeBuffer(99))
            using (var duma = new DerivedUnmanagedMemoryAccessor())
            {
                Assert.False(duma.CanRead);
                Assert.False(duma.CanWrite);
                Assert.Equal(0, duma.Capacity);
                Assert.False(duma.IsOpen);
                duma.Initialize(fakeBuffer, 0, (long)fakeBuffer.ByteLength, FileAccess.ReadWrite);
                Assert.True(duma.IsOpen);
                Assert.Throws<InvalidOperationException>(() => duma.Initialize(fakeBuffer, 0, (long)fakeBuffer.ByteLength, FileAccess.ReadWrite));
            }
        }