Skip to content

Commit

Permalink
Code cleanup + NUnit4 (#317)
Browse files Browse the repository at this point in the history
* Fit & Finish. Use latest syntax, fix spelling, update to NUnit4 (with accompanying assert style changes)

* Update documentation

* Update SDK to v8.0.100

* Update SDK in global.json

* Remove unnecessary casts

---------

Co-authored-by: Ben Watson <bewatson@microsoft.com>
  • Loading branch information
benmwatson and Ben Watson authored Dec 6, 2023
1 parent 9995e7d commit 6e154dd
Show file tree
Hide file tree
Showing 85 changed files with 757 additions and 905 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.102
dotnet-version: 8.0.100

# Build and test validation

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.102
dotnet-version: 8.0.100

- name: Checkout repository
uses: actions/checkout@v4
Expand Down
172 changes: 84 additions & 88 deletions UnitTests/Tests.cs

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
<RootNamespace>Microsoft.IO.UnitTests</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>

<!--NUnit2045 - Use Assert.Multiple. Not interested at this time. -->
<NoWarn>NUnit2045</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.14.0" />
<PackageReference Include="nunit" Version="4.0.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.10.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Microsoft.IO.RecyclableMemoryStream.csproj" />
Expand Down
8 changes: 4 additions & 4 deletions docs/Microsoft.IO/RecyclableMemoryStream.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed class RecyclableMemoryStream : MemoryStream, IBufferWriter<byte>

| name | description |
| --- | --- |
| [RecyclableMemoryStream](RecyclableMemoryStream/RecyclableMemoryStream.md)(…) | Initializes a new instance of the [`RecyclableMemoryStream`](./RecyclableMemoryStream.md) class. (8 constructors) |
| [RecyclableMemoryStream](RecyclableMemoryStream/RecyclableMemoryStream.md)(…) | Initializes a new instance of the [`RecyclableMemoryStream`](./RecyclableMemoryStream.md) class. (6 constructors) |
| override [CanRead](RecyclableMemoryStream/CanRead.md) { get; } | Whether the stream can currently read. |
| override [CanSeek](RecyclableMemoryStream/CanSeek.md) { get; } | Whether the stream can currently seek. |
| override [CanTimeout](RecyclableMemoryStream/CanTimeout.md) { get; } | Always false. |
Expand All @@ -29,8 +29,8 @@ public sealed class RecyclableMemoryStream : MemoryStream, IBufferWriter<byte>
| [GetSpan](RecyclableMemoryStream/GetSpan.md)(…) | |
| override [Read](RecyclableMemoryStream/Read.md)(…) | Reads from the current position into the provided buffer. (2 methods) |
| override [ReadByte](RecyclableMemoryStream/ReadByte.md)() | Reads a single byte from the current position in the stream. |
| [SafeRead](RecyclableMemoryStream/SafeRead.md)(…) | Reads from the specified position into the provided buffer. (4 methods) |
| [SafeReadByte](RecyclableMemoryStream/SafeReadByte.md)(…) | Reads a single byte from the specified position in the stream. (2 methods) |
| [SafeRead](RecyclableMemoryStream/SafeRead.md)(…) | Reads from the specified position into the provided buffer. (2 methods) |
| [SafeReadByte](RecyclableMemoryStream/SafeReadByte.md)(…) | Reads a single byte from the specified position in the stream. |
| override [Seek](RecyclableMemoryStream/Seek.md)(…) | Sets the position to the offset from the seek location. |
| override [SetLength](RecyclableMemoryStream/SetLength.md)(…) | Sets the length of the stream. |
| override [ToArray](RecyclableMemoryStream/ToArray.md)() | Returns a new array with a copy of the buffer's contents. You should almost certainly be using [`GetBuffer`](./RecyclableMemoryStream/GetBuffer.md) combined with the [`Length`](./RecyclableMemoryStream/Length.md) to access the bytes in this stream. Calling `ToArray` will destroy the benefits of pooled buffers, but it is included for the sake of completeness. |
Expand All @@ -39,7 +39,7 @@ public sealed class RecyclableMemoryStream : MemoryStream, IBufferWriter<byte>
| override [Write](RecyclableMemoryStream/Write.md)(…) | Writes the buffer to the stream. (2 methods) |
| override [WriteByte](RecyclableMemoryStream/WriteByte.md)(…) | Writes a single byte to the current position in the stream. |
| override [WriteTo](RecyclableMemoryStream/WriteTo.md)(…) | Synchronously writes this stream's bytes to the argument stream. |
| [WriteTo](RecyclableMemoryStream/WriteTo.md)(…) | Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream. (5 methods) |
| [WriteTo](RecyclableMemoryStream/WriteTo.md)(…) | Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream. (4 methods) |

## Protected Members

Expand Down
67 changes: 10 additions & 57 deletions docs/Microsoft.IO/RecyclableMemoryStream/RecyclableMemoryStream.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RecyclableMemoryStream constructor (1 of 8)
# RecyclableMemoryStream constructor (1 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

Expand All @@ -18,7 +18,7 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager)

