using System.Collections.Generic; using System.Dynamic; using Microsoft.VisualStudio.TestTools.UnitTesting; using Z.Expressions; namespace Outbound.Tests.Avo { [TestClass] public class EvalTests { [TestMethod] public void CanReferenceStringMethodsWhenNoDataContext() { var context = new EvalContext {UseCache = false}; var code = @"String.IsNullOrEmpty(""Foo"")"; var result = context.Execute(code); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenAnonymousDataContext() { var context = new EvalContext {UseCache = false}; var code = @"String.IsNullOrEmpty(Custom.Foo)"; var dataContext = new {Custom = new {Foo = "Bar"}}; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenDictionaryDataContext() { var context = new EvalContext {UseCache = false}; var code = @"String.IsNullOrEmpty(Custom.Foo)"; var dataContext = new Dictionary { {"Custom", new {Foo = "Bar"}} }; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenExpandoDataContext() { var context = new EvalContext {UseCache = false}; var code = @"String.IsNullOrEmpty(Custom.Foo)"; dynamic dataContext = new ExpandoObject(); dataContext.Custom = new {Foo = "Bar"}; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenExpandoDataContextWithoutUsingIt() { var context = new EvalContext { UseCache = false }; var code = @"String.IsNullOrEmpty(""Foo"")"; dynamic dataContext = new ExpandoObject(); dataContext.Custom = new { Foo = "Bar" }; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceExpandoDataContext() { var context = new EvalContext {UseCache = false}; var code = @"Custom.Foo == ""Baz"""; dynamic dataContext = new ExpandoObject(); dataContext.Custom = new {Foo = "Bar"}; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenExpandoInsideAnonymousDataContext() { var context = new EvalContext {UseCache = false}; var code = @"String.IsNullOrEmpty(Custom.Foo)"; var dataContext = new {Custom = (dynamic) new ExpandoObject()}; dataContext.Custom.Foo = "Bar"; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceStringMethodsWhenExpandoInsideAnonymousDataContextWithoutUsingIt() { var context = new EvalContext { UseCache = false }; var code = @"String.IsNullOrEmpty(""Foo"")"; var dataContext = new { Custom = (dynamic)new ExpandoObject() }; dataContext.Custom.Foo = "Bar"; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } [TestMethod] public void CanReferenceExpandoInsideAnonymousDataContext() { var context = new EvalContext {UseCache = false}; var code = @"Custom.Foo == ""Baz"""; var dataContext = new {Custom = (dynamic) new ExpandoObject()}; dataContext.Custom.Foo = "Bar"; var result = context.Execute(code, dataContext); Assert.IsFalse(result); } } }