Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions PolyShim.Tests/Net70/StreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void ReadAtLeast_Array_SilentOverflow_Test()

// Assert
bytesRead.Should().Be(5);
buffer.Should().StartWith(new byte[] { 1, 2, 3, 4, 5 });
buffer.Should().StartWith([1, 2, 3, 4, 5]);
}

[Fact]
Expand Down Expand Up @@ -118,7 +118,7 @@ public async Task ReadAtLeastAsync_Array_SilentOverflow_Test()

// Assert
bytesRead.Should().Be(5);
buffer.Should().StartWith(new byte[] { 1, 2, 3, 4, 5 });
buffer.Should().StartWith([1, 2, 3, 4, 5]);
}

[Fact]
Expand Down Expand Up @@ -163,7 +163,7 @@ public void ReadAtLeast_Span_Test()

// Assert
bytesRead.Should().BeGreaterOrEqualTo(3);
buffer.Should().StartWith(new byte[] { 1, 2, 3 });
buffer.Should().StartWith([1, 2, 3]);
}
finally
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public void ReadAtLeast_Span_SilentOverflow_Test()

// Assert
bytesRead.Should().BeGreaterOrEqualTo(5);
buffer.Should().StartWith(new byte[] { 1, 2, 3, 4, 5 });
buffer.Should().StartWith([1, 2, 3, 4, 5]);
}
finally
{
Expand All @@ -224,7 +224,7 @@ public void ReadExactly_Span_Test()
stream.ReadExactly(buffer.AsSpan()[..3]);

// Assert
buffer.Should().StartWith(new byte[] { 1, 2, 3 });
buffer.Should().StartWith([1, 2, 3]);
}
finally
{
Expand All @@ -244,7 +244,7 @@ public async Task ReadAtLeastAsync_Memory_Test()

// Assert
bytesRead.Should().BeGreaterOrEqualTo(3);
buffer.Memory.ToArray().Should().StartWith(new byte[] { 1, 2, 3 });
buffer.Memory.ToArray().Should().StartWith([1, 2, 3]);
}

[Fact]
Expand Down Expand Up @@ -272,7 +272,7 @@ public async Task ReadAtLeastAsync_Memory_SilentOverflow_Test()

// Assert
bytesRead.Should().BeGreaterOrEqualTo(5);
buffer.Memory.ToArray().Should().StartWith(new byte[] { 1, 2, 3, 4 });
buffer.Memory.ToArray().Should().StartWith([1, 2, 3, 4]);
}

[Fact]
Expand All @@ -286,6 +286,6 @@ public async Task ReadExactlyAsync_Memory_Test()
await stream.ReadExactlyAsync(buffer.Memory[..3]);

// Assert
buffer.Memory.ToArray().Should().StartWith(new byte[] { 1, 2, 3 });
buffer.Memory.ToArray().Should().StartWith([1, 2, 3]);
}
}
2 changes: 1 addition & 1 deletion PolyShim.Tests/Net90/FileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void AppendAllBytes_Test()
File.WriteAllBytes(tempFilePath, [0x00, 0x01, 0x02]);

// Act
File.AppendAllBytes(tempFilePath, new byte[] { 0x0A, 0x0B, 0x0C, 0x0D, 0x0E });
File.AppendAllBytes(tempFilePath, [0x0A, 0x0B, 0x0C, 0x0D, 0x0E]);

// Assert
var readBytes = File.ReadAllBytes(tempFilePath);
Expand Down
59 changes: 59 additions & 0 deletions PolyShim.Tests/NetCore21/MemoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.NetCore21;

public class MemoryTests
{
[Fact]
public void ImplicitConversion_Test()
{
// Act
Memory<byte> memory = new byte[] { 1, 2, 3, 4, 5 };

// Assert
memory.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void Slice_Test()
{
// Arrange
Memory<byte> memory = new byte[] { 10, 20, 30, 40, 50 };

// Act & Assert
memory.Slice(0, 2).ToArray().Should().Equal(10, 20);
memory.Slice(2, 2).ToArray().Should().Equal(30, 40);
memory.Slice(4, 1).ToArray().Should().Equal(50);
}

[Fact]
public void CopyTo_Test()
{
// Arrange
Memory<byte> source = new byte[] { 1, 2, 3, 4, 5 };
Memory<byte> destination = new byte[5];

// Act
source.CopyTo(destination);

// Assert
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void TryCopyTo_Test()
{
// Arrange
Memory<byte> source = new byte[] { 1, 2, 3, 4, 5 };
Memory<byte> destination = new byte[5];

// Act
var result = source.TryCopyTo(destination);

// Assert
result.Should().BeTrue();
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}
}
4 changes: 1 addition & 3 deletions PolyShim.Tests/NetCore21/RandomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public void NextBytes_Span_Test()
// Assert
buffer
.Should()
.StartWith(
new byte[] { 0x30, 0xE6, 0x63, 0xCA, 0x5F, 0x41, 0x21, 0x48, 0x1F, 0x8F }
);
.StartWith([0x30, 0xE6, 0x63, 0xCA, 0x5F, 0x41, 0x21, 0x48, 0x1F, 0x8F]);
}
finally
{
Expand Down
59 changes: 59 additions & 0 deletions PolyShim.Tests/NetCore21/ReadOnlyMemoryTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.NetCore21;

public class ReadOnlyMemoryTests
{
[Fact]
public void ImplicitConversion_Test()
{
// Act
ReadOnlyMemory<byte> memory = new byte[] { 1, 2, 3, 4, 5 };

// Assert
memory.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void Slice_Test()
{
// Arrange
ReadOnlyMemory<byte> memory = new byte[] { 10, 20, 30, 40, 50 };

// Act & Assert
memory.Slice(0, 2).ToArray().Should().Equal(10, 20);
memory.Slice(2, 2).ToArray().Should().Equal(30, 40);
memory.Slice(4, 1).ToArray().Should().Equal(50);
}

[Fact]
public void CopyTo_Test()
{
// Arrange
ReadOnlyMemory<byte> source = new byte[] { 1, 2, 3, 4, 5 };
Memory<byte> destination = new byte[5];

// Act
source.CopyTo(destination);

// Assert
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void TryCopyTo_Test()
{
// Arrange
ReadOnlyMemory<byte> source = new byte[] { 1, 2, 3, 4, 5 };
Memory<byte> destination = new byte[5];

// Act
var result = source.TryCopyTo(destination);

// Assert
result.Should().BeTrue();
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}
}
90 changes: 90 additions & 0 deletions PolyShim.Tests/NetCore21/ReadOnlySpanTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using FluentAssertions;
using Xunit;

namespace PolyShim.Tests.NetCore21;

public class ReadOnlySpanTests
{
[Fact]
public void ImplicitConversion_Test()
{
// Act
ReadOnlySpan<byte> readOnlySpan = [1, 2, 3, 4, 5];

// Assert
readOnlySpan.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void Indexer_Test()
{
// Arrange
ReadOnlySpan<byte> readOnlySpan = [10, 20, 30, 40, 50];

// Act & Assert
readOnlySpan[0].Should().Be(10);
readOnlySpan[1].Should().Be(20);
readOnlySpan[2].Should().Be(30);
readOnlySpan[3].Should().Be(40);
readOnlySpan[4].Should().Be(50);
}

[Fact]
public void Slice_Test()
{
// Arrange
ReadOnlySpan<byte> readOnlySpan = [10, 20, 30, 40, 50];

// Act
var slice = readOnlySpan.Slice(1, 3);

// Assert
slice.ToArray().Should().Equal(20, 30, 40);
}

[Fact]
public void CopyTo_Test()
{
// Arrange
ReadOnlySpan<byte> source = [1, 2, 3, 4, 5];
Span<byte> destination = new byte[5];

// Act
source.CopyTo(destination);

// Assert
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void TryCopyTo_Test()
{
// Arrange
ReadOnlySpan<byte> source = [1, 2, 3, 4, 5];
Span<byte> destination = new byte[5];

// Act
var result = source.TryCopyTo(destination);

// Assert
result.Should().BeTrue();
destination.ToArray().Should().Equal(1, 2, 3, 4, 5);
}

[Fact]
public void Enumeration_Test()
{
// Arrange
ReadOnlySpan<byte> readOnlySpan = [1, 2, 3, 4, 5];
var result = new List<byte>();

// Act
foreach (var item in readOnlySpan)
result.Add(item);

// Assert
result.Should().Equal(1, 2, 3, 4, 5);
}
}
Loading
Loading