示例#1
0
 public static MockWorkItemStore Add(this MockWorkItemStore store, IEnumerable <IEnumerable <KeyValuePair <string, object> > > values)
 {
     foreach (var value in values)
     {
         store.Add(value);
     }
     return(store);
 }
示例#2
0
 public MockQuery(
     [NotNull] MockWorkItemStore store,
     [CanBeNull] string wiql           = null,
     [CanBeNull] IEnumerable <int> ids = null)
 {
     _wiql  = wiql;
     _ids   = ids;
     _store = store ?? throw new ArgumentNullException(nameof(store));
 }
示例#3
0
        public static MockWorkItemStore AddChildLink(this MockWorkItemStore store, int parentId, int childId)
        {
            var child = store.Query(childId);

            if (child == null)
            {
                throw new ArgumentException($"Parameter {nameof(childId)} ({childId}) does not refer to a work item in the store.");
            }

            child.Links.Add(child.CreateRelatedLink(parentId, store.GetChildLinkTypeEnd()));
            store.BatchSave(child);

            return(store);
        }
示例#4
0
        public static MockWorkItem Create(this MockWorkItemStore store, IEnumerable <KeyValuePair <string, object> > values = null)
        {
            var project = store.Projects[0];
            var wit     = project.WorkItemTypes[0];

            var tp = new KeyValuePair <string, object>(CoreFieldRefNames.TeamProject, project.Name);
            var wp = new KeyValuePair <string, object>(CoreFieldRefNames.WorkItemType, wit.Name);
            var a  = new[] { tp, wp };

            values = values?.Union(a) ?? a;

            var wi = (MockWorkItem)wit.NewWorkItem(values);

            store.BatchSave(wi);
            return(wi);
        }
示例#5
0
        public MockQueryByWiql(string query, MockWorkItemStore store)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(query));
            }

            _store = store ?? throw new ArgumentNullException(nameof(store));

            _parts = new List <Tuple <string, string, string> >();
            foreach (Match m in EqualsRegex.Matches(query))
            {
                var d = (m.Groups["direction"].Value ?? string.Empty)
                        .Replace("[", string.Empty)
                        .Replace("]", string.Empty);
                var f = m.Groups["field"].Value
                        .Replace("[", string.Empty)
                        .Replace("]", string.Empty);
                var v = m.Groups["value"]
                        .Value.Replace("'", string.Empty);

                var t = new Tuple <string, string, string>(d, f, v);
                _parts.Add(t);
            }

            foreach (Match m in InRegex.Matches(query))
            {
                var d = (m.Groups["direction"].Value ?? string.Empty)
                        .Replace("[", string.Empty)
                        .Replace("]", string.Empty);
                var f = m.Groups["field"]
                        .Value.Replace("[", string.Empty)
                        .Replace("]", string.Empty);
                var v = m.Groups["value"].Value
                        .Replace("'", string.Empty)
                        .Replace("(", string.Empty)
                        .Replace(")", string.Empty);

                var arrV = v.Split(',');
                foreach (var av in arrV)
                {
                    var t = new Tuple <string, string, string>(d, f, av.Trim());
                    _parts.Add(t);
                }
            }
        }
示例#6
0
        public static MockWorkItemStore Add(
            this MockWorkItemStore store,
            IEnumerable <IWorkItem> workItems,
            IEnumerable <IWorkItemLinkInfo> links)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (workItems == null && links == null)
            {
                throw new ArgumentException($"Both {nameof(workItems)} and {nameof(links)} cannot be null.");
            }
            if (links != null && workItems == null)
            {
                throw new ArgumentNullException(nameof(workItems), $"{nameof(workItems)} cannot be null when {nameof(links)} is not null.");
            }

            if (workItems != null)
            {
                store.BatchSave(workItems);
            }

            if (links != null && workItems != null)
            {
                var wi = workItems.ToDictionary(k => k.Id, e => e);
                foreach (var link in links.OrderBy(p => p.SourceId))
                {
                    if (link.SourceId == 0)
                    {
                        var w = wi[link.TargetId];
                        w.Links.Add(w.CreateRelatedLink(0));
                        store.BatchSave(w);
                    }
                    else
                    {
                        var w = wi[link.SourceId];
                        w.Links.Add(w.CreateRelatedLink(link.TargetId, link.LinkType));
                        store.BatchSave(w);
                    }
                }
            }

            return(store);
        }
示例#7
0
        public static MockWorkItemStore AddLink(this MockWorkItemStore store, int targetId, int sourceId, string linkType)
        {
            var child = store.Query(targetId);

            if (child == null)
            {
                throw new ArgumentException($"Parameter {nameof(targetId)} ({targetId}) does not refer to a work item in the store.");
            }

            var lt = store.WorkItemLinkTypes[linkType];

            child.Links.Add(child.CreateRelatedLink(sourceId, lt.ForwardEnd));

            store.BatchSave(child);


            return(store);
        }
示例#8
0
 public MockQueryByWiqlFactory([NotNull] MockWorkItemStore store)
 {
     _store = store ?? throw new ArgumentNullException(nameof(store));
 }
示例#9
0
 public static MockWorkItemStore Add(this MockWorkItemStore store, IEnumerable <KeyValuePair <string, object> > values)
 {
     Create(store, values);
     return(store);
 }
示例#10
0
 internal static void BatchSave(this MockWorkItemStore store, params IWorkItem[] workItems)
 {
     store.BatchSave(workItems);
 }
示例#11
0
 public static MockWorkItemStore WithLinkType(this MockWorkItemStore store, params IWorkItemLinkType[] linkTypes)
 {
     store.WorkItemLinkTypes = new WorkItemLinkTypeCollection(store.WorkItemLinkTypes.Union(linkTypes).ToList());
     return(store);
 }
示例#12
0
 public static MockWorkItemStore Add(this MockWorkItemStore store, params IWorkItem[] workItems)
 {
     return(Add(store, workItems as IEnumerable <IWorkItem>));
 }
示例#13
0
        public static MockWorkItem Generate(this MockWorkItemStore store)
        {
            var g = new WorkItemGenerator <MockWorkItem>(store.Create, new[] { "Revisions", "Item" });

            return(g.Generate(1).Single());
        }
示例#14
0
 public static MockWorkItem Create(this MockWorkItemStore store)
 {
     return(Create(store, null));
 }
示例#15
0
 public static MockWorkItemStore Add(this MockWorkItemStore store, IEnumerable <IWorkItem> workItems)
 {
     return(store.Add(workItems, null));
 }
示例#16
0
 public MockQueryByWiql(IEnumerable <int> ids, string query, MockWorkItemStore store)
     : this(query, store)
 {
     _ids = ids;
 }