Exemple #1
0
        public void IncorrectNumberOfIndices()
        {
            dynamic d = new int[2, 2, 2];
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => d[1] = 0);

            Assert.Contains("[]", ex.Message);
            Assert.Contains("'3'", ex.Message);

            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4] = 0);
            Assert.Contains("[]", ex.Message);
            Assert.Contains("'3'", ex.Message);

            ex = Assert.Throws <RuntimeBinderException>(() => d[1]);
            Assert.Contains("[]", ex.Message);
            Assert.Contains("'3'", ex.Message);

            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4]);
            Assert.Contains("[]", ex.Message);
            Assert.Contains("'3'", ex.Message);

            d  = new int[2];
            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4] = 0);
            Assert.Contains("[]", ex.Message);
            Assert.Contains("'1'", ex.Message);

            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4]);
            Assert.Contains("[]", ex.Message);
            Assert.Contains("'1'", ex.Message);
        }
        public void NonIndexerParameterizedSetterOnlyIndexAccess()
        {
            dynamic d = GetObjectWithNonIndexerParameterProperty(false, true);
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => d.ItemProp[2] = 9);

            // Similar message to CS1546 advises about setter method.
            Assert.Contains("set_ItemProp", ex.Message);
        }
Exemple #3
0
        public void InnerExceptionCtor()
        {
            string    message          = "This is a test message.";
            Exception inner            = new Exception("This is a test exception");
            RuntimeBinderException rbe = new RuntimeBinderException(message, inner);

            Assert.Same(inner, rbe.InnerException);
        }
Exemple #4
0
        public TreeNode Fallback(IAstObject item, RuntimeBinderException excException)
        {
            if (ReferenceEquals(item, null))
            {
                return(new TreeNode("Null Node!"));
            }

            return(new TreeNode("Unhandled Node Object"));
        }
Exemple #5
0
        public void NullaryCtor()
        {
            RuntimeBinderException rbe = new RuntimeBinderException();

            Assert.Null(rbe.InnerException);
            Assert.Empty(rbe.Data);
            Assert.True((rbe.HResult & 0xFFFF0000) == 0x80130000); // Error from .NET
            Assert.Contains(rbe.GetType().FullName, rbe.Message);  // Localized, but should contain type name.
        }
Exemple #6
0
        public void InnerExceptionCtor()
        {
            string    message          = "This is a test message.";
            Exception inner            = new Exception("This is a test exception");
            RuntimeBinderException rbe = new RuntimeBinderException(message, inner);

            Assert.Same(inner, rbe.InnerException);
            BinaryFormatterHelpers.AssertRoundtrips(rbe);
        }
        public void NonIndexerParameterizedGetterAndSetterIndexAccess()
        {
            dynamic d = GetObjectWithNonIndexerParameterProperty(true, true);
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => d.ItemProp[2] = 3);

            // Similar message to CS1545 advises about getter and setter methods.
            Assert.Contains("get_ItemProp", ex.Message);
            Assert.Contains("set_ItemProp", ex.Message);
        }
Exemple #8
0
        public virtual void Fallback(ISyntaxTreeElement objItem, RuntimeBinderException excException)
        {
            //If the object is null do nothing
            if (objItem == null)
            {
                return;
            }

            AddInternalComment("Syntax element not implemented: ", objItem.ToString());
        }
Exemple #9
0
        public void MultiDimArrayTypeNames()
        {
            dynamic d = new int[3, 2, 1];
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });

            Assert.Contains("int[,,]", ex.Message);

            d  = Array.CreateInstance(typeof(int), new[] { 3, 2, 1 }, new[] { -2, 2, -0 });
            ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });
            Assert.Contains("int[,,]", ex.Message);
        }
Exemple #10
0
        public void ArrayTypeNames()
        {
            dynamic d = Array.CreateInstance(typeof(int), new[] { 8 }, new[] { -2 });
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });

            Assert.Contains("int[*]", ex.Message);

            d  = new int[3];
            ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });
            Assert.Contains("int[]", ex.Message);
        }
Exemple #11
0
        public void Fallback(IIronyAstObject objItem, RuntimeBinderException excException)
        {
            if (ReferenceEquals(objItem, null))
            {
                Log.Append("<Unrecognized null object");
            }

            else
            {
                Log.Append("<Unrecognized object " + objItem + ">");
            }
        }
Exemple #12
0
        public void StringCtor()
        {
            string message             = "This is a test message.";
            RuntimeBinderException rbe = new RuntimeBinderException(message);

            Assert.Null(rbe.InnerException);
            Assert.Empty(rbe.Data);
            Assert.True((rbe.HResult & 0xFFFF0000) == 0x80130000); // Error from .NET
            Assert.Same(message, rbe.Message);
            rbe = new RuntimeBinderException(null);
            Assert.Equal(new RuntimeBinderException().Message, rbe.Message);
        }
Exemple #13
0
        private void WrapRuntimeBinderExceptionAndRethrow(
            string errorProperty,
            RuntimeBinderException rbe)
        {
            throw new PackageJsonException(
                      string.Format(@"Exception occurred retrieving {0} from package.json. The file may be invalid: you should edit it to correct an errors.

The following error occurred:

{1}",
                                    errorProperty,
                                    rbe));
        }
        public void MultiDimArrayTypeNames()
        {
            dynamic d = new int[3, 2, 1];
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });

            Assert.Contains("int[,,]", ex.Message);

            if (PlatformDetection.IsNonZeroLowerBoundArraySupported)
            {
                d  = Array.CreateInstance(typeof(int), new[] { 3, 2, 1 }, new[] { -2, 2, -0 });
                ex = Assert.Throws <RuntimeBinderException>(() => { string s = d; });
                Assert.Contains("int[,,]", ex.Message);
            }
        }
Exemple #15
0
        public void IncorrectNumberOfIndices()
        {
            dynamic d = new int[2, 2, 2];
            RuntimeBinderException ex = Assert.Throws <RuntimeBinderException>(() => d[1] = 0);

            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'3'", ex.Message);
            }


            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4] = 0);
            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'3'", ex.Message);
            }

            ex = Assert.Throws <RuntimeBinderException>(() => d[1]);
            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'3'", ex.Message);
            }

            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4]);
            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'3'", ex.Message);
            }

            d  = new int[2];
            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4] = 0);
            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'1'", ex.Message);
            }

            ex = Assert.Throws <RuntimeBinderException>(() => d[1, 2, 3, 4]);
            if (!PlatformDetection.IsNetNative) // .NET Native toolchain optimizes away Exception messages.
            {
                Assert.Contains("[]", ex.Message);
                Assert.Contains("'1'", ex.Message);
            }
        }
Exemple #16
0
        public void TestSerialization1()
        {
            var dish = new Dish
            {
                Recipes = new List <Recipe>
                {
                    new Recipe
                    {
                        Name = "Recipe A",
                    },
                    new Recipe
                    {
                        Name = "Recipe B",
                    },
                }
            };
            var json = JsonConvert.SerializeObject(dish);

            dynamic ds = JsonConvert.DeserializeObject(json);

            object jRecipes = null;
            RuntimeBinderException exception = null;

            try
            {
                jRecipes = ds.recipes;
            }
            catch (RuntimeBinderException e)
            {
                exception = e;
            }
            Assert.That(exception, Is.Null, "recipes field should not be serialized.");

            Assert.That((string)ds.RecipesSummary[0].Name, Is.EqualTo("Recipe A"));
            Assert.That((string)ds.RecipesSummary[1].Name, Is.EqualTo("Recipe B"));
        }
Exemple #17
0
        private static PackageJsonException WrapRuntimeBinderException(string errorProperty, RuntimeBinderException rbe)
        {
            return(new PackageJsonException(
                       string.Format(CultureInfo.CurrentCulture, @"Exception occurred retrieving {0} from package.json. The file may be invalid: you should edit it to correct an errors.

The following error occurred:

{1}",
                                     errorProperty,
                                     rbe)));
        }
 public TreeNode Fallback(IIronyAstObject objItem, RuntimeBinderException excException)
 {
     return(new TreeNode("Unrecognized Node!"));
 }
Exemple #19
0
 public virtual ISyntaxTreeElement Fallback(ISyntaxTreeElement objItem, RuntimeBinderException excException)
 {
     return(objItem);
 }
Exemple #20
0
 /// <summary>
 /// The fall back method that is called if no matching visit method is found and UseExceptions flag is false
 /// </summary>
 /// <param name="value1"></param>
 /// <param name="value2"></param>
 /// <param name="excException"></param>
 /// <returns></returns>
 public abstract ILanguageValue Fallback(ILanguageValue value1, ILanguageValue value2, RuntimeBinderException excException);
Exemple #21
0
 public void Fallback(IIronyAstObject objItem, RuntimeBinderException excException)
 {
     throw new NotImplementedException();
 }
Exemple #22
0
 public virtual void Fallback(IAstObject objItem, RuntimeBinderException excException)
 {
 }
 public override ILanguageValue Fallback(ILanguageValue value1, RuntimeBinderException excException)
 {
     throw new NotImplementedException();
 }
Exemple #24
0
        public void _01()
        {
            RuntimeBinderException exception = Assert.Throws <RuntimeBinderException>(() => { C10.Fn01(); });

            Assert.Equal("Cannot implicitly convert type 'string' to 'int'", exception.Message);
        }
Exemple #25
0
 public void Fallback(IIronyAstObject objItem, RuntimeBinderException excException)
 {
 }