Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikus1993 committed Feb 29, 2024
1 parent 34ed0d4 commit 7f0d28b
Showing 1 changed file with 84 additions and 0 deletions.
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);
}
}

0 comments on commit 7f0d28b

Please sign in to comment.