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())); }
public void ImplicitCast_InvalidName_MultiplierPathString(string name) { // arrange // act Action a = () => { MultiplierPathString nameString = name; }; // assert Assert.Throws <ArgumentException>(a); }
public void ImplicitCast_ValidName_MultiplierPathString(string name) { // arrange // act MultiplierPathString nameString = name; // assert Assert.Equal(name, nameString.Value); }
public void ToString_ReturnsValue() { // arrange var nameString = new MultiplierPathString("Foo"); // act string value = nameString.ToString();; // assert Assert.Equal(nameString.Value, value); }
public void ImplicitCast_MultiplierPathString_String() { // arrange var nameString = new MultiplierPathString("Foo"); // act string name = nameString; // assert Assert.Equal(nameString.Value, name); }
public void Create_DefaultConstructor_IsEmpty() { // arrange // act var nameString = new MultiplierPathString(); // assert Assert.True(nameString.IsEmpty); Assert.False(nameString.HasValue); Assert.Null(nameString.Value); }
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); }
public void Equals_SameInstance_True() { // arrange var a = new MultiplierPathString("Foo"); // act bool result = a.Equals(a); // assert Assert.True(result); }
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()); }
public void NotEqualsOp_StringDifferentValue_True() { // arrange var a = new MultiplierPathString("Foo"); var b = "Bar"; // act bool result = a != b; // assert Assert.True(result); }
public void NotEqualsOp_StringWithSameValue_False() { // arrange var a = new MultiplierPathString("Foo"); var b = "Foo"; // act bool result = a != b; // assert Assert.False(result); }
public void NotEqualsOp_SameInstance_False() { // arrange var a = new MultiplierPathString("Foo"); MultiplierPathString b = a; // act bool result = a != b; // assert Assert.False(result); }
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); }
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); }
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); }
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); }