Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed generic type declaration. #55

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions src/Fluxera.ValueObject/PrimitiveValueObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
/// <typeparam name="TValue">The type of the value.</typeparam>
[PublicAPI]
[TypeConverter(typeof(PrimitiveValueObjectConverter))]
public abstract class PrimitiveValueObject<TValueObject, TValue> : IComparable<TValueObject>, IEquatable<TValueObject>
public abstract class PrimitiveValueObject<TValueObject, TValue> :
IComparable<PrimitiveValueObject<TValueObject, TValue>>,
IEquatable<PrimitiveValueObject<TValueObject, TValue>>
where TValueObject : PrimitiveValueObject<TValueObject, TValue>
where TValue : IComparable<TValue>, IEquatable<TValue>
{
Expand Down Expand Up @@ -65,7 +67,7 @@ public static TValueObject Create(TValue value)
}

/// <inheritdoc />
public bool Equals(TValueObject other)
public bool Equals(PrimitiveValueObject<TValueObject, TValue> other)
{
return this.Equals(other as object);
}
Expand All @@ -78,7 +80,7 @@ public sealed override bool Equals(object obj)
return false;
}

if(object.ReferenceEquals(this, obj))
if(ReferenceEquals(this, obj))
{
return true;
}
Expand All @@ -90,7 +92,7 @@ public sealed override bool Equals(object obj)
}

/// <inheritdoc />
public int CompareTo(TValueObject other)
public int CompareTo(PrimitiveValueObject<TValueObject, TValue> other)
{
return (this.Value, other.Value) switch
{
Expand Down Expand Up @@ -122,6 +124,50 @@ public int CompareTo(TValueObject other)
return !(left == right);
}

/// <summary>
/// Compares the given primitive value object instances with the lower-than operator.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator <(PrimitiveValueObject<TValueObject, TValue> left, PrimitiveValueObject<TValueObject, TValue> right)
{
return left.CompareTo(right) < 0;
}

/// <summary>
/// Compares the given primitive value object instances with the lower-than-equal operator.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator <=(PrimitiveValueObject<TValueObject, TValue> left, PrimitiveValueObject<TValueObject, TValue> right)
{
return left.CompareTo(right) <= 0;
}

/// <summary>
/// Compares the given primitive value object instances with the greater-than operator.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >(PrimitiveValueObject<TValueObject, TValue> left, PrimitiveValueObject<TValueObject, TValue> right)
{
return left.CompareTo(right) > 0;
}

/// <summary>
/// Compares the given primitive value object instances with the greater-than-equal operator.
/// </summary>
/// <param name="left"></param>
/// <param name="right"></param>
/// <returns></returns>
public static bool operator >=(PrimitiveValueObject<TValueObject, TValue> left, PrimitiveValueObject<TValueObject, TValue> right)
{
return left.CompareTo(right) >= 0;
}

/// <summary>
/// Converts the value object implicitly to its primitive value.
/// </summary>
Expand All @@ -132,10 +178,10 @@ public static implicit operator TValue(PrimitiveValueObject<TValueObject, TValue
}

/// <summary>
/// Converts the primitive value explicitly to its value object.
/// Converts the primitive value implicitly to its value object.
/// </summary>
/// <param name="value"></param>
public static explicit operator PrimitiveValueObject<TValueObject, TValue>(TValue value)
public static implicit operator PrimitiveValueObject<TValueObject, TValue>(TValue value)
{
return Create(value);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Fluxera.ValueObject.LiteDB.UnitTests.Model
namespace Fluxera.ValueObject.EntityFrameworkCore.UnitTests.Model
{
public sealed class Age : PrimitiveValueObject<Age, int>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace Fluxera.ValueObject.EntityFrameworkCore.UnitTests.Model
{
using System.ComponentModel.DataAnnotations;
using Fluxera.ValueObject.LiteDB.UnitTests.Model;

public class Person
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using Bogus;
using Fluxera.ValueObject.LiteDB.UnitTests.Model;

public static class PersonFactory
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using FluentAssertions;
using Fluxera.ValueObject.EntityFrameworkCore.UnitTests.Model;
using Fluxera.ValueObject.LiteDB.UnitTests.Model;
using Microsoft.EntityFrameworkCore;
using NUnit.Framework;

Expand Down Expand Up @@ -37,7 +36,7 @@ public async Task ShouldFindByPrimitiveValueObjectEquals()
linqFilterResult.Should().NotBeNull();
}

[Ignore("Fix this later")]
[Ignore("Fix this later. Drop .NET 7 in November?")]
[Test]
public async Task ShouldFindByValueEquals()
{
Expand All @@ -48,7 +47,6 @@ public async Task ShouldFindByValueEquals()
linqFilterResult.Should().NotBeNull();
}

[Ignore("Fix this later")]
[Test]
public async Task ShouldFindByPrimitiveValueObjectComparison()
{
Expand All @@ -59,7 +57,6 @@ public async Task ShouldFindByPrimitiveValueObjectComparison()
linqFilterResult.Should().NotBeNull();
}

[Ignore("Fix this later")]
[Test]
public async Task ShouldFindByValueComparison()
{
Expand Down