-
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.
1. xUnit Tests added for AltaSoft.DomainPrimitives assembly
2. xUnit Tests added for AltaSoft.DomainPrimitives.Abstractions assembly
- Loading branch information
1 parent
6b6b81f
commit facd0fc
Showing
18 changed files
with
677 additions
and
1 deletion.
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
3 changes: 3 additions & 0 deletions
3
src/AltaSoft.DomainPrimitives.Abstractions/AssemblyAttributes.cs
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,3 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("AltaSoft.DomainPrimitives.Tests")] |
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
30 changes: 30 additions & 0 deletions
30
tests/AltaSoft.DomainPrimitives.Tests/AltaSoft.DomainPrimitives.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>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AltaSoft.DomainPrimitives.Abstractions\AltaSoft.DomainPrimitives.Abstractions.csproj" /> | ||
<ProjectReference Include="..\..\src\AltaSoft.DomainPrimitives\AltaSoft.DomainPrimitives.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using AltaSoft.DomainPrimitives.Abstractions; | ||
|
||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the AsciiString class. | ||
/// </summary> | ||
public class AsciiStringTests | ||
{ | ||
[Fact] | ||
public void Validate_ValidAsciiString_DoesNotThrowException() | ||
{ | ||
// Arrange | ||
const string validString = "Hello"; | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => AsciiString.Validate(validString)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Validate_InvalidAsciiString_ThrowsException() | ||
{ | ||
// Arrange | ||
const string invalidString = "Hello😊"; | ||
|
||
// Act & Assert | ||
Assert.Throws<InvalidDomainValueException>(() => AsciiString.Validate(invalidString)); | ||
} | ||
|
||
[Fact] | ||
public void Default_ReturnsEmptyString() | ||
{ | ||
// Act | ||
var defaultValue = AsciiString.Default; | ||
|
||
// Assert | ||
Assert.Equal(string.Empty, defaultValue); | ||
} | ||
} |
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,47 @@ | ||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the GDay class. | ||
/// </summary> | ||
public class GDayTests | ||
{ | ||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(15)] | ||
[InlineData(31)] | ||
public void Validate_ShouldNotThrowException_WhenValidDateOnly(int day) | ||
{ | ||
// Arrange | ||
var validDateOnly = new DateOnly(2000, 1, day); | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => GDay.Validate(validDateOnly)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Default_ShouldReturnDefaultDateOnly() | ||
{ | ||
// Act | ||
var defaultDateOnly = GDay.Default; | ||
|
||
// Assert | ||
Assert.Equal(default, defaultDateOnly); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, "01")] | ||
[InlineData(15, "15")] | ||
[InlineData(31, "31")] | ||
public void ToString_ShouldReturnFormattedString(int day, string expectedString) | ||
{ | ||
// Arrange | ||
var dateOnly = new DateOnly(2000, 1, day); | ||
|
||
// Act | ||
var result = GDay.ToString(dateOnly); | ||
|
||
// Assert | ||
Assert.Equal(expectedString, result); | ||
} | ||
} |
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,49 @@ | ||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// This class contains unit tests for the GMonthDay class. | ||
/// </summary> | ||
public class GMonthDayTests | ||
{ | ||
[Theory] | ||
[InlineData(1, 1)] | ||
[InlineData(12, 31)] | ||
[InlineData(2, 28)] | ||
[InlineData(3, 15)] | ||
public void Validate_ShouldNotThrowException_WhenValidDateOnly(int month, int day) | ||
{ | ||
// Arrange | ||
var validDateOnly = new DateOnly(2000, month, day); | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => GMonthDay.Validate(validDateOnly)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Default_ShouldReturnDefaultDateOnly() | ||
{ | ||
// Act | ||
var defaultDateOnly = GMonthDay.Default; | ||
|
||
// Assert | ||
Assert.Equal(default, defaultDateOnly); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, 1, "01-01")] | ||
[InlineData(12, 31, "12-31")] | ||
[InlineData(2, 28, "02-28")] | ||
[InlineData(3, 15, "03-15")] | ||
public void ToString_ShouldReturnFormattedString(int month, int day, string expectedString) | ||
{ | ||
// Arrange | ||
var dateOnly = new DateOnly(2000, month, day); | ||
|
||
// Act | ||
var result = GMonthDay.ToString(dateOnly); | ||
|
||
// Assert | ||
Assert.Equal(expectedString, result); | ||
} | ||
} |
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,47 @@ | ||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the GMonth class. | ||
/// </summary> | ||
public class GMonthTests | ||
{ | ||
[Theory] | ||
[InlineData(1)] | ||
[InlineData(6)] | ||
[InlineData(12)] | ||
public void Validate_ShouldNotThrowException_WhenValidDateOnly(int month) | ||
{ | ||
// Arrange | ||
var validDateOnly = new DateOnly(2000, month, 1); | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => GMonth.Validate(validDateOnly)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Default_ShouldReturnDefaultDateOnly() | ||
{ | ||
// Act | ||
var defaultDateOnly = GMonth.Default; | ||
|
||
// Assert | ||
Assert.Equal(default, defaultDateOnly); | ||
} | ||
|
||
[Theory] | ||
[InlineData(1, "01")] | ||
[InlineData(6, "06")] | ||
[InlineData(12, "12")] | ||
public void ToString_ShouldReturnFormattedString(int month, string expectedString) | ||
{ | ||
// Arrange | ||
var dateOnly = new DateOnly(2000, month, 1); | ||
|
||
// Act | ||
var result = GMonth.ToString(dateOnly); | ||
|
||
// Assert | ||
Assert.Equal(expectedString, result); | ||
} | ||
} |
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,49 @@ | ||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the GYearMonth class. | ||
/// </summary> | ||
public class GYearMonthTests | ||
{ | ||
[Theory] | ||
[InlineData(2022, 1)] | ||
[InlineData(2024, 12)] | ||
[InlineData(2024, 2)] | ||
[InlineData(2023, 3)] | ||
public void Validate_ShouldNotThrowException_WhenValidDateOnly(int year, int month) | ||
{ | ||
// Arrange | ||
var validDateOnly = new DateOnly(year, month, 1); | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => GYearMonth.Validate(validDateOnly)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Default_ShouldReturnDefaultDateOnly() | ||
{ | ||
// Act | ||
var defaultDateOnly = GYearMonth.Default; | ||
|
||
// Assert | ||
Assert.Equal(default, defaultDateOnly); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2022, 1, "2022-01")] | ||
[InlineData(2024, 12, "2024-12")] | ||
[InlineData(2024, 2, "2024-02")] | ||
[InlineData(2023, 3, "2023-03")] | ||
public void ToString_ShouldReturnFormattedString(int year, int month, string expectedString) | ||
{ | ||
// Arrange | ||
var dateOnly = new DateOnly(year, month, 1); | ||
|
||
// Act | ||
var result = GYearMonth.ToString(dateOnly); | ||
|
||
// Assert | ||
Assert.Equal(expectedString, result); | ||
} | ||
} |
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,48 @@ | ||
namespace AltaSoft.DomainPrimitives.Tests; | ||
|
||
/// <summary> | ||
/// Contains unit tests for the GYear class. | ||
/// </summary> | ||
public class GYearTests | ||
{ | ||
[Theory] | ||
[InlineData(2022)] | ||
[InlineData(2024)] | ||
[InlineData(2023)] | ||
public void Validate_ShouldNotThrowException_WhenValidDateOnly(int year) | ||
{ | ||
// Arrange | ||
var validDateOnly = new DateOnly(year, 1, 1); | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => GYear.Validate(validDateOnly)); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void Default_ShouldReturnDefaultDateOnly() | ||
{ | ||
// Act | ||
var defaultDateOnly = GYear.Default; | ||
|
||
// Assert | ||
Assert.Equal(default, defaultDateOnly); | ||
} | ||
|
||
[Theory] | ||
[InlineData(2022, "2022")] | ||
[InlineData(2024, "2024")] | ||
[InlineData(2024, "2024")] | ||
Check warning on line 35 in tests/AltaSoft.DomainPrimitives.Tests/GYearTests.cs GitHub Actions / build
Check warning on line 35 in tests/AltaSoft.DomainPrimitives.Tests/GYearTests.cs GitHub Actions / build
|
||
[InlineData(2023, "2023")] | ||
public void ToString_ShouldReturnFormattedString(int year, string expectedString) | ||
{ | ||
// Arrange | ||
var dateOnly = new DateOnly(year, 1, 1); | ||
|
||
// Act | ||
var result = GYear.ToString(dateOnly); | ||
|
||
// Assert | ||
Assert.Equal(expectedString, result); | ||
} | ||
} |
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 @@ | ||
global using Xunit; |
Oops, something went wrong.