Example #1
0
        public void ShouldHandleNullableValueTypes()
        {
            const string script = @"
                result.NullableInt32 = input ? ToInt32(input) : null;
                result.String = null;
            ";

            var result = new TypeWithNullableValueTypeProperty
            {
                NullableInt32 = 1,
                String = "",
            };

            new JintEngine()
                .SetParameter("input", "")
                .SetParameter("result", result)
                .Run(script);

            Assert.IsNull(result.NullableInt32);
            Assert.IsNull(result.String);
        }
Example #2
0
        public void ShouldHandleNonNullableValueTypes()
        {
            const string script = @"
                result.Int32 = null;
            ";

            var result = new TypeWithNullableValueTypeProperty();

            try
            {
                new JintEngine()
                        .SetParameter("result", result)
                        .Run(script);
            }
            catch (JintException je)
            {
                Assert.IsTrue(je.Message.Contains("Cannot cast null value to Int32"));
            }
        }