示例#1
0
文件: Fixtures.cs 项目: cosh/Jint
        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);
        }
示例#2
0
文件: Fixtures.cs 项目: cosh/Jint
        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"));
            }
        }