|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.IO; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using Moq; |
| 8 | +using Xunit; |
| 9 | + |
| 10 | +namespace Microsoft.AspNetCore.Http |
| 11 | +{ |
| 12 | + public class ReferenceReadStreamTests |
| 13 | + { |
| 14 | + [Fact] |
| 15 | + public void CanRead_ReturnsTrue() |
| 16 | + { |
| 17 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 18 | + Assert.True(stream.CanRead); |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public void CanSeek_ReturnsFalse() |
| 23 | + { |
| 24 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 25 | + Assert.False(stream.CanSeek); |
| 26 | + } |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void CanWrite_ReturnsFalse() |
| 30 | + { |
| 31 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 32 | + Assert.False(stream.CanWrite); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void SetLength_Throws() |
| 37 | + { |
| 38 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 39 | + Assert.Throws<NotSupportedException>(() => stream.SetLength(0)); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void Write_Throws() |
| 44 | + { |
| 45 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 46 | + Assert.Throws<NotSupportedException>(() => stream.Write(new byte[1], 0, 1)); |
| 47 | + } |
| 48 | + |
| 49 | + [Fact] |
| 50 | + public void WriteByte_Throws() |
| 51 | + { |
| 52 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 53 | + Assert.Throws<NotSupportedException>(() => stream.WriteByte(0)); |
| 54 | + } |
| 55 | + |
| 56 | + [Fact] |
| 57 | + public async Task WriteAsync_Throws() |
| 58 | + { |
| 59 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 60 | + await Assert.ThrowsAsync<NotSupportedException>(() => stream.WriteAsync(new byte[1], 0, 1)); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void Flush_DoesNotThrow() |
| 65 | + { |
| 66 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 67 | + stream.Flush(); |
| 68 | + } |
| 69 | + |
| 70 | + [Fact] |
| 71 | + public async Task FlushAsync_DoesNotThrow() |
| 72 | + { |
| 73 | + var stream = new ReferenceReadStream(Mock.Of<Stream>(), 0, 1); |
| 74 | + await stream.FlushAsync(); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments