-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34ed0d4
commit 7f0d28b
Showing
1 changed file
with
84 additions
and
0 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
tests/BuildingBlocks/Common.Tests/Extensions/StreamExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Text; | ||
|
||
using Common.Extensions; | ||
|
||
namespace Common.Tests.Extensions; | ||
|
||
public sealed class StreamExtensionsTests | ||
{ | ||
[Fact] | ||
public static void TestReadBytesWhenStreamIsNull() | ||
{ | ||
using Stream stream = Stream.Null; | ||
|
||
var res = stream.ReadBytes(10); | ||
|
||
Assert.Empty(res); | ||
} | ||
|
||
[Fact] | ||
public static void TestReadBytesWhenStreamIsNulll() | ||
{ | ||
Stream stream = null!; | ||
|
||
Assert.Throws<ArgumentNullException>(() => stream.ReadBytes(10)); | ||
} | ||
|
||
[Fact] | ||
public static void TestReadBytesWhenCountIsNegative() | ||
{ | ||
using Stream stream = Stream.Null; | ||
|
||
Assert.Throws<ArgumentOutOfRangeException>(() => stream.ReadBytes(-10)); | ||
} | ||
|
||
[Fact] | ||
public static void TestReadBytesWhenCountIsZero() | ||
{ | ||
using Stream stream = Stream.Null; | ||
|
||
var res = stream.ReadBytes(0); | ||
|
||
Assert.Empty(res); | ||
} | ||
|
||
|
||
[Fact] | ||
public static void TestWhenStreamIsShorterThanCount() | ||
{ | ||
var data = "test"u8.ToArray(); | ||
using Stream stream = new MemoryStream(data); | ||
|
||
var res = stream.ReadBytes(1000); | ||
|
||
Assert.NotEmpty(res); | ||
Assert.Equal(data.Length, res.Length); | ||
Assert.Equal(data, res); | ||
} | ||
|
||
[Fact] | ||
public static void TestWhenStreamIsEqualCount() | ||
{ | ||
var data = "test"u8.ToArray(); | ||
using Stream stream = new MemoryStream(data); | ||
|
||
var res = stream.ReadBytes(data.Length); | ||
|
||
Assert.NotEmpty(res); | ||
Assert.Equal(data.Length, res.Length); | ||
Assert.Equal(data, res); | ||
} | ||
|
||
[Fact] | ||
public static void TestWhenStreamIsLongerThanCount() | ||
{ | ||
var data = "test jan pawel 3"u8.ToArray(); | ||
using Stream stream = new MemoryStream(data); | ||
|
||
var res = stream.ReadBytes(data.Length - 1); | ||
|
||
Assert.NotEmpty(res); | ||
Assert.Equal(data.Length - 1, res.Length); | ||
Assert.NotEqual(data, res); | ||
} | ||
} |