public override object ParseLiteral(IValueNode literal)
        {
            if (literal == null)
            {
                throw new ArgumentNullException(nameof(literal));
            }

            if (literal is StringValueNode stringLiteral)
            {
                if (!MultiplierPathString.IsValidName(stringLiteral.Value))
                {
                    throw new ScalarSerializationException(
                              string.Format(CultureInfo.InvariantCulture,
                                            AbstractionResources.Type_NameIsNotValid,
                                            stringLiteral.Value ?? "null"));
                }
                return(new MultiplierPathString(stringLiteral.Value));
            }

            if (literal is NullValueNode)
            {
                return(null);
            }

            throw new ScalarSerializationException(
                      TypeResourceHelper.Scalar_Cannot_ParseLiteral(
                          Name, literal.GetType()));
        }
示例#2
0
        public void ImplicitCast_InvalidName_MultiplierPathString(string name)
        {
            // arrange
            // act
            Action a = () => { MultiplierPathString nameString = name; };

            // assert
            Assert.Throws <ArgumentException>(a);
        }
示例#3
0
        public void ImplicitCast_ValidName_MultiplierPathString(string name)
        {
            // arrange
            // act
            MultiplierPathString nameString = name;

            // assert
            Assert.Equal(name, nameString.Value);
        }
示例#4
0
        public void ToString_ReturnsValue()
        {
            // arrange
            var nameString = new MultiplierPathString("Foo");

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

            // assert
            Assert.Equal(nameString.Value, value);
        }
示例#5
0
        public void ImplicitCast_MultiplierPathString_String()
        {
            // arrange
            var nameString = new MultiplierPathString("Foo");

            // act
            string name = nameString;

            // assert
            Assert.Equal(nameString.Value, name);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
0
        public void Equals_SameInstance_True()
        {
            // arrange
            var a = new MultiplierPathString("Foo");

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

            // assert
            Assert.True(result);
        }
示例#9
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());
        }
示例#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);
        }
示例#11
0
        public void NotEqualsOp_StringWithSameValue_False()
        {
            // arrange
            var a = new MultiplierPathString("Foo");
            var b = "Foo";

            // act
            bool result = a != b;

            // assert
            Assert.False(result);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#16
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());
        }
        public static IObjectFieldDescriptor Cost(
            this IObjectFieldDescriptor descriptor,
            int complexity,
            MultiplierPathString multiplier)
        {
            if (descriptor is null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            return(descriptor.Directive(
                       new CostDirective(complexity, multiplier)));
        }
        public void Serialize_Type()
        {
            // arrange
            var type = new MultiplierPathType();
            MultiplierPathString input = "_123456";

            // act
            object serializedValue = type.Serialize(input);

            // assert
            Assert.IsType <string>(serializedValue);
            Assert.Equal("_123456", serializedValue);
        }
        public override bool IsInstanceOfType(IValueNode literal)
        {
            if (literal == null)
            {
                throw new ArgumentNullException(nameof(literal));
            }

            if (literal is NullValueNode)
            {
                return(true);
            }

            return(literal is StringValueNode s &&
                   MultiplierPathString.IsValidName(s.Value));
        }
        public override bool TryDeserialize(object serialized, out object value)
        {
            if (serialized is null)
            {
                value = null;
                return(true);
            }

            if (serialized is string s)
            {
                value = new MultiplierPathString(s);
                return(true);
            }

            if (serialized is MultiplierPathString n)
            {
                value = n;
                return(true);
            }

            value = null;
            return(false);
        }