< Summary

Information
Class: NGql.Core.EnumValue
Assembly: NGql.Core
File(s): /home/runner/work/NGql/NGql/src/Core/EnumValue.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 64
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Value()100%11100%
.ctor(...)100%66100%
ToString()100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
op_LessThan(...)100%11100%
op_GreaterThan(...)100%11100%
op_LessThanOrEqual(...)100%11100%
op_GreaterThanOrEqual(...)100%11100%
CompareTo(...)100%44100%
CompareTo(...)100%11100%
Equals(...)100%11100%
Equals(...)100%11100%
GetHashCode()100%11100%

File(s)

/home/runner/work/NGql/NGql/src/Core/EnumValue.cs

#LineLine coverage
 1namespace NGql.Core;
 2
 3/// <summary>
 4/// Wraps a GraphQL enum value so it renders unquoted (e.g. <c>role:ADMIN</c>) instead of as
 5/// a string literal. Pass an <see cref="EnumValue"/> as an argument value to opt out of
 6/// string quoting in the rendered query.
 7/// </summary>
 8public readonly struct EnumValue : IComparable, IComparable<EnumValue>, IEquatable<EnumValue>
 9{
 10    /// <summary>The enum identifier as it will appear in the rendered GraphQL.</summary>
 24611    public string Value { get; }
 12
 13    /// <summary>
 14    /// Creates an <see cref="EnumValue"/> from a non-empty string identifier or a CLR
 15    /// <see cref="System.Enum"/> instance (its <c>ToString()</c> becomes the rendered value).
 16    /// </summary>
 17    /// <param name="value">A non-empty string or an <see cref="Enum"/> instance.</param>
 18    /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
 19    /// <exception cref="ArgumentException"><paramref name="value"/> is an empty/whitespace string, an
 20    /// undefined or unnamed-<c>[Flags]</c> enum value, or an unsupported type.</exception>
 21    public EnumValue(object value)
 22    {
 22823        ArgumentNullException.ThrowIfNull(value);
 22224        Value = value switch
 22225        {
 37526            string str when !string.IsNullOrWhiteSpace(str) => str,
 3027            Enum enumValue => ValueFormatter.FormatEnumName(enumValue),
 328            string => throw new ArgumentException("Enum value cannot be null or whitespace.", nameof(value)),
 329            _ => throw new ArgumentException($"Invalid enum value type: {value.GetType().Name}. Expected a non-empty str
 22230        };
 21031    }
 32
 333    public override string ToString() => Value;
 34
 635    public static bool operator ==(EnumValue left, EnumValue right) => left.Equals(right);
 36
 637    public static bool operator !=(EnumValue left, EnumValue right) => !left.Equals(right);
 38
 339    public static bool operator <(EnumValue left, EnumValue right) => left.CompareTo(right) < 0;
 40
 341    public static bool operator >(EnumValue left, EnumValue right) => left.CompareTo(right) > 0;
 42
 643    public static bool operator <=(EnumValue left, EnumValue right) => left.CompareTo(right) <= 0;
 44
 645    public static bool operator >=(EnumValue left, EnumValue right) => left.CompareTo(right) >= 0;
 46
 47    public int CompareTo(object? obj)
 48    {
 2449        return obj switch
 2450        {
 951            null => 1,
 352            EnumValue enumValue => CompareTo(enumValue),
 1253            _ => throw new ArgumentException($"Object must be of type {nameof(EnumValue)}")
 2454        };
 55    }
 56
 5757    public int CompareTo(EnumValue other) => string.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);
 58
 1259    public override bool Equals(object? obj) => CompareTo(obj) == 0;
 60
 2761    public bool Equals(EnumValue other) => CompareTo(other) == 0;
 62
 1263    public override int GetHashCode() => Value.GetHashCode(StringComparison.OrdinalIgnoreCase);
 64}