public void ParseLiteral_Null_Throws()
        {
            // arrange
            var type = new DecimalType();

            // act
            // assert
            Assert.Throws <ArgumentNullException>(
                () => type.ParseLiteral(null));
        }
        public void IsInstanceOfType_Null_Throws()
        {
            // arrange
            var type = new DecimalType();

            // act
            // assert
            Assert.Throws <ArgumentNullException>(
                () => type.IsInstanceOfType(null));
        }
        public void Serialize_Null()
        {
            // arrange
            var type = new DecimalType();

            // act
            var serializedValue = type.Serialize(null);

            // assert
            Assert.Null(serializedValue);
        }
Example #4
0
        public void EnsureDecimalTypeKindIsCorret()
        {
            // arrange
            DecimalType type = new DecimalType();

            // act
            TypeKind kind = type.Kind;

            // assert
            Assert.Equal(TypeKind.Scalar, type.Kind);
        }
        public void IsInstanceOfType_NullLiteral_True()
        {
            // arrange
            var type = new DecimalType();

            // act
            var result = type.IsInstanceOfType(NullValueNode.Default);

            // assert
            Assert.True(result);
        }
        public void IsInstanceOfType_FloatLiteral_True()
        {
            // arrange
            var type = new DecimalType();

            // act
            var result = type.IsInstanceOfType(CreateExponentialLiteral());

            // assert
            Assert.True(result);
        }
        public void ParseLiteral_Wrong_ValueNode_Throws()
        {
            // arrange
            var type  = new DecimalType();
            var input = new StringValueNode("abc");

            // act
            // assert
            Assert.Throws <SerializationException>(
                () => type.ParseLiteral(input));
        }
        public void Ensure_TypeKind_is_Scalar()
        {
            // arrange
            var type = new DecimalType();

            // act
            TypeKind kind = type.Kind;

            // assert
            Assert.Equal(TypeKind.Scalar, kind);
        }
        public void IsInstanceOfType_IntLiteral_True()
        {
            // arrange
            var type = new DecimalType();

            // act
            var result = type.IsInstanceOfType(new IntValueNode(123));

            // assert
            Assert.True(result);
        }
        public void ParseLiteral_NullValueNode()
        {
            // arrange
            var type = new DecimalType();

            // act
            var output = type.ParseLiteral(NullValueNode.Default);

            // assert
            Assert.Null(output);
        }
        public void IsInstanceOfType_StringLiteral_False()
        {
            // arrange
            var type = new DecimalType();

            // act
            var result = type.IsInstanceOfType(new StringValueNode("123"));

            // assert
            Assert.False(result);
        }
        public void Serialize_MaxValue_Violation()
        {
            // arrange
            var     type  = new DecimalType(0, 100);
            decimal value = 123.456M;

            // act
            // assert
            Assert.Throws <SerializationException>(
                () => type.Serialize(value));
        }
        public void Serialize_Wrong_Type_Throws()
        {
            // arrange
            var type  = new DecimalType();
            var input = "abc";

            // act
            // assert
            Assert.Throws <SerializationException>(
                () => type.Serialize(input));
        }
        public void ParseValue_Wrong_Value_Throws()
        {
            // arrange
            var type  = new DecimalType();
            var value = "123";

            // act
            // assert
            Assert.Throws <SerializationException>(
                () => type.ParseValue(value));
        }
        public void ParseValue_MinValue_Violation()
        {
            // arrange
            var     type  = new DecimalType(1, 100);
            decimal input = 0M;

            // act
            Action action = () => type.ParseValue(input);

            // assert
            Assert.Throws <SerializationException>(action);
        }
        public void ParseValue_MinValue()
        {
            // arrange
            var     type  = new DecimalType(1, 100);
            decimal input = 1M;

            // act
            var literal = (FloatValueNode)type.ParseValue(input);

            // assert
            Assert.Equal(1M, literal.ToDecimal());
        }
