Example #1
0
 public void TryParse_NonStringValue_ExceptionIsThrown()
 {
     var value        = 0;
     var decimals     = 2;
     var property     = typeof(MockRecord).GetProperty(nameof(MockRecord.DecimalField));
     var bitAttribute = new ImplicitDecimalAttribute(decimals);
     var couldParse   = bitAttribute.TryParse(property, value, out object parsedFieldValue, out string failureMessage);
 }
Example #2
0
        public void TryParse_ZeroImpliedDecimals_CouldParse()
        {
            var value        = "10050";
            var decimals     = 0;
            var property     = typeof(MockRecord).GetProperty(nameof(MockRecord.DecimalField));
            var bitAttribute = new ImplicitDecimalAttribute(decimals);
            var couldParse   = bitAttribute.TryParse(property, value, out object parsedFieldValue, out string failureMessage);

            Assert.IsTrue(couldParse);
            Assert.AreEqual(10050m, parsedFieldValue);
            Assert.IsNull(failureMessage);
        }
Example #3
0
        public void TryParse_InvalidStringValue_CouldNotParse()
        {
            var value        = "invalid";
            var decimals     = 2;
            var property     = typeof(MockRecord).GetProperty(nameof(MockRecord.DecimalField));
            var bitAttribute = new ImplicitDecimalAttribute(decimals);
            var couldParse   = bitAttribute.TryParse(property, value, out object parsedFieldValue, out string failureMessage);

            Assert.IsFalse(couldParse);
            Assert.IsNull(parsedFieldValue);
            Assert.IsFalse(String.IsNullOrEmpty(failureMessage));
        }
Example #4
0
        public void TryParse_ValidStringValueAndNullableDecimalTypeTarget_CouldParse()
        {
            var value        = "10050";
            var decimals     = 2;
            var property     = typeof(MockRecord).GetProperty(nameof(MockRecord.NullableDecimalField));
            var bitAttribute = new ImplicitDecimalAttribute(decimals);
            var couldParse   = bitAttribute.TryParse(property, value, out object parsedFieldValue, out string failureMessage);

            Assert.IsTrue(couldParse);
            Assert.AreEqual(100.5m, parsedFieldValue);
            Assert.IsNull(failureMessage);
        }