< 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: 63
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>
 16811    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 or an unsupported typ
 20    public EnumValue(object value)
 21    {
 14422        ArgumentNullException.ThrowIfNull(value);
 13823        Value = value switch
 13824        {
 23125            string str when !string.IsNullOrWhiteSpace(str) => str,
 1826            Enum enumValue => enumValue.ToString(),
 327            string => throw new ArgumentException("Enum value cannot be null or whitespace.", nameof(value)),
 328            _ => throw new ArgumentException($"Invalid enum value type: {value.GetType().Name}. Expected a non-empty str
 13829        };
 13230    }
 31
 332    public override string ToString() => Value;
 33
 634    public static bool operator ==(EnumValue left, EnumValue right) => left.Equals(right);
 35
 636    public static bool operator !=(EnumValue left, EnumValue right) => !left.Equals(right);
 37
 338    public static bool operator <(EnumValue left, EnumValue right) => left.CompareTo(right) < 0;
 39
 340    public static bool operator >(EnumValue left, EnumValue right) => left.CompareTo(right) > 0;
 41
 642    public static bool operator <=(EnumValue left, EnumValue right) => left.CompareTo(right) <= 0;
 43
 644    public static bool operator >=(EnumValue left, EnumValue right) => left.CompareTo(right) >= 0;
 45
 46    public int CompareTo(object? obj)
 47    {
 2448        return obj switch
 2449        {
 950            null => 1,
 351            EnumValue enumValue => CompareTo(enumValue),
 1252            _ => throw new ArgumentException($"Object must be of type {nameof(EnumValue)}")
 2453        };
 54    }
 55
 5756    public int CompareTo(EnumValue other) => string.Compare(Value, other.Value, StringComparison.OrdinalIgnoreCase);
 57
 1258    public override bool Equals(object? obj) => CompareTo(obj) == 0;
 59
 2760    public bool Equals(EnumValue other) => CompareTo(other) == 0;
 61
 1262    public override int GetHashCode() => Value.GetHashCode(StringComparison.OrdinalIgnoreCase);
 63}