Example #17
0
        public void ParseLiteral_NullValueNode()
        {
            // arrange
            DecimalType   type  = new DecimalType();
            NullValueNode input = new NullValueNode();

            // act
            object output = type.ParseLiteral(input);

            // assert
            Assert.Null(output);
        }
        public void ParseValue_Nullable()
        {
            // arrange
            var     type  = new DecimalType();
            decimal?input = 123M;

            // act
            FloatValueNode output = (FloatValueNode)type.ParseValue(input);

            // assert
            Assert.Equal(123M, output.ToDecimal());
        }
        public void ParseValue_Null()
        {
            // arrange
            var    type  = new DecimalType();
            object input = null;

            // act
            object output = type.ParseValue(input);

            // assert
            Assert.IsType <NullValueNode>(output);
        }
Example #20
0
        public void Serialize_Decimal()
        {
            // arrange
            DecimalType type  = new DecimalType();
            decimal     input = 1.0m;

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

            // assert
            Assert.IsType <decimal>(serializedValue);
            Assert.Equal(1.0m, serializedValue);
        }
        public void Serialize_Type()
        {
            // arrange
            var     type  = new DecimalType();
            decimal value = 123.456M;

            // act
            var serializedValue = type.Serialize(value);

            // assert
            Assert.IsType <decimal>(serializedValue);
            Assert.Equal(value, serializedValue);
        }
        public void ParseLiteral_ExponentialLiteral()
        {
            // arrange
            var            type    = new DecimalType();
            FloatValueNode literal = CreateExponentialLiteral();

            // act
            var value = type.ParseLiteral(literal);

            // assert
            Assert.IsType <decimal>(value);
            Assert.Equal(literal.ToDecimal(), value);
        }
        public void ParseLiteral_IntLiteral()
        {
            // arrange
            var type    = new DecimalType();
            var literal = new IntValueNode(123);

            // act
            var value = type.ParseLiteral(literal);

            // assert
            Assert.IsType <decimal>(value);
            Assert.Equal(literal.ToDecimal(), value);
        }
Example #24
0
        public void ParseLiteral_FloatValueNode()
        {
            // arrange
            DecimalType    type  = new DecimalType();
            FloatValueNode input = new FloatValueNode("1.000000e+000");

            // act
            object output = type.ParseLiteral(input);

            // assert
            Assert.IsType <decimal>(output);
            Assert.Equal(1.0m, output);
        }
Example #25
0
        public void ParseValue_Decimal_Min()
        {
            // arrange
            DecimalType type  = new DecimalType();
            decimal     input = decimal.MinValue;
            string      expectedLiteralValue = "-7.922816e+028";

            // act
            FloatValueNode literal =
                (FloatValueNode)type.ParseValue(input);

            // assert
            Assert.Equal(expectedLiteralValue, literal.Value, StringComparer.InvariantCulture);
        }
        public void ParseValue_FormatsToSpecifiedNumberOfDecimalDigitsLong()
        {
            // arrange
            var type   = new DecimalType();
            var input  = 1234567.890123456789m;
            var output = "1234567.890123456789";

            // act
            var result = type.ParseValue(input);

            // assert
            Assert.True(result is FloatValueNode);
            Assert.True(result.Value is string);
            Assert.Equal(output, (string)result.Value);
        }
        public void ParseValue_Handle12Digits()
        {
            // arrange
            var type   = new DecimalType();
            var input  = 1234567.890123456789m;
            var output = "1234567.890123456789";

            // act
            var result = type.ParseValue(input);

            // assert
            Assert.True(result is FloatValueNode);
            Assert.True(result.Value is string);
            Assert.Equal(output, (string)result.Value);
        }
        public void ParseValue_FormatsToDefaultSignificantDigits()
        {
            // arrange
            var type   = new DecimalType();
            var input  = 1234567.891123456789m;
            var output = "1234567.891123456789";

            // act
            var result = type.ParseValue(input);

            // assert
            Assert.True(result is FloatValueNode);
            Assert.True(result.Value is string);
            Assert.Equal(output, (string)result.Value);
        }