Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix Position getter of uninitiliazed LazyFileStream returning 0 #211

Merged
merged 3 commits into from
Jul 15, 2024
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ dotnet_naming_symbols.non_field_members.required_modifiers =
### .NET SDK
dotnet_diagnostic.CA1303.severity = none # We don't translate exception and log messages from English
dotnet_diagnostic.SA1025.severity = none # Allow spaces in comments to structure info
dotnet_diagnostic.IDE0028.severity = suggestion # Simplify collection initialization
dotnet_diagnostic.IDE0045.severity = suggestion # Simplify ifs
dotnet_diagnostic.IDE0046.severity = suggestion # Simplify ifs

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: "Build"
uses: ./.github/workflows/build.yml
with:
dotnet_version: '8.0.100'
dotnet_version: '8.0.303'

# Preview release on push to main only
# Stable release on version tag push only
Expand All @@ -25,7 +25,7 @@ jobs:
needs: build
uses: ./.github/workflows/deploy.yml
with:
dotnet_version: '8.0.100'
dotnet_version: '8.0.303'
azure_nuget_feed: 'https://pkgs.dev.azure.com/SceneGate/SceneGate/_packaging/SceneGate-Preview/nuget/v3/index.json'
secrets:
nuget_preview_token: "az" # Dummy values as we use Azure DevOps only
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
with:
dotnet-version: ${{ inputs.dotnet_version }}

- name: "Setup .NET 6.0 SDK"
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.424'

- name: "Build and test"
run: dotnet run --project build/orchestrator -- --target=Default --dotnet-configuration=Release
env:
Expand Down
21 changes: 20 additions & 1 deletion src/Yarhl.UnitTests/IO/StreamFormat/LazyFileStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,29 @@ public void ConstructorSetFileLengthOrZero()
}

[Test]
public void GetPositionWithoutInitializeReturnsZero()
public void GetPositionWithoutInitializeReturnsSameAsSet()
{
using var stream = new LazyFileStream(tempFile, FileOpenMode.ReadWrite);
Assert.That(stream.Position, Is.EqualTo(0));

stream.Position = 0x42;
Assert.That(stream.BaseStream, Is.Null);
Assert.That(stream.Position, Is.EqualTo(0x42));
}

[Test]
public void FileOpenedWithInitialPosition()
{
byte[] fileContent = { 0xFF, 0x42 };
File.WriteAllBytes(tempFile, fileContent);
using var stream = new LazyFileStream(tempFile, FileOpenMode.ReadWrite);
stream.Position = 1;

Assert.That(stream.BaseStream, Is.Null);
byte actual = (byte)stream.ReadByte();

Assert.That(actual, Is.EqualTo(fileContent[1]));
Assert.That(stream.Position, Is.EqualTo(2));
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/Yarhl/IO/StreamFormat/LazyFileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public LazyFileStream(string path, FileOpenMode mode)
/// <inheritdoc/>
public override long Position
{
get => BaseStream?.Position ?? 0;
get => BaseStream?.Position ?? initialPosition;
set
{
if (BaseStream is null) {
Expand Down
Loading