public void the_root_of_the_path_is_the_property_type()
        {
            var pp = new PropertyPathForInstance<object>(
                () => Customer.FirstName);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("FirstName");
            pp.Value.ShouldBe("John");
        }
        public void the_root_of_the_path_is_the_property_type()
        {
            var pp = new PropertyPathForInstance <object>(
                () => Customer.FirstName);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("FirstName");
            pp.Value.ShouldBe("John");
        }
        public void nested_properties_are_generated()
        {
            var customer = new Customer { DateOfBirth = DateTime.Parse("14 Nov 2000") };
            var pp = new PropertyPathForInstance<int>(() => customer.DateOfBirth.Day);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("DateOfBirth.Day");
            pp.PropertyType.ShouldBe<int>();
            pp.Value.ShouldBe(14);
        }
Example #4
0
        public static IInputCheckedElement CheckBox(this IXhtmlAnchor anchor, Expression <Func <bool> > property)
        {
            var et      = new PropertyPathForInstance <bool>(property);
            var element = Document.CreateElement <IInputCheckedElement>("input").InputType(InputType.CheckBox).Name(et.FullPath);

            if ((bool)et.Value)
            {
                element.Checked();
            }
            return(element);
        }
        public void the_class_without_namespace_is_generated()
        {
            var customer = new Customer { Username = "******" };
            var pp = new PropertyPathForInstance<object>(
                () => customer.Username);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("Username");
            pp.PropertyType.ShouldBe<string>();
            pp.Value.ShouldBe("johndoe");
        }
Example #6
0
        static T FillNameValue <T>(T element, Expression <Func <object> > property) where T : IInputElement

        {
            var expressionTree = new PropertyPathForInstance <object>(property);

            element.Name = expressionTree.FullPath;
            if (expressionTree.Value != null && !expressionTree.Value.Equals(expressionTree.PropertyType.GetDefaultValue()))
            {
                element.Value = expressionTree.Value.ConvertToString();
            }
            return(element);
        }
        public void nested_properties_are_generated()
        {
            var customer = new Customer {
                DateOfBirth = DateTime.Parse("14 Nov 2000")
            };
            var pp = new PropertyPathForInstance <int>(() => customer.DateOfBirth.Day);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("DateOfBirth.Day");
            pp.PropertyType.ShouldBe(typeof(int));
            pp.Value.ShouldBe(14);
        }
        public void the_class_without_namespace_is_generated()
        {
            var customer = new Customer {
                Username = "******"
            };
            var pp = new PropertyPathForInstance <object>(
                () => customer.Username);

            pp.Path.TypePrefix.ShouldBe("Customer");
            pp.Path.TypeSuffix.ShouldBe("Username");
            pp.PropertyType.ShouldBe(typeof(string));
            pp.Value.ShouldBe("johndoe");
        }
        public void an_instance_part_of_the_path_is_replaced_with_the_prefix_in_object_paths()
        {
            try
            {
                ObjectPaths.Add(Customer, new PropertyPath { TypePrefix = "Customer", TypeSuffix = "TheFirst" });

                var pp = new PropertyPathForInstance<object>(() => Customer.FirstName);
                pp.Path.TypePrefix.ShouldBe("Customer");
                pp.Path.TypeSuffix.ShouldBe("TheFirst.FirstName");
            }
            finally
            {
                ObjectPaths.Remove(Customer);
            }
        }
Example #10
0
        public static ISelectElement Select(this IXhtmlAnchor anchor, Expression <Func <object> > property)
        {
            var et = new PropertyPathForInstance <object>(property);

            Type enumType;
            bool isNullable = false;

            if (et.PropertyType.IsGenericType && et.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) && (enumType = et.PropertyType.GetGenericArguments()[0]).IsEnum)
            {
                isNullable = true;
            }
            else if (et.PropertyType.IsEnum)
            {
                enumType = et.PropertyType;
            }
            else
            {
                throw new InvalidOperationException("Cannot automatically generate select entries if the type is not an enumeration or a nullable enumeration.");
            }

            var optionElements = Enum.GetNames(enumType)
                                 .Select(x => Document.CreateElement <IOptionElement>().Value(x)[x]).ToList();

            if (isNullable)
            {
                optionElements.Insert(0, Document.CreateElement <IOptionElement>()[string.Empty]);
            }

            var select = Document.CreateElement <ISelectElement>().Name(et.FullPath);

            optionElements.ForEach(option => select.ChildNodes.Add(option));


            if (et.Value != null)
            {
                var valueToFind = et.Value.ConvertToString();
                foreach (var option in select.ChildNodes.Cast <IOptionElement>())
                {
                    option.Selected = option.Value == valueToFind || option.InnerText == valueToFind;
                }
            }
            else if (isNullable)
            {
                select.ChildNodes.Cast <IOptionElement>().First().Selected();
            }
            return(select);
        }
        public void an_instance_part_of_the_path_is_replaced_with_the_prefix_in_object_paths()
        {
            try
            {
                ObjectPaths.Add(Customer, new PropertyPath {
                    TypePrefix = "Customer", TypeSuffix = "TheFirst"
                });

                var pp = new PropertyPathForInstance <object>(() => Customer.FirstName);
                pp.Path.TypePrefix.ShouldBe("Customer");
                pp.Path.TypeSuffix.ShouldBe("TheFirst.FirstName");
            }
            finally
            {
                ObjectPaths.Remove(Customer);
            }
        }
Example #12
0
        public static ISelectElement Select(this IXhtmlAnchor hook, Expression <Func <object> > propertyName, IEnumerable <IOptionElement> options)
        {
            var et = new PropertyPathForInstance <object>(propertyName);


            var select = Document.CreateElement <ISelectElement>().Name(et.FullPath);

            //TODOD: Special case multiple values
            if (et.Value != null)
            {
                var valueToFind = et.Value.ConvertToString();
                foreach (var option in options)
                {
                    option.Selected = option.Value == valueToFind || option.InnerText == valueToFind;
                }
            }
            options.ForEach(option => select.ChildNodes.Add(option));
            return(select);
        }
Example #13
0
        public static ITextAreaElement TextArea(this IXhtmlAnchor hook, Expression <Func <object> > property)
        {
            var expressionTree = new PropertyPathForInstance <object>(property);

            return(Document.CreateElement <ITextAreaElement>().Name(expressionTree.FullPath)[expressionTree.Value.ConvertToString()]);
        }