---

# RecyclableMemoryStream constructor (2 of 8)
# RecyclableMemoryStream constructor (2 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

Expand All @@ -39,12 +39,12 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid

---

# RecyclableMemoryStream constructor (3 of 8)
# RecyclableMemoryStream constructor (3 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag)
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string? tag)
```

| parameter | description |
Expand All @@ -60,12 +60,12 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, strin

---

# RecyclableMemoryStream constructor (4 of 8)
# RecyclableMemoryStream constructor (4 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string tag)
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string? tag)
```

| parameter | description |
Expand All @@ -82,35 +82,12 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid

---

# RecyclableMemoryStream constructor (5 of 8)
# RecyclableMemoryStream constructor (5 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag,
int requestedSize)
```

| parameter | description |
| --- | --- |
| memoryManager | The memory manager |
| tag | A string identifying this stream for logging and debugging purposes. |
| requestedSize | The initial requested size to prevent future allocations. |

## See Also

* class [RecyclableMemoryStreamManager](../RecyclableMemoryStreamManager.md)
* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream constructor (6 of 8)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string tag,
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, string? tag,
long requestedSize)
```

Expand All @@ -128,36 +105,12 @@ public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, strin

---

# RecyclableMemoryStream constructor (7 of 8)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string tag,
int requestedSize)
```

| parameter | description |
| --- | --- |
| memoryManager | The memory manager. |
| id | A unique identifier which can be used to trace usages of the stream. |
| tag | A string identifying this stream for logging and debugging purposes. |
| requestedSize | The initial requested size to prevent future allocations. |

## See Also

* class [RecyclableMemoryStreamManager](../RecyclableMemoryStreamManager.md)
* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream constructor (8 of 8)
# RecyclableMemoryStream constructor (6 of 6)

Initializes a new instance of the [`RecyclableMemoryStream`](../RecyclableMemoryStream.md) class.

```csharp
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string tag,
public RecyclableMemoryStream(RecyclableMemoryStreamManager memoryManager, Guid id, string? tag,
long requestedSize)
```

Expand Down
71 changes: 2 additions & 69 deletions docs/Microsoft.IO/RecyclableMemoryStream/SafeRead.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
# RecyclableMemoryStream.SafeRead method (1 of 4)

Reads from the specified position into the provided buffer.

```csharp
public int SafeRead(Span<byte> buffer, ref int streamPosition)
```

| parameter | description |
| --- | --- |
| buffer | Destination buffer. |
| streamPosition | Position in the stream to start reading from. |

## Return Value

The number of bytes read.

## Exceptions

| exception | condition |
| --- | --- |
| ObjectDisposedException | Object has been disposed. |
| InvalidOperationException | Stream position is beyond `int.MaxValue`. |

## See Also

* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream.SafeRead method (2 of 4)
# RecyclableMemoryStream.SafeRead method (1 of 2)

Reads from the specified position into the provided buffer.

Expand Down Expand Up @@ -59,43 +28,7 @@ The number of bytes read.

---

# RecyclableMemoryStream.SafeRead method (3 of 4)

Reads from the specified position into the provided buffer.

```csharp
public int SafeRead(byte[] buffer, int offset, int count, ref int streamPosition)
```

| parameter | description |
| --- | --- |
| buffer | Destination buffer. |
| offset | Offset into buffer at which to start placing the read bytes. |
| count | Number of bytes to read. |
| streamPosition | Position in the stream to start reading from. |

## Return Value

The number of bytes read.

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | *buffer* is null. |
| ArgumentOutOfRangeException | *offset* or *count* is less than 0. |
| ArgumentException | *offset* subtracted from the buffer length is less than *count*. |
| ObjectDisposedException | Object has been disposed. |
| InvalidOperationException | Stream position is beyond `int.MaxValue`. |

## See Also

* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream.SafeRead method (4 of 4)
# RecyclableMemoryStream.SafeRead method (2 of 2)

Reads from the specified position into the provided buffer.

Expand Down
32 changes: 1 addition & 31 deletions docs/Microsoft.IO/RecyclableMemoryStream/SafeReadByte.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@
# RecyclableMemoryStream.SafeReadByte method (1 of 2)

Reads a single byte from the specified position in the stream.

```csharp
public int SafeReadByte(ref int streamPosition)
```

| parameter | description |
| --- | --- |
| streamPosition | The position in the stream to read from. |

## Return Value

The byte at the current position, or -1 if the position is at the end of the stream.

## Exceptions

| exception | condition |
| --- | --- |
| ObjectDisposedException | Object has been disposed. |
| InvalidOperationException | Stream position is beyond `int.MaxValue`. |

## See Also

* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream.SafeReadByte method (2 of 2)
# RecyclableMemoryStream.SafeReadByte method

Reads a single byte from the specified position in the stream.

Expand Down
2 changes: 1 addition & 1 deletion docs/Microsoft.IO/RecyclableMemoryStream/Seek.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The new position.
| exception | condition |
| --- | --- |
| ObjectDisposedException | Object has been disposed. |
| ArgumentOutOfRangeException | *offset* is larger than [`MaximumStreamCapacity`](../RecyclableMemoryStreamManager/MaximumStreamCapacity.md). |
| ArgumentOutOfRangeException | *offset* is larger than [`MaximumStreamCapacity`](../RecyclableMemoryStreamManager.Options/MaximumStreamCapacity.md). |
| ArgumentException | Invalid seek origin. |
| IOException | Attempt to set negative position. |

Expand Down
2 changes: 1 addition & 1 deletion docs/Microsoft.IO/RecyclableMemoryStream/SetLength.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public override void SetLength(long value)

| exception | condition |
| --- | --- |
| ArgumentOutOfRangeException | value is negative or larger than [`MaximumStreamCapacity`](../RecyclableMemoryStreamManager/MaximumStreamCapacity.md). |
| ArgumentOutOfRangeException | value is negative or larger than [`MaximumStreamCapacity`](../RecyclableMemoryStreamManager.Options/MaximumStreamCapacity.md). |
| ObjectDisposedException | Object has been disposed. |

## See Also
Expand Down
39 changes: 5 additions & 34 deletions docs/Microsoft.IO/RecyclableMemoryStream/WriteTo.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RecyclableMemoryStream.WriteTo method (1 of 6)
# RecyclableMemoryStream.WriteTo method (1 of 5)

Writes bytes from the current stream to a destination `byte` array.

Expand Down Expand Up @@ -28,7 +28,7 @@ The entire stream is written to the target array.

---

# RecyclableMemoryStream.WriteTo method (2 of 6)
# RecyclableMemoryStream.WriteTo method (2 of 5)

Synchronously writes this stream's bytes to the argument stream.

Expand Down Expand Up @@ -58,7 +58,7 @@ Important: This does a synchronous write, which may not be desired in some situa

---

# RecyclableMemoryStream.WriteTo method (3 of 6)
# RecyclableMemoryStream.WriteTo method (3 of 5)

Writes bytes from the current stream to a destination `byte` array.

Expand Down Expand Up @@ -87,36 +87,7 @@ public void WriteTo(byte[] buffer, long offset, long count)

---

# RecyclableMemoryStream.WriteTo method (4 of 6)

Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream.

```csharp
public void WriteTo(Stream stream, int offset, int count)
```

| parameter | description |
| --- | --- |
| stream | Destination stream. |
| offset | Offset in source. |
| count | Number of bytes to write. |

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | *stream* is null. |
| ArgumentOutOfRangeException | *offset* is less than 0, or *offset* + *count* is beyond this *stream*'s length. |
| ObjectDisposedException | Object has been disposed. |

## See Also

* class [RecyclableMemoryStream](../RecyclableMemoryStream.md)
* namespace [Microsoft.IO](../../Microsoft.IO.RecyclableMemoryStream.md)

---

# RecyclableMemoryStream.WriteTo method (5 of 6)
# RecyclableMemoryStream.WriteTo method (4 of 5)

Synchronously writes this stream's bytes, starting at offset, for count bytes, to the argument stream.

Expand Down Expand Up @@ -145,7 +116,7 @@ public void WriteTo(Stream stream, long offset, long count)

---

# RecyclableMemoryStream.WriteTo method (6 of 6)
# RecyclableMemoryStream.WriteTo method (5 of 5)

Writes bytes from the current stream to a destination `byte` array.

Expand Down
Loading

0 comments on commit 6e154dd

Please sign in to comment.