Skip to content

Commit

Permalink
Taggeds metapackage: Setup project files / Update the tests to NUnit 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Feb 11, 2024
1 parent 8fd7eac commit 8b0f35a
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 80 deletions.
15 changes: 11 additions & 4 deletions src/core-taggeds/Taggeds.Tests/Taggeds.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<Authors>Andrei Sergeev, Pavel Moskovoy</Authors>
<Copyright>Copyright © 2020-2023 Andrei Sergeev, Pavel Moskovoy</Copyright>
<RootNamespace>PrimeFuncPack.Core.Tests</RootNamespace>
<AssemblyName>PrimeFuncPack.Core.Taggeds.Tests</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="PrimeFuncPack.UnitTest.Data" Version="3.1.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Optional_ToResult_SourceOptionalIsPresent_ExpectSuccessResultOfSourc
var actual = sourceOptional.ToResult();
var expected = Result<string?, Unit>.Success(sourceValue);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -31,6 +31,6 @@ public void Optional_ToResult_SourceOptionalIsAbsent_ExpectFailureResultOfUnit()
var actual = sourceOptional.ToResult();
var expected = Result<SomeRecord, Unit>.Failure(Unit.Value);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Optional_ToTaggedUnion_OptionalIsPresent_ExpectActualIsFirst(
var actual = optional.ToTaggedUnion();

var expected = TaggedUnion<object?, Unit>.First(sourceValue);
Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -25,6 +25,6 @@ public void Optional_ToTaggedUnion_OptionalIsAbsent_ExpectActualIsSecond()
var actual = optional.ToTaggedUnion();

var expected = TaggedUnion<RefType, Unit>.Second(Unit.Value);
Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void Result_ToOptional_SourceResultIsDefault_ExpectAbsent()
var actual = sourceResult.ToOptional();
var expected = Optional<SomeRecord?>.Absent;

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -26,7 +26,7 @@ public void Result_ToOptional_SourceResultIsFailure_ExpectUnionSecondOfSourceFai
var actual = sourceResult.ToOptional();
var expected = Optional<RefType>.Absent;

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -37,7 +37,7 @@ public void Result_ToOptional_SourceResultIsSuccessAndSourceValueIsNull_ExpectPr
var actual = sourceResult.ToOptional();
var expected = Optional<object?>.Present(null);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -49,6 +49,6 @@ public void Result_ToOptional_SourceResultIsSuccessAndSourceValueIsNotNull_Expec
var actual = sourceResult.ToOptional();
var expected = Optional<RefType>.Present(sourceValue);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public void Result_ToTaggedUnion_SourceResultIsDefault_ExpectUnionSecondOfDefaul
Result<RefType?, StructType> sourceResult)
{
var actual = sourceResult.ToTaggedUnion();
var expected = TaggedUnion<RefType?, StructType>.Second(default(StructType));
var expected = TaggedUnion<RefType?, StructType>.Second(default);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -26,7 +26,7 @@ public void Result_ToTaggedUnion_SourceResultIsFailure_ExpectUnionSecondOfSource
var actual = sourceResult.ToTaggedUnion();
var expected = TaggedUnion<RefType, StructType>.Second(SomeTextStructType);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -37,7 +37,7 @@ public void Result_ToTaggedUnion_SourceResultIsSuccessAndSourceValueIsNull_Expec
var actual = sourceResult.ToTaggedUnion();
var expected = TaggedUnion<RefType?, StructType>.First(null);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -48,6 +48,6 @@ public void Result_ToTaggedUnion_SourceResultIsSuccessAndSourceValueIsNotNull_Ex
var actual = sourceResult.ToTaggedUnion();
var expected = TaggedUnion<RefType, StructType>.First(PlusFifteenIdRefType);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TaggedUnion_ToOptional_UnionIsFirst_ExpectPresent(
var actual = union.ToOptional();

var expected = Optional.Present(sourceValue);
Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -25,7 +25,7 @@ public void TaggedUnion_ToOptional_UnionIsDefault_ExpectAbsent()
var actual = union.ToOptional();

var expected = Optional.Absent<StructType>();
Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -35,6 +35,6 @@ public void TaggedUnion_ToOptional_UnionIsSecond_ExpectAbsent()
var actual = union.ToOptional();

var expected = Optional.Absent<RefType>();
Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void TaggedUnion_ToResult_SourceUnionIsDefault_ExpectDefaultResult()
var actual = sourceUnion.ToResult();
var expected = default(Result<SomeRecord, StructType>);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -27,7 +27,7 @@ public void TaggedUnion_ToResult_SourceUnionIsSecond_ExpectFailureResult()
var actual = sourceUnion.ToResult();
var expected = Result<RefType?, SomeError>.Failure(sourceValue);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -38,7 +38,7 @@ public void TaggedUnion_ToResult_SourceUnionIsFirstAndSourceValueIsNull_ExpectSu
var actual = sourceUnion.ToResult();
var expected = Result<RefType?, StructType>.Success(null);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}

[Test]
Expand All @@ -53,6 +53,6 @@ public void TaggedUnion_ToResult_SourceUnionIsFirstAndSourceValueIsNotNull_Expec
var actual = sourceUnion.ToResult();
var expected = Result<SomeRecord, SomeError>.Success(sourceValue);

Assert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected));
}
}
8 changes: 2 additions & 6 deletions src/core-taggeds/Taggeds.Tests/TestData/SomeError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@

namespace PrimeFuncPack.Core.Tests;

internal readonly struct SomeError
internal readonly struct SomeError(int errorCode)
{
private readonly int errorCode;

public SomeError(int errorCode)
=>
this.errorCode = errorCode;
private readonly int errorCode = errorCode;

public bool Equals(SomeError other)
=>
Expand Down
100 changes: 50 additions & 50 deletions src/core-taggeds/Taggeds.Tests/TestData/TestDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,76 @@

namespace PrimeFuncPack.Core.Tests;

internal static class TestDataSource
{
public static IEnumerable<object[]> SuccessNullTestSource
=>
new Result<RefType?, StructType>[]
{
internal static class TestDataSource
{
public static IEnumerable<object[]> SuccessNullTestSource
=>
new Result<RefType?, StructType>[]
{
Result.Success<RefType?>(null).With<StructType>(),
Result.Success<RefType?>(null),
Result<RefType?, StructType>.Success(null),
new Result<RefType?, StructType>(null),
new(null),
null
}
.ToTestSource();
}
.ToTestSource();

public static IEnumerable<object[]> SuccessPlusFifteenIdRefTypeTestSource
=>
new Result<RefType, StructType>[]
{
public static IEnumerable<object[]> SuccessPlusFifteenIdRefTypeTestSource
=>
new Result<RefType, StructType>[]
{
Result.Success(PlusFifteenIdRefType).With<StructType>(),
Result.Success(PlusFifteenIdRefType),
Result<RefType, StructType>.Success(PlusFifteenIdRefType),
new Result<RefType, StructType>(PlusFifteenIdRefType),
new(PlusFifteenIdRefType),
PlusFifteenIdRefType
}
.ToTestSource();
}
.ToTestSource();

public static IEnumerable<object[]> FailureDefaultTestSource
=>
new Result<RefType, StructType>[]
{
public static IEnumerable<object[]> FailureDefaultTestSource
=>
new Result<RefType, StructType>[]
{
default,
new Result<RefType, StructType>(),
new Result<RefType, StructType>(default(StructType)),
new(),
new(default(StructType)),
Result.Failure(default(StructType)),
Result.Failure(default(StructType)).With<RefType>(),
Result<RefType, StructType>.Failure(default)
}
.ToTestSource();
public static IEnumerable<object[]> FailureSomeTextStructTypeTestSource
=>
new Result<RefType, StructType>[]
{
new Result<RefType, StructType>(SomeTextStructType),
}
.ToTestSource();

public static IEnumerable<object[]> FailureSomeTextStructTypeTestSource
=>
new Result<RefType, StructType>[]
{
new(SomeTextStructType),
Result.Failure(SomeTextStructType),
Result.Failure(SomeTextStructType).With<RefType>(),
Result<RefType, StructType>.Failure(SomeTextStructType)
}
.ToTestSource();
}
.ToTestSource();

public static IEnumerable<object?[]> ObjectNullableTestSource
=>
new object?[]
{
public static IEnumerable<object?[]> ObjectNullableTestSource
=>
new object?[]
{
null,
new object(),
new(),
MinusFifteen,
PlusFifteenIdRefType,
SomeTextStructType
}
.ToNullableTestSource();
private static IEnumerable<object[]> ToTestSource<T>(
this IEnumerable<T> source)
where T : notnull
=>
source.Select(
item => new object[] { item });
}
.ToNullableTestSource();

private static IEnumerable<object[]> ToTestSource<T>(
this IEnumerable<T> source)
where T : notnull
=>
source.Select(
item => new object[] { item });

private static IEnumerable<object?[]> ToNullableTestSource(this IEnumerable<object?> source)
=>
source.Select(v => new[] { v });
}
private static IEnumerable<object?[]> ToNullableTestSource(this IEnumerable<object?> source)
=>
source.Select(v => new[] { v });
}
1 change: 1 addition & 0 deletions src/core-taggeds/Taggeds/Taggeds.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
Expand Down

0 comments on commit 8b0f35a

Please sign in to comment.