public void ShouldRednerTextFieldWithLiquidTest()
        {
            //arange
            var      factory  = new TextFieldFactory();
            var      field    = factory.CreateNew("greetings", "hello", null);
            Template template = Template.Parse("{{ greetings }}");

            Assert.AreEqual("hello", template.Render(Hash.FromDictionary(new ConcurrentDictionary <string, object>
            {
                [field.FieldName] = field.ToLiquid()
            })));
        }
        public void TextToLiquidTest()
        {
            //arrange
            var factory = new TextFieldFactory();
            var field   = factory.CreateNew("test", "hello", null);

            Template template = Template.Parse("{{ test }}");

            Console.WriteLine(factory.GetType().AssemblyQualifiedName);
            Assert.AreEqual("hello", template.Render(Hash.FromDictionary(new ConcurrentDictionary <string, object>
            {
                [field.FieldName] = field.ToLiquid()
            })));
        }
Exemplo n.º 3
0
        public Task ShouldValidateIncommingFields()
        {
            // arrange
            var builder = new GenericIEntityBuilder <Entity, Category>(_factoryProvider, new UrlBuilder());
            var entity  = new Entity()
            {
                Handle = "test url ssss     ssss"
            };
            var textFieldDefenition = new FieldDefenition()
            {
                Title = "text1", Type = "text", IsRequired = true, Id = Guid.NewGuid()
            };
            var numberFieldDefenition = new FieldDefenition()
            {
                Title = "number", Type = "number", IsRequired = true, Id = Guid.NewGuid()
            };

            var entityScheme = new EntityScheme()
            {
                FieldDefenitions = new List <FieldDefenition>()
                {
                    textFieldDefenition,
                    numberFieldDefenition
                }
            };


            var textFactory   = new TextFieldFactory();
            var numberFactory = new NumberFieldFactory();


            // act
            builder.SetBuildingEntity(entity, entityScheme, new Category()
            {
                FieldDefenitions = new List <FieldDefenition>()
            });

            var text   = textFactory.CreateNew("text1", "hello world", null);
            var number = numberFactory.CreateNew("number", 5, null);

            var textField = new Field()
            {
                RawValue = text.Value, FieldDefenition = textFieldDefenition
            };
            var numberField = new Field()
            {
                RawValue = number.Value, FieldDefenition = numberFieldDefenition
            };



            var liquidAdapter = new EntityLiquidAdapter();

            liquidAdapter.FieldFactoryProvider = _factoryProvider;
            liquidAdapter.Entity = builder.GetResult();
            Template t      = Template.Parse("text is {{entity.text1}} and number is {{entity.number}}");
            var      actual = t.Render(Hash.FromAnonymousObject(new { entity = liquidAdapter }));

            //assert
            Console.WriteLine(actual);

            return(Task.FromResult(0));
        }