Пример #1
0
        public void Should_render_include_with_same_model()
        {
            var model = new { Name = "Joe" };
            RegisterTemplate("person", SyntaxTree.Block(
                SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name"))
            ));
            var template = SyntaxTree.Block(
                SyntaxTree.WriteString("Hello "),
                SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType()))
            );

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("Hello Joe"));
        }
Пример #2
0
        public void Should_map_an_anonymous_object_to_the_settings()
        {
            var converterCache = new DynamicObjectConverterCache(new DynamicImplementationBuilder());
            var cache = new DictionaryConverterCache();

            var source = new
                {
                    Host = "localhost",
                    VirtualHost = "vortex",
                    Username = "******",
                    Password = "******",
                    Port = 5672,
                };

            IDictionaryConverter converter = cache.GetConverter(source.GetType());
            IDictionary<string, object> dictionary = converter.GetDictionary(source);

            IObjectConverter objectConverter = converterCache.GetConverter(typeof(RabbitMqSettings));

            var settings = (RabbitMqSettings)objectConverter.GetObject(dictionary);

            Assert.IsNotNull(settings);

            Assert.AreEqual("localhost", settings.Host);
            Assert.AreEqual("vortex", settings.VirtualHost);
            Assert.AreEqual("joe", settings.Username);
            Assert.AreEqual("guess", settings.Password);
            Assert.AreEqual(5672, settings.Port);
            Assert.AreEqual(0, settings.Heartbeat);

            Assert.IsNull(settings.Options);
        }
Пример #3
0
        public void Should_render_include_with_same_sub_model()
        {
            var model = new { Name = "Joe", Company = new { Name = "Foo" } };
            RegisterTemplate("company", SyntaxTree.Block(
                SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name"))
            ));
            RegisterTemplate("person", SyntaxTree.Block(
                SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name"))
            ));
            var template = SyntaxTree.Block(
                SyntaxTree.WriteString("Welcome from "),
                SyntaxTree.Include("company", SyntaxTreeExpression.Property(model.GetType(), "Company")),
                SyntaxTree.WriteString(" the amazing "),
                SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType())),
                SyntaxTree.WriteString(".")
            );

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("Welcome from Foo the amazing Joe."));
        }
Пример #4
0
 public void Should_use_items_from_collection_as_scope()
 {
     var model = new { Items = new[] { new ItemModel { Name = "John" }, new ItemModel { Name = "Kim" } } };
     var template = SyntaxTree.Block(SyntaxTree.Iterate(
         SyntaxTreeExpression.Property(model.GetType(), "Items"),
         SyntaxTree.Block(
             SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(typeof(ItemModel), "Name"))
         )
     ));
     var result = ExecuteTemplate(template, model);
     Assert.That(result, Is.EqualTo("JohnKim"));
 }
Пример #5
0
        public void Should_throw_if_unable_to_load_template()
        {
            var model = new { Name = "Joe" };
            var template = SyntaxTree.Block(
                SyntaxTree.WriteString("Hello "),
                SyntaxTree.Include("person", SyntaxTreeExpression.Self(model.GetType()))
            );

            Assert.Throws<VeilCompilerException>(() =>
            {
                ExecuteTemplate(template, model);
            });
        }
Пример #6
0
        public void Should_be_able_to_output_value_types_from_collections()
        {
            var model = new { Items = new[] { "1", "2", "3", "4" } };
            var template = SyntaxTree.Block(SyntaxTree.Iterate(
                SyntaxTreeExpression.Property(model.GetType(), "Items"),
                SyntaxTree.Block(
                    SyntaxTree.WriteExpression(SyntaxTreeExpression.Self(typeof(string)))
                )
            ));

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("1234"));
        }
        public void SholdKnowIfATypeIsAListOfResources()
        {
            var list = new List<IBehaveAsResource>();
            var array = new[] {new SomeResource()};

            var notAResourceList = new List<int>();
            var notAResourceArray = new[] {1, 2};

            Assert.IsTrue(list.GetType().IsAListOfResources());
            Assert.IsTrue(array.GetType().IsAListOfResources());

            Assert.IsFalse(notAResourceList.GetType().IsAListOfResources());
            Assert.IsFalse(notAResourceArray.GetType().IsAListOfResources());
        }
Пример #8
0
        public void Should_be_able_to_iterate_an_array()
        {
            var model = new { Items = new[] { "1", "2" } };
            var template = SyntaxTree.Block(SyntaxTree.Iterate(
                SyntaxTreeExpression.Property(model.GetType(), "Items"),
                SyntaxTree.Block(
                    SyntaxTree.WriteString("Item")
                ),
                SyntaxTree.Block(
                    SyntaxTree.WriteString("Empty")
                )
            ));

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("ItemItem"));
        }
Пример #9
0
        public void Root_model_of_template_should_be_the_model_executed_against()
        {
            var model = new { Name = "Joe", Company = new { Name = "Foo", Departments = new[] { "IT", "Admin" } } };
            RegisterTemplate("company", SyntaxTree.Block(
                SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name")),
                SyntaxTree.WriteString(" - "),
                SyntaxTree.Iterate(SyntaxTreeExpression.Property(model.Company.GetType(), "Departments"), SyntaxTree.Block(
                    SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.Company.GetType(), "Name", ExpressionScope.RootModel))
                ))
            ));
            var template = SyntaxTree.Block(
                SyntaxTree.Include("company", SyntaxTreeExpression.Property(model.GetType(), "Company"))
            );

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("Foo - FooFoo"));
        }
        public void Does_encode_unicode()
        {
            string test = "<\"I get this : 􏰁􏰂􏰃􏰄􏰂􏰅􏰆􏰇􏰈􏰀􏰉􏰊􏰇􏰋􏰆􏰌􏰀􏰆􏰊􏰀􏰍􏰄􏰎􏰆􏰏􏰐􏰑􏰑􏰆􏰒􏰆􏰂􏰊􏰀";
            var obj = new { test };
            using (var mem = new System.IO.MemoryStream())
            {
                ServiceStack.Text.JsonSerializer.SerializeToStream(obj, obj.GetType(), mem);

                var encoded = System.Text.Encoding.UTF8.GetString(mem.ToArray());

                var copy1 = JsonObject.Parse(encoded);

                Assert.That(test, Is.EqualTo(copy1["test"]));

                System.Diagnostics.Debug.WriteLine(copy1["test"]);
            }
        }
Пример #11
0
        public void Should_be_able_to_extend_a_template()
        {
            var model = new { Name = "Bob" };
            RegisterTemplate("master", SyntaxTree.Block(
                SyntaxTree.WriteString("<html><head>"),
                SyntaxTree.Override("head"),
                SyntaxTree.WriteString("</head></html>")
            ));
            var template = SyntaxTree.Extend("master", new Dictionary<string, SyntaxTreeNode> {
                {
                    "head",
                    SyntaxTree.Block(
                        SyntaxTree.WriteString("<title>"),
                        SyntaxTree.WriteExpression(SyntaxTreeExpression.Property(model.GetType(), "Name")),
                        SyntaxTree.WriteString("</title>")
                    )
                }
            });
            var result = ExecuteTemplate(template, model);

            Assert.That(result, Is.EqualTo("<html><head><title>Bob</title></head></html>"));
        }
 public void AnonObjectIsNotSimpleType()
 {
     var dummyObject = new { id = 1, Name = "fred" };
     Assert.That(reader.IsSimpleType(dummyObject.GetType()), Is.False);
 }
Пример #13
0
        public void Should_render_empty_block_no_items_in_collection()
        {
            var model = new { Items = new List<string> { } };
            var template = SyntaxTree.Block(SyntaxTree.Iterate(
                SyntaxTreeExpression.Property(model.GetType(), "Items"),
                SyntaxTree.Block(
                    SyntaxTree.WriteString("Item")
                ),
                SyntaxTree.Block(
                    SyntaxTree.WriteString("Empty")
                )
            ));

            var result = ExecuteTemplate(template, model);
            Assert.That(result, Is.EqualTo("Empty"));
        }
Пример #14
0
 public IList<dynamic> GetFlowAuths(decimal flowId)
 {
     using (var ctx = new OAContext())
     {
         var x = new
         {
             flow_id = 1m,
             auth_to = 1m,
             auth_to_name = ""
         };
         var t = x.GetType();
         var re = ctx.SqlDynamic(string.Format(@"
     select fa.*,nvl(o.org_name,'') || nvl(d.dept_name,'') || nvl(r.role_name,'') as auth_name from t_flow_auth fa left join t_org o on fa.auth_to = o.org_id
     left join t_dept d on fa.auth_to = d.dept_id
     left join t_role r on fa.auth_to = r.role_id
     where fa.flow_id={0}", flowId));
         return re;
     }
 }