generated from kasthack-labs/dotnet-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix nullref, add tests, bump package version to 1.0.3
- Loading branch information
Showing
6 changed files
with
151 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace kasthack.NotEmpty.Tests | ||
{ | ||
public class XunitNotEmptyTest : NotEmptyTestBase | ||
{ | ||
public XunitNotEmptyTest() | ||
: base(x => kasthack.NotEmpty.Xunit.NotEmptyExtensions.NotEmpty(x)) | ||
{ | ||
} | ||
} | ||
|
||
public class NunitNotEmptyTest : NotEmptyTestBase | ||
{ | ||
public NunitNotEmptyTest() | ||
: base(x => kasthack.NotEmpty.Nunit.NotEmptyExtensions.NotEmpty(x)) | ||
{ | ||
} | ||
} | ||
|
||
public class MsTestNotEmptyTest : NotEmptyTestBase | ||
{ | ||
public MsTestNotEmptyTest() | ||
: base(x => kasthack.NotEmpty.MsTest.NotEmptyExtensions.NotEmpty(x)) | ||
{ | ||
} | ||
} | ||
|
||
public class RawNotEmptyTest : NotEmptyTestBase | ||
{ | ||
public RawNotEmptyTest() | ||
: base(x => kasthack.NotEmpty.Raw.NotEmptyExtensions.NotEmpty(x)) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
namespace kasthack.NotEmpty.Tests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using global::Xunit; | ||
|
||
public abstract class NotEmptyTestBase | ||
{ | ||
private readonly Action<object?> action; | ||
|
||
public NotEmptyTestBase(Action<object?> action) => this.action = action; | ||
|
||
[Fact] | ||
public void NullThrows() => Assert.ThrowsAny<Exception>(() => this.action(null)); | ||
|
||
[Fact] | ||
public void ObjectWorks() => this.action(new object()); | ||
|
||
[Fact] | ||
public void ObjectWithPropsWorks() => this.action(new { Value = 1 }); | ||
|
||
[Fact] | ||
public void ObjectWithDefaultThrows() => Assert.ThrowsAny<Exception>(() => this.action(new { Value = 0 })); | ||
|
||
[Fact] | ||
public void NestedObjectWithDefaultThrows() => Assert.ThrowsAny<Exception>(() => this.action(new { Property = new { Value = 0, } })); | ||
|
||
[Fact] | ||
public void PrimitiveWorks() => this.action(1); | ||
|
||
[Fact] | ||
public void ZeroThrows() => Assert.ThrowsAny<Exception>(() => this.action(0)); | ||
|
||
[Fact] | ||
public void EmptyArrayThrows() => Assert.ThrowsAny<Exception>(() => this.action(new object[] { })); | ||
|
||
[Fact] | ||
public void EmptyListThrows() => Assert.ThrowsAny<Exception>(() => this.action(new List<object>())); | ||
|
||
[Fact] | ||
public void ListWorks() => this.action(new List<object> { new object() }); | ||
|
||
[Fact] | ||
public void ArrayWorks() => this.action(new object[] { new object() }); | ||
|
||
[Fact] | ||
public void ArrayWithDefaultThrows() => Assert.ThrowsAny<Exception>(() => this.action(new object[] { 1, 0 })); | ||
|
||
[Fact] | ||
public void ArrayWithNullThrows() => Assert.ThrowsAny<Exception>(() => this.action(new object?[] { null, new object() })); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/kasthack.NotEmpty.Tests/kasthack.NotEmpty.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.1.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\kasthack.NotEmpty.MsTest\kasthack.NotEmpty.MsTest.csproj" /> | ||
<ProjectReference Include="..\kasthack.NotEmpty.Nunit\kasthack.NotEmpty.Nunit.csproj" /> | ||
<ProjectReference Include="..\kasthack.NotEmpty.Raw\kasthack.NotEmpty.Raw.csproj" /> | ||
<ProjectReference Include="..\kasthack.NotEmpty.Xunit\kasthack.NotEmpty.Xunit.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters