Skip to content

Commit

Permalink
Added test console to unit test the behavior of the code generated by…
Browse files Browse the repository at this point in the history
… the generator

Fixed a bug where sequences where incorrectly compared
  • Loading branch information
MooVC committed Nov 10, 2024
1 parent e10741c commit eddc6d2
Show file tree
Hide file tree
Showing 39 changed files with 1,542 additions and 41 deletions.
14 changes: 13 additions & 1 deletion Valuify.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Valuify", "src\Valuify\Valuify.csproj", "{38C8F251-DED6-4E26-AB2B-978657F2D314}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valuify.Tests", "src\Valuify.Tests\Valuify.Tests.csproj", "{12488AA0-C4E2-4839-BBF7-0A1547A188FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Valuify.Tests", "src\Valuify.Tests\Valuify.Tests.csproj", "{12488AA0-C4E2-4839-BBF7-0A1547A188FB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Actions", "Actions", "{0D4D9A28-3FD6-4824-8E13-E96B8706D5D5}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -57,6 +57,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Configuration", "Configurat
nuget.config = nuget.config
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valuify.Console", "src\Valuify.Console\Valuify.Console.csproj", "{6BAF1E2F-B993-4CD5-B09B-0014F1E7983B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valuify.Console.Tests", "src\Valuify.Console.Tests\Valuify.Console.Tests.csproj", "{30AF6070-4A2E-4E32-B330-A299C7F841E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -71,6 +75,14 @@ Global
{12488AA0-C4E2-4839-BBF7-0A1547A188FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12488AA0-C4E2-4839-BBF7-0A1547A188FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12488AA0-C4E2-4839-BBF7-0A1547A188FB}.Release|Any CPU.Build.0 = Release|Any CPU
{6BAF1E2F-B993-4CD5-B09B-0014F1E7983B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6BAF1E2F-B993-4CD5-B09B-0014F1E7983B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6BAF1E2F-B993-4CD5-B09B-0014F1E7983B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6BAF1E2F-B993-4CD5-B09B-0014F1E7983B}.Release|Any CPU.Build.0 = Release|Any CPU
{30AF6070-4A2E-4E32-B330-A299C7F841E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30AF6070-4A2E-4E32-B330-A299C7F841E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30AF6070-4A2E-4E32-B330-A299C7F841E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30AF6070-4A2E-4E32-B330-A299C7F841E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
158 changes: 158 additions & 0 deletions src/Valuify.Console.Tests/NestingTests/WhenEqualityIsChecked.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
namespace Valuify.Console.NestingTests;

public abstract class WhenEqualityIsChecked
{
[Fact]
public void GivenIdenticalInstancesThenTheyAreDeemedEqual()
{
// Arrange
var instance1 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex",
};

var instance2 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex",
};

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeTrue();
}

[Fact]
public void GivenADifferentNameThenTheyAreNotDeemedEqual()
{
// Arrange
var instance1 = new Nesting
{
Declaration = "partial class",
Name = "Simple1",
Qualification = "Complex",
};

var instance2 = new Nesting
{
Declaration = "partial class",
Name = "Simple2",
Qualification = "Complex",
};

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeFalse();
}

[Fact]
public void GivenADifferentQualificationThenTheyAreNotDeemedEqual()
{
// Arrange
var instance1 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex1",
};

var instance2 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex2",
};

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeFalse();
}

[Fact]
public void GivenDifferentTypeThenTheyAreDeemedNotEqual()
{
// Arrange
var instance1 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex",
};

var instance2 = new Nesting
{
Declaration = "struct",
Name = "Simple",
Qualification = "Complex",
};

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeFalse();
}

[Fact]
public void GivenOneInstanceIsNullThenTheyAreDeemedNotEqual()
{
// Arrange
var instance = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex",
};

// Act
bool areEqual = AreEqual(instance, default);

// Assert
_ = areEqual.Should().BeFalse();
}

[Fact]
public void GivenBothInstancesAreNullThenTheyAreDeemedEqual()
{
// Arrange
Nesting? instance1 = default;
Nesting? instance2 = default;

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeTrue();
}

[Fact]
public void GivenSameReferenceThenTheyAreDeemedEqual()
{
// Arrange
var instance1 = new Nesting
{
Declaration = "partial class",
Name = "Simple",
Qualification = "Complex",
};

Nesting instance2 = instance1;

// Act
bool areEqual = AreEqual(instance1, instance2);

// Assert
_ = areEqual.Should().BeTrue();
}

private protected abstract bool AreEqual(Nesting? instance1, Nesting? instance2);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Valuify.Console.NestingTests;

using Valuify.Console;

public sealed class WhenEqualityIsCheckedByEquals
: WhenEqualityIsChecked
{
private protected override bool AreEqual(Nesting? instance1, Nesting? instance2)
{
if (instance1 is not null)
{
return instance1.Equals((object?)instance2);
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Valuify.Console.NestingTests;

using Valuify.Console;

public sealed class WhenEqualityIsCheckedByEquatable
: WhenEqualityIsChecked
{
private protected override bool AreEqual(Nesting? instance1, Nesting? instance2)
{
if (instance1 is not null)
{
return instance1.Equals(instance2);
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Valuify.Console.NestingTests;

using Valuify.Console;

public sealed class WhenEqualityIsCheckedByOperator
: WhenEqualityIsChecked
{
private protected override bool AreEqual(Nesting? instance1, Nesting? instance2)
{
return instance1 == instance2;
}
}
Loading

0 comments on commit eddc6d2

Please sign in to comment.