public override object ConvertFrom(
     ITypeDescriptorContext context,
     CultureInfo culture,
     object value) =>
 value is string
 ?MultiplierPathString.ConvertFromString((string)value)
     : base.ConvertFrom(context, culture, value);
Ejemplo n.º 2
0
        public static int DefaultCalculation(
            IOutputField field,
            FieldNode selection,
            CostDirective?cost,
            int fieldDepth,
            int nodeDepth,
            Func <string, object?> getVariable,
            IMaxComplexityOptionsAccessor options)
        {
            if (cost is null)
            {
                return(options.DefaultComplexity);
            }

            if (options.UseComplexityMultipliers)
            {
                if (cost.Multipliers.Count == 0)
                {
                    return(cost.Complexity);
                }

                int complexity = 0;

                for (int i = 0; i < cost.Multipliers.Count; i++)
                {
                    MultiplierPathString multiplier = cost.Multipliers[i];
                    ArgumentNode         argument   = selection.Arguments.FirstOrDefault(t =>
                                                                                         t.Name.Value.Equals(multiplier.Value));

                    if (argument is { } && argument.Value is { })
Ejemplo n.º 3
0
        public void ImplicitCast_InvalidName_MultiplierPathString(string name)
        {
            // arrange
            // act
            Action a = () => { MultiplierPathString nameString = name; };

            // assert
            Assert.Throws <ArgumentException>(a);
        }
Ejemplo n.º 4
0
        public void ImplicitCast_ValidName_MultiplierPathString(string name)
        {
            // arrange
            // act
            MultiplierPathString nameString = name;

            // assert
            Assert.Equal(name, nameString.Value);
        }
Ejemplo n.º 5
0
        public void ToString_ReturnsValue()
        {
            // arrange
            var nameString = new MultiplierPathString("Foo");

            // act
            string value = nameString.ToString();;

            // assert
            Assert.Equal(nameString.Value, value);
        }
Ejemplo n.º 6
0
        public void ImplicitCast_MultiplierPathString_String()
        {
            // arrange
            var nameString = new MultiplierPathString("Foo");

            // act
            string name = nameString;

            // assert
            Assert.Equal(nameString.Value, name);
        }
Ejemplo n.º 7
0
        public void Create_DefaultConstructor_IsEmpty()
        {
            // arrange
            // act
            var nameString = new MultiplierPathString();

            // assert
            Assert.True(nameString.IsEmpty);
            Assert.False(nameString.HasValue);
            Assert.Null(nameString.Value);
        }
Ejemplo n.º 8
0
        public void Create_WithValidName_HasValue(string value)
        {
            // arrange
            // act
            var nameString = new MultiplierPathString(value);

            // assert
            Assert.Equal(nameString.Value, value);
            Assert.True(nameString.HasValue);
            Assert.False(nameString.IsEmpty);
        }
Ejemplo n.º 9
0
        public void Equals_SameInstance_True()
        {
            // arrange
            var a = new MultiplierPathString("Foo");

            // act
            bool result = a.Equals(a);

            // assert
            Assert.True(result);
        }
Ejemplo n.º 10
0
        public void NotEqualsOp_StringDifferentValue_True()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = "Bar";

            // act
            bool result = a != b;

            // assert
            Assert.True(result);
        }
Ejemplo n.º 11
0
        public void Append_MultiplierPathString_CombinedMultiplierPathString()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = new MultiplierPathString("Bar");

            // act
            MultiplierPathString combined = a.Add(b);

            // assert
            Assert.Equal("FooBar", combined.ToString());
        }
Ejemplo n.º 12
0
        public void NotEqualsOp_SameInstance_False()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            MultiplierPathString b = a;

            // act
            bool result = a != b;

            // assert
            Assert.False(result);
        }
Ejemplo n.º 13
0
        public void EqualsOp_MultiplierPathStringDifferentValue_False()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = new MultiplierPathString("Bar");

            // act
            bool result = a == b;

            // assert
            Assert.False(result);
        }
Ejemplo n.º 14
0
        public void EqualsOp_MultiplierPathStringWithSameValue_True()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = new MultiplierPathString("Foo");

            // act
            bool result = a == b;

            // assert
            Assert.True(result);
        }
Ejemplo n.º 15
0
        public void EqualsIgnoreCasing_MultiplierPathStringWithDifferentCasing_True()
        {
            // arrange
            var a = new MultiplierPathString("FOO");
            var b = new MultiplierPathString("foo");

            // act
            bool result = a.Equals(b, StringComparison.OrdinalIgnoreCase);

            // assert
            Assert.True(result);
        }
Ejemplo n.º 16
0
        public void AddOp_String_CombinedMultiplierPathString()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = "Bar";

            // act
            MultiplierPathString combined = a + b;

            // assert
            Assert.Equal("FooBar", combined.ToString());
        }
Ejemplo n.º 17
0
        public void NotEqualsOp_StringWithSameValue_False()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = "Foo";

            // act
            bool result = a != b;

            // assert
            Assert.False(result);
        }
        public static MultiplierPathString EnsureNotEmpty(
            this MultiplierPathString name,
            string argumentName)
        {
            if (name.IsEmpty)
            {
                throw new ArgumentException(
                          TypeResources.Name_Cannot_BeEmpty(),
                          argumentName);
            }

            return(name);
        }
    public static IInterfaceFieldDescriptor Cost(
        this IInterfaceFieldDescriptor descriptor,
        int complexity,
        MultiplierPathString multiplier)
    {
        if (descriptor is null)
        {
            throw new ArgumentNullException(nameof(descriptor));
        }

        return(descriptor.Directive(
                   new CostDirective(complexity, multiplier)));
    }