Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Sep 4, 2024
1 parent 2d31633 commit 92c5f8d
Show file tree
Hide file tree
Showing 11 changed files with 673 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Prevent including Equatable.Generator as a dependence
### Requirements

This library requires:

- Target framework .NET Standard 2.0 or greater
- Project C# `LangVersion` 9.0 or higher

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;

namespace Equatable.Attributes;

Expand Down
14 changes: 14 additions & 0 deletions test/Equatable.Entities/Nested.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Equatable.Attributes;

namespace Equatable.Entities;

public class Nested
{
//[Equatable]
public partial class Animal
{
public int Id { get; set; }
public string Name { get; set; }

Check warning on line 11 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 11 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Type { get; set; }

Check warning on line 12 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 12 in test/Equatable.Entities/Nested.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Type' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
}
}
2 changes: 1 addition & 1 deletion test/Equatable.Entities/StatusRecordList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public partial record StatusRecordList(
string? Description,
int DisplayOrder,
bool IsActive,
List<string> Versions
[property: SequenceEquality] List<string> Versions
);
246 changes: 246 additions & 0 deletions test/Equatable.Generator.Tests/Entities/DataTypeTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
using Equatable.Entities;

namespace Equatable.Generator.Tests.Entities;

public class DataTypeTest
{
[Fact]
public void EqualNotNull()
{
var left = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0),
BooleanNull = false,
ShortNull = 2,
LongNull = 200,
FloatNull = 200.20F,
DoubleNull = 300.35,
DecimalNull = 456.12M,
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
GuidNull = Guid.Empty,
TimeSpanNull = TimeSpan.FromHours(1),
DateOnlyNull = new DateOnly(2022, 12, 1),
TimeOnlyNull = new TimeOnly(1, 30, 0),
};

var right = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0),
BooleanNull = false,
ShortNull = 2,
LongNull = 200,
FloatNull = 200.20F,
DoubleNull = 300.35,
DecimalNull = 456.12M,
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
GuidNull = Guid.Empty,
TimeSpanNull = TimeSpan.FromHours(1),
DateOnlyNull = new DateOnly(2022, 12, 1),
TimeOnlyNull = new TimeOnly(1, 30, 0),
};

var isEqual = left.Equals(right);
isEqual.Should().BeTrue();

// check operator ==
isEqual = left == right;
isEqual.Should().BeTrue();

}

[Fact]
public void EqualNulls()
{
var left = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0)
};

var right = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0)
};

var isEqual = left.Equals(right);
isEqual.Should().BeTrue();

// check operator ==
isEqual = left == right;
isEqual.Should().BeTrue();

}

[Fact]
public void NotEqualNotNull()
{
var left = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0),
BooleanNull = false,
ShortNull = 2,
LongNull = 200,
FloatNull = 200.20F,
DoubleNull = 300.35,
DecimalNull = 456.12M,
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
GuidNull = Guid.Empty,
TimeSpanNull = TimeSpan.FromHours(1),
DateOnlyNull = new DateOnly(2022, 12, 1),
TimeOnlyNull = new TimeOnly(1, 30, 0),
};

var right = new DataType
{
Id = 2,
Name = "Test2",
Boolean = true,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0),
BooleanNull = false,
ShortNull = 2,
LongNull = 200,
FloatNull = 200.20F,
DoubleNull = 300.35,
DecimalNull = 456.12M,
DateTimeNull = new DateTime(2024, 4, 1, 8, 0, 0),
DateTimeOffsetNull = new DateTimeOffset(2024, 4, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
GuidNull = Guid.Empty,
TimeSpanNull = TimeSpan.FromHours(1),
DateOnlyNull = new DateOnly(2022, 12, 1),
TimeOnlyNull = new TimeOnly(1, 30, 0),
};

var isEqual = left.Equals(right);
isEqual.Should().BeFalse();

// check operator !=
isEqual = left != right;
isEqual.Should().BeTrue();

}

[Fact]
public void NotEqualNulls()
{
var left = new DataType
{
Id = 1,
Name = "Test1",
Boolean = false,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0)
};

var right = new DataType
{
Id = 2,
Name = "Test2",
Boolean = true,
Short = 2,
Long = 200,
Float = 200.20F,
Double = 300.35,
Decimal = 456.12M,
DateTime = new DateTime(2024, 5, 1, 8, 0, 0),
DateTimeOffset = new DateTimeOffset(2024, 5, 1, 8, 0, 0, TimeSpan.FromHours(-6)),
Guid = Guid.Empty,
TimeSpan = TimeSpan.FromHours(1),
DateOnly = new DateOnly(2022, 12, 1),
TimeOnly = new TimeOnly(1, 30, 0)
};

var isEqual = left.Equals(right);
isEqual.Should().BeFalse();

// check operator !=
isEqual = left != right;
isEqual.Should().BeTrue();

}
}
Loading

0 comments on commit 92c5f8d

Please sign in to comment.