コード例 #1
0
        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());
        }
コード例 #17
0
        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)));
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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));
        }
コード例 #20
0
        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);
        }