public void Invalid_add_relation_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(aw.Products["ProductCategoryID"]);

            // no link between relation field product.category and normal field contact.name
            Assert.Throws<ArgumentException>(() => { path.Add(aw.Contacts.DefaultField); });
        }
        public void Invalid_add_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(aw.Products.DefaultField);

            // no link between normal field product.name and normal field contact.name
            Assert.Throws<InvalidOperationException>(() => { path.Add(aw.Contacts.DefaultField); });
        }
        public void Insert0_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath();

            // creating the path in reverse should be fine
            path.Insert(0, aw.ProductCategory.DefaultField);
            path.Insert(0, aw.Products["ProductCategoryID"]);
            path.Insert(0, aw.SalesOrderDetails["ProductID"]);
        }
        public void Clear_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(
                aw.SalesOrderDetails["ProductID"],
                aw.Products["ProductCategoryID"],
                aw.ProductCategory.DefaultField);

            path.Clear();
            Assert.AreEqual(0, path.Count);
        }
        public void Invalid_remove_relation_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(
                aw.SalesOrderDetails["ProductID"],
                aw.Products["ProductCategoryID"],
                aw.ProductCategory.DefaultField);

            // removing the middle relation creates an invalid link between sales order.product -> category.name
            Assert.Throws<ArgumentException>(() => { path.Remove(aw.Products["ProductCategoryID"]); });
        }
        public void Single_field_path()
        {
            var config = new Chinook();
            var factory = new Factory();
            var adapter = new FieldPathComboAdapter(factory);

            var path = new FieldPath(config["Track"]["Name"]);
            var fields = factory.GetFields(path[0].Subject);

            adapter.SelectedPath = path;
            Assert.AreEqual(1, adapter.Items.Count);
            Assert.AreEqual(fields.Count, adapter.Items[0].Fields.Count);
            Assert.Contains(path[0], adapter.Items[0].Fields);
        }
        public void Double_field_path()
        {
            var config = new Chinook();
            var factory = new Factory();
            var adapter = new FieldPathComboAdapter(factory);

            var path = new FieldPath(config["Track"]["AlbumId"], config["Album"]["Title"]);
            var fields1 = factory.GetFields(path[0].Subject);
            var fields2 = factory.GetFields(path[1].Subject);

            adapter.SelectedPath = path;
            Assert.AreEqual(2, adapter.Items.Count);
            Assert.AreEqual(fields1.Count, adapter.Items[0].Fields.Count);
            Assert.AreEqual(fields2.Count, adapter.Items[1].Fields.Count);
            Assert.Contains(path[0], adapter.Items[0].Fields);
            Assert.Contains(path[1], adapter.Items[1].Fields);
        }
        public void Incomplete_field_path()
        {
            var config = new Chinook();
            var factory = new Factory();
            var adapter = new FieldPathComboAdapter(factory);

            var path = new FieldPath(config["Track"]["AlbumId"], config["Album"]["ArtistId"]);
            var fields1 = factory.GetFields(path[0].Subject);
            var fields2 = factory.GetFields(path[1].Subject);
            var fields3 = factory.GetFields(config["Artist"]); // this should be added by SelectedPath

            adapter.SelectedPath = path;
            Assert.AreEqual(3, adapter.Items.Count);
            Assert.AreEqual(fields1.Count, adapter.Items[0].Fields.Count);
            Assert.AreEqual(fields2.Count, adapter.Items[1].Fields.Count);
            Assert.AreEqual(fields3.Count, adapter.Items[2].Fields.Count);
            Assert.Contains(path[0], adapter.Items[0].Fields);
            Assert.Contains(path[1], adapter.Items[1].Fields);
            Assert.Contains(path[2], adapter.Items[2].Fields);
        }
        /// <summary>
        /// Parse text containing placeholders for fields delimited by bracket.  
        /// The first stop delimits the subject.field, subsequent stops traverse relationships.
        /// For example:
        /// [Products.Name] is the "Products" subject, field "Name"
        /// [Products.ProductCategoryID.Name] is the "Products" subject, field "ProductCategoryID" which is a RelationField to subject "Product Category" with a field "Name".
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="texts"></param>
        /// <returns></returns>
        public virtual Dictionary<string, IFieldPath> Parse(IConfiguration config, params string[] texts)
        {
            var fields = new Dictionary<string, IFieldPath>();

            foreach (var t in texts)
            {
                var matches = Regex.Matches(t, @"\[((?<subject>[^\]\.]+)(\.([^\]\.]+))+)\]");
                foreach (Match m in matches)
                {
                    // represent the entire path as the key to the dictionary
                    if (!fields.ContainsKey(m.Groups[1].Value))
                    {
                        // now create the FieldPath based on the Regex
                        var path = new FieldPath();
                        var subject = config[m.Groups["subject"].Value];
                        if (subject != null)
                        {
                            foreach (Capture capture in m.Groups[3].Captures)
                            {
                                var field = subject[capture.Value];
                                if (field == null)
                                {
                                    path.Clear();
                                    break;
                                }

                                path.Add(field);
                                if (field is IRelationField)
                                    subject = ((IRelationField)field).RelatedSubject;
                            }

                            if (path.Count > 0)
                                fields.Add(m.Groups[0].Value, path);
                        }
                    }
                }
            }

            return fields;
        }
        public IEnumerable<IFieldPath> Add(Node n)
        {
            // if node is SubjectNode, add all fields (and defaults for IRelationFields)
            // if node is FieldNode with an IRelationField, add all fields for the related subject (and defaults for IRelationFields)
            // if node is FieldNode with an IField, create a path tracing back to the parent

            if (n is SubjectNode)
            {
                var fields = PathFactory.GetFields(((SubjectNode)n).Subject);
                foreach (var f in fields)
                {
                    f.Description = null; // this is bad behaviour from the FieldPathFactory
                    if (!Fields.Contains(f))
                        Fields.Add(f);
                }
                return fields;
            }
            else if (n is FieldNode && ((FieldNode)n).Field is IRelationField)
            {
                var fields = PathFactory.GetFields((IRelationField)((FieldNode)n).Field);
                foreach (var f in fields)
                {
                    // ensure hierarchy is maintained
                    var parent = n;
                    while (parent != null && parent is FieldNode)
                    {
                        f.Insert(0, ((FieldNode)parent).Field);
                        parent = parent.Parent;
                    }
                    f.Description = null;
                    if (!Fields.Contains(f))
                        Fields.Add(f);
                }
                return fields;
            }
            else
            {
                var path = new FieldPath();
                var parent = n;
                while (parent != null && parent is FieldNode)
                {
                    path.Insert(0, ((FieldNode)parent).Field);
                    parent = parent.Parent;
                }
                if (!Fields.Contains(path))
                    Fields.Add(path);
                return new IFieldPath[] { path };
            }
        }
        public void Multiple_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(
                aw.SalesOrderDetails["ProductID"],
                aw.Products["ProductCategoryID"],
                aw.ProductCategory.DefaultField);

            Assert.AreEqual(3, path.Count);
            Assert.AreEqual(aw.SalesOrderDetails["ProductID"], path[0]);
            Assert.AreEqual(aw.Products["ProductCategoryID"], path[1]);
            Assert.AreEqual(aw.ProductCategory.DefaultField, path[2]);
        }
Exemple #12
0
 public static FieldPath operator +(FieldPath path, IField field)
 {
     var path2 = new FieldPath(path);
     path2.Add(field);
     return path2;
 }
Exemple #13
0
 public static FieldPath FromDefault(IField field)
 {
     var path = new FieldPath();
     var cur = field;
     while (cur is IRelationField)
     {
         path.Add(cur);
         cur = ((IRelationField)cur).RelatedSubject.DefaultField;
     }
     path.Add(cur);
     return path;
 }
Exemple #14
0
        public IFieldPath this[int from, int? to]
        {
            get
            {
                var f = new FieldPath();
                if (from < 0)
                    from = 0;
                if (!to.HasValue)
                    to = _fields.Count;
                else if (to < 0)
                    to += _fields.Count;

                for (int i = from; i < _fields.Count && i < to; i++)
                    f.Add(_fields[i]);
                return f;
            }
        }
Exemple #15
0
 public static FieldPath operator +(FieldPath path1, FieldPath path2)
 {
     var path3 = new FieldPath(path1);
     path3.Add(path2);
     return path3;
 }
Exemple #16
0
 public LikeParameter(IField field, string value, MatchMode mode)
     : this(FieldPath.FromDefault(field), value, mode)
 {
 }
Exemple #17
0
 public NullParameter(IField field)
     : this(FieldPath.FromDefault(field))
 {
 }
 void SelectedFieldChanged(object sender, EventArgs e)
 {
     var d = ((FieldPathComboItem)sender);
     var path = new FieldPath();
     foreach (var f in Items)
     {
         path.Add(f.SelectedField);
         if (f == d) // end of the road (either truncated or the last field changed)
         {
             SelectedPath = path;
             return;
         }
     }
 }
Exemple #19
0
 public BetweenParameter(IField field, object lo, object hi)
     : this(FieldPath.FromDefault(field), lo, hi)
 {
 }
 static FieldPathAssemblerStub()
 {
     Source = new FieldPath();
     DTO = new FieldPathDTO();
 }
Exemple #21
0
 public SimpleParameter(IField field, string op, object value)
     : this(FieldPath.FromDefault(field), op, value)
 {
 }
        public void Single_field_path()
        {
            var aw = new AdventureWorks();
            var path = new FieldPath(aw.Products.DefaultField);

            Assert.AreEqual(1, path.Count);
            Assert.AreEqual(aw.Products.DefaultField, path[0]);
        }