public void RepeatedDisposeOnDistinctCopiesDoesNotThrowMirror()
 {
     using (var context = JsonOperationContext.ShortTermSingleUse())
     {
         var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize));
         Assert.False(buffer.IsDisposed);
         var bufferCopy = buffer;
         Assert.False(buffer.IsDisposed);
         Assert.False(bufferCopy.IsDisposed);
         bufferCopy.Dispose();
         Assert.True(buffer.IsDisposed);
         Assert.True(bufferCopy.IsDisposed);
         buffer.Dispose();
         Assert.True(buffer.IsDisposed);
         Assert.True(bufferCopy.IsDisposed);
     }
 }
        public void CopyToThrowsAfterDispose()
        {
            using (var context = JsonOperationContext.ShortTermSingleUse())
            {
                var buffer = new UnmanagedWriteBuffer(context, context.GetMemory(DefaultBufferSize));
                buffer.Dispose();

                var outputBuffer = new byte[DefaultBufferSize];
                fixed(byte *outputBufferPtr = outputBuffer)
                {
#if DEBUG
                    try
                    {
                        buffer.CopyTo(outputBufferPtr);
                        Assert.False(true);
                    }
                    catch (ObjectDisposedException)
                    {
                    }
                    catch (Exception)
                    {
                        Assert.False(true);
                    }
#else
                    try
                    {
                        buffer.CopyTo(outputBufferPtr);
                        Assert.False(true);
                    }
                    catch (NullReferenceException)
                    {
                    }
                    catch (Exception)
                    {
                        Assert.False(true);
                    }
#endif
                }
            }
        }
Exemple #3
0
 public void Dispose()
 {
     _buffer.Dispose();
 }