Example #1
0
        internal void BuildPropertyParts(Part part, object result)
        {
            var resultType = result.GetType();
            var propertyParts = part.Parts.Where(n => n is PropertyPart);
            foreach (var propertyPart in propertyParts)
            {
                var prop = resultType.GetProperty(propertyPart.Name,
                                  bindingFlags);

                var partFactory = FindPartFactory(propertyPart);

                var propValue = partFactory.CreateObject(propertyPart);

                prop.SetValue(
                    result,
                    propValue,
                    null);

                if (propValue != null)
                {
                    if (propValue is IList)
                        BuildValueParts(propertyPart, propValue as IList);
                    else
                        BuildPropertyParts(propertyPart, propValue);
                }
            }
        }
Example #2
0
        public PartMetadata(Part part)
        {
            if (part == null) throw new ArgumentNullException();

            Part = part;
            Data = new Dictionary<string, object>();
            Count = 1;
        }
Example #3
0
        public Part AddPart(Part part)
        {
            if (part == null) throw new ArgumentNullException();

            part.Parent = this;
            parts.Add(part);

            return part;
        }
        public override bool CanCreateObjectsFor(Part part)
        {
            if (part != null &&
                part.Type == typeof(string) &&
                part.Metadata.Data.ContainsKey("HumanName"))
                return true;

            return false;
        }
			public void Setup()
			{
				Given(TextPartFactory_is_created);
				And("Part is created", () =>
				{
					part = new Part(typeof(string));
					part.Metadata.Data.Add("Text", numberOfWords);
				});

				When(create_object);
			}
Example #6
0
        public virtual List<Object> CreateObjects(Part part)
        {
            var result = new List<Object>();

            for (int i = 0; i < part.Metadata.Count; i++)
            {
                result.Add(CreateObject(part));
            }

            return result;
        }
Example #7
0
        public override List<object> CreateObjects(Part part)
        {
            var result = new List<Object>();

            for (int i = 0; i < part.Metadata.Count; i++)
            {
                var obj = Activator.CreateInstance(part.Type);
                objectBuilder.BuildPropertyParts(part, obj);
                result.Add(obj);
            }

            return result;
        }
Example #8
0
        public Object Build(Part part)
        {
            Object result = null;

            result = Activator.CreateInstance(part.Type);

            BuildPropertyParts(part, result);

            if (result is IList)
            {
                BuildValueParts(part, result as IList);
            }

            return result;
        }
Example #9
0
        public override object CreateObject(Part part)
        {
            var result = new StringBuilder();
            var words = wordRepository.Get();

            int numberOfWordsToCreate = (int)part.Metadata.Data["Text"];

            foreach (var word in words)
            {
                result.Append(word);
                result.Append(" ");
            }

            return result.ToString();
        }
Example #10
0
        public override Object CreateObject(Part part)
        {
            var str = string.Empty;

            if (part.Metadata.Data.ContainsKey("HumanName"))
            {
                var options = (HumanNameOptions)part.Metadata.Data["HumanName"];
                if ((options & HumanNameOptions.FemaleName) == HumanNameOptions.FemaleName)
                    str = humanNameRepository.Get(All.FemaleNames()).Random<HumanName>().Name;
                else if ((options & HumanNameOptions.MaleName) == HumanNameOptions.MaleName)
                    str = humanNameRepository.Get(All.MaleNames()).Random<HumanName>().Name;
                else if ((options & HumanNameOptions.Name) == HumanNameOptions.Name)
                    str = humanNameRepository.Get(All.Names()).Random<HumanName>().Name;

                if ((options & HumanNameOptions.Surname) == HumanNameOptions.Surname)
                    str += string.Format(" {0}", humanNameRepository.Get(All.Names()).Random<HumanName>().Surname);
            }

            return str;
        }
Example #11
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("part for list of objects is specified", () =>
                {
                    part = new Part(typeof(List<Customer>));
                    var customer1Part = new ValuePart(typeof (Customer));
                    customer1Part.AddPart(new PropertyPart("CEO", typeof (Employee)));
                    var employeesPart = new PropertyPart("Employees", typeof (ObservableCollection<Employee>));
                    var employeePart = new ValuePart(typeof (Employee));
                    employeePart.AddPart(new PropertyPart("Boss", typeof(Employee)));

                    employeesPart.AddPart(employeePart);
                    customer1Part.AddPart(employeesPart);

                    part.AddPart(customer1Part);
                    part.AddPart(new ValuePart(typeof(Customer)));
                });

                When(build_object_graph);
            }
Example #12
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);
                And("recipe is specified", () =>
                {
                    part = new Part(typeof (List<string>));
                    part.AddPart(new ValuePart(typeof (string))).Describe(metadata =>
                    {
                        metadata.Count = 10;
                        metadata.Data.Add("HumanName", HumanNameOptions.Name | HumanNameOptions.Surname);
                    });
                });

                When("build object graph", () =>
                    names = objectBuilder.Build(part) as List<string>);
            }
Example #13
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);
                And("recipe is specified", () =>
                {
                    part = new Part(typeof (List<List<string>>));
                    part.AddPart(new ValuePart(typeof(List<string>))).Describe(metadata =>
                    {
                        metadata.Count = 10;
                        metadata.Part.AddPart(new ValuePart(typeof (string))).Describe(m =>
                        {
                            m.Count = 10;
                            m.Data.Add("HumanName", HumanNameOptions.Name);
                        });
                    });
                });

                When(build_object_graph);
            }
Example #14
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);
                And("recipe is specified", () =>
                {
                    part = new Part(typeof (List<string>));
                    part.AddPart(new ValuePart(typeof(string))).Describe(metadata =>
                    {
                        metadata.Count = 100;
                    });
                });

                When(build_object_graph);
            }
Example #15
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("parts for lists of customers are specified", () =>
                {
                    part = new Part(typeof(List<Customer>));
                    var customerPart = new ValuePart(typeof (Customer));
                    customerPart.Describe(m => m.Count = 10);
                    customerPart.AddPart(new PropertyPart("Name", typeof(string))).
                        Describe(m =>
                        {
                            m.Data.Add("HumanName", HumanNameOptions.Name);
                        });

                    var ceoPart = new PropertyPart("CEO", typeof (Employee));
                    ceoPart.AddPart(new PropertyPart("Name", typeof (string))).
                        Describe(metadata =>
                            metadata.Data.Add("HumanName", HumanNameOptions.Name | HumanNameOptions.Surname));
                    customerPart.AddPart(ceoPart);
                    part.AddPart(customerPart);
                });

                When(build_object_graph);
            }
Example #16
0
            public void Setup()
            {
                Given(ObjectBuilder_is_created);

                And("part for a complex object is specified", () =>
                {
                    part = new Part(typeof(Customer));
                    part.AddPart(new PropertyPart("CEO", typeof(Employee)));
                    var employeesProperty = new PropertyPart("Employees", typeof (ObservableCollection<Employee>));
                    part.AddPart(employeesProperty);

                    employeesProperty.AddPart(new ValuePart(typeof(Employee)));
                });

                When(build_object_graph);
            }
Example #17
0
 public override object CreateObject(Part part)
 {
     return string.Empty;
 }
private static void NewPart()
{
    part = new Part(typeof(List<string>));
}
Example #19
0
        private void BuildValueParts(Part listPart, IList list)
        {
            var valueParts = listPart.Parts.Where(n => n is ValuePart).Cast<ValuePart>();

            foreach (var valuePart in valueParts)
            {
                var valueFactory = FindPartFactory(valuePart);

                if (valueFactory != null)
                {
                    valueFactory.Initialize(this);

                    foreach (var v in valueFactory.CreateObjects(valuePart))
                    {
                        list.Add(v);

                        if (v is IList)
                            BuildValueParts(valuePart, v as IList);
                    }
                }
            }
        }
Example #20
0
 public override Object CreateObject(Part part)
 {
     return Activator.CreateInstance(part.Type);
 }
Example #21
0
 public abstract bool CanCreateObjectsFor(Part part);
Example #22
0
 public override bool CanCreateObjectsFor(Part part)
 {
     throw new NotImplementedException();
 }
Example #23
0
 public override bool CanCreateObjectsFor(Part part)
 {
     if (part.Type == typeof(string)) return true;
     return false;
 }
Example #24
0
 internal PartFactory FindPartFactory(Part part)
 {
     return listPartValueFactories.Where(f => f.CanCreateObjectsFor(part)).FirstOrDefault();
 }
Example #25
0
 public abstract Object CreateObject(Part part);