Skip to content

Commit

Permalink
test: increase coverage for exceptions
Browse files Browse the repository at this point in the history
Signed-off-by: Shiwei Zhang <[email protected]>
  • Loading branch information
shizhMSFT committed Jan 11, 2024
1 parent 30ff1c6 commit c35e717
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public InvalidDescriptorSizeException()
{
}

public InvalidDescriptorSizeException(string message)
public InvalidDescriptorSizeException(string? message)
: base(message)
{
}

public InvalidDescriptorSizeException(string message, Exception inner)
public InvalidDescriptorSizeException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrasProject.Oras/Content/MismatchedDigestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public MismatchedDigestException()
{
}

public MismatchedDigestException(string message)
public MismatchedDigestException(string? message)
: base(message)
{
}

public MismatchedDigestException(string message, Exception inner)
public MismatchedDigestException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrasProject.Oras/Exceptions/AlreadyExistsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public AlreadyExistsException()
{
}

public AlreadyExistsException(string message)
public AlreadyExistsException(string? message)
: base(message)
{
}

public AlreadyExistsException(string message, Exception inner)
public AlreadyExistsException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrasProject.Oras/Exceptions/InvalidDigestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public InvalidDigestException()
{
}

public InvalidDigestException(string message)
public InvalidDigestException(string? message)
: base(message)
{
}

public InvalidDigestException(string message, Exception inner)
public InvalidDigestException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrasProject.Oras/Exceptions/InvalidReferenceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public InvalidReferenceException()
{
}

public InvalidReferenceException(string message)
public InvalidReferenceException(string? message)
: base(message)
{
}

public InvalidReferenceException(string message, Exception inner)
public InvalidReferenceException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/OrasProject.Oras/Exceptions/NotFoundException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public NotFoundException()
{
}

public NotFoundException(string message)
public NotFoundException(string? message)
: base(message)
{
}

public NotFoundException(string message, Exception inner)
public NotFoundException(string? message, Exception? inner)
: base(message, inner)
{
}
Expand Down
36 changes: 36 additions & 0 deletions tests/OrasProject.Oras.Tests/Content/ExceptionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using OrasProject.Oras.Content;
using Xunit;

namespace OrasProject.Oras.Tests.Content;

public class ExceptionTest
{
[Fact]
public async Task InvalidDescriptorSizeException()
{
await Assert.ThrowsAsync<InvalidDescriptorSizeException>(() => throw new InvalidDescriptorSizeException());
await Assert.ThrowsAsync<InvalidDescriptorSizeException>(() => throw new InvalidDescriptorSizeException("Invalid descriptor size"));
await Assert.ThrowsAsync<InvalidDescriptorSizeException>(() => throw new InvalidDescriptorSizeException("Invalid descriptor size", null));
}

[Fact]
public async Task MismatchedDigestException()
{
await Assert.ThrowsAsync<MismatchedDigestException>(() => throw new MismatchedDigestException());
await Assert.ThrowsAsync<MismatchedDigestException>(() => throw new MismatchedDigestException("Mismatched digest"));
await Assert.ThrowsAsync<MismatchedDigestException>(() => throw new MismatchedDigestException("Mismatched digest", null));
}
}
52 changes: 52 additions & 0 deletions tests/OrasProject.Oras.Tests/Exceptions/ExceptionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright The ORAS Authors.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using OrasProject.Oras.Exceptions;
using Xunit;

namespace OrasProject.Oras.Tests.Exceptions;

public class ExceptionTest
{
[Fact]
public async Task AlreadyExistsException()
{
await Assert.ThrowsAsync<AlreadyExistsException>(() => throw new AlreadyExistsException());
await Assert.ThrowsAsync<AlreadyExistsException>(() => throw new AlreadyExistsException("Already exists"));
await Assert.ThrowsAsync<AlreadyExistsException>(() => throw new AlreadyExistsException("Already exists", null));
}

[Fact]
public async Task InvalidDigestException()
{
await Assert.ThrowsAsync<InvalidDigestException>(() => throw new InvalidDigestException());
await Assert.ThrowsAsync<InvalidDigestException>(() => throw new InvalidDigestException("Invalid digest"));
await Assert.ThrowsAsync<InvalidDigestException>(() => throw new InvalidDigestException("Invalid digest", null));
}

[Fact]
public async Task InvalidReferenceException()
{
await Assert.ThrowsAsync<InvalidReferenceException>(() => throw new InvalidReferenceException());
await Assert.ThrowsAsync<InvalidReferenceException>(() => throw new InvalidReferenceException("Invalid reference"));
await Assert.ThrowsAsync<InvalidReferenceException>(() => throw new InvalidReferenceException("Invalid reference", null));
}

[Fact]
public async Task NotFoundException()
{
await Assert.ThrowsAsync<NotFoundException>(() => throw new NotFoundException());
await Assert.ThrowsAsync<NotFoundException>(() => throw new NotFoundException("Not found"));
await Assert.ThrowsAsync<NotFoundException>(() => throw new NotFoundException("Not found", null));
}
}

0 comments on commit c35e717

Please sign in to comment.