Example #1
0
 static partial void InstanceFactory(ref WorkItemImpl instance, string callerName)
 {
     if (callerName == "Revisions_UnitTest")
     {
         instance = JsonWorkItem.APIFactory().GetWorkItem(95, WorkItemImpl.FromToken).Result;
     }
 }
        /// <summary>
        ///     Gets the test instance.
        /// </summary>
        /// <returns>IWorkItemCollection.</returns>
        private IWorkItemCollection GetTestInstance()
        {
            var initialItems = new List <WorkItemImpl>();

            initialItems.Add(JsonWorkItem.APIFactory().GetWorkItem(195, WorkItemImpl.FromToken).Result);
            var instance = new WorkItemCollectionImpl(null, initialItems);

            Assert.IsNotNull(instance);
            return(instance);
        }
Example #3
0
 /// <summary>
 /// Gets the definition.
 /// </summary>
 /// <param name="referenceName">Name of the reference.</param>
 /// <returns>JsonFieldDefinition.</returns>
 public static JsonFieldDefinition GetDefinition(string referenceName)
 {
     if (s_Cache == null)
     {
         IReadOnlyList <JsonFieldDefinition> definitions = JsonWorkItem.APIFactory().GetFieldDefinitions().Result;
         s_Cache = new Dictionary <string, JsonFieldDefinition>();
         foreach (var definition in definitions)
         {
             s_Cache.Add(definition.ReferenceName, definition);
         }
     }
     return(s_Cache[referenceName]);
 }
Example #4
0
        public static TWorkItem BuildWorkItem <TWorkItem>(string projectName, string workItemTypeName, IReadOnlyList <KeyValuePair <string, object> > fieldValues, Func <JToken, TWorkItem> fromToken) where TWorkItem : JsonWorkItem
        {
            Task <IReadOnlyDictionary <string, JsonWorkItemType> > workItemTypes = JsonWorkItem.APIFactory().GetWorkItemTypes(projectName);
            JsonWorkItemType workItemType             = workItemTypes.Result[workItemTypeName];
            JsonFieldDefinitionCollection definitions = workItemType.FieldDefinitions;
            var json = new JObject();

            json.Add(new JProperty("id", "-1"));
            json.Add(new JProperty("rev", "-1"));
            json.Add(new JProperty("url", "http://example.com"));
            var jFieldContainer = new JObject();
            var jFieldsProperty = new JProperty("fields", jFieldContainer);

            foreach (JsonFieldDefinition fieldDefinition in definitions)
            {
                object content = null;
                switch (fieldDefinition.ReferenceName)
                {
                case "System.TeamProject":
                    content = projectName;
                    break;

                case "System.WorkItemType":
                    content = workItemTypeName;
                    break;

                case "System.Id":
                    content = -1;
                    break;

                case "System.Rev":
                    content = -1;
                    break;
                }
                var jProperty = new JProperty(fieldDefinition.ReferenceName, content);
                jFieldContainer.Add(jProperty);
            }
            json.Add(jFieldsProperty);
            TWorkItem retVal = fromToken(json);

            foreach (KeyValuePair <string, object> field in fieldValues)
            {
                retVal.SetFieldValue(field.Key, field.Value);
            }
            return(retVal);
        }
Example #5
0
        /// <summary>
        ///     Froms the token.
        /// </summary>
        /// <param name="json">The json.</param>
        /// <returns>JsonRelatedLink.</returns>
        public new static JsonRelatedLink FromToken(JToken json)
        {
            var initializer = new JsonWorkItemInitializer
            {
                OtherItemInitializer = new ParameterizedLazyWithReset <JsonRelatedLink, WorkItemImpl>(o =>
                {
                    WorkItemImpl retVal = JsonWorkItem.APIFactory().GetWorkItem(new Uri(sr_Url.Eval(o)), WorkItemImpl.FromToken);
                    return(retVal);
                }),
                LinkTypeEndInitializer = new ParameterizedLazyWithReset <JsonRelatedLink, WorkItemLinkTypeEndImpl>(o =>
                {
                    JProperty property = ((JObject)o.JsonValue).Properties().FirstOrDefault(p => p.Name == "rel");
                    var retVal         = new WorkItemLinkTypeEndImpl(property.Value);
                    return(retVal);
                })
            };

            return(new RelatedLinkImpl(json, initializer));
        }
        /// <summary>
        ///     Queries the count.
        /// </summary>
        /// <param name="wiql">The wiql.</param>
        /// <returns>Int32.</returns>
        Int32 IWorkItemStore.QueryCount(String wiql)
        {
            IReadOnlyList <JsonWorkItem> result = JsonWorkItem.APIFactory().WiqlQuery(wiql, true).Result;

            return(result.Count);
        }
        /// <summary>
        ///     Queries the specified wiql.
        /// </summary>
        /// <param name="wiql">The wiql.</param>
        /// <returns>IWorkItemCollection.</returns>
        IWorkItemCollection IWorkItemStore.Query(String wiql)
        {
            IReadOnlyList <WorkItemImpl> result = JsonWorkItem.APIFactory().WiqlQuery(wiql, true, WorkItemImpl.FromToken).Result;

            return(new WorkItemCollectionImpl(this, result));
        }
        /// <summary>
        ///     Gets the work item.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns>IWorkItem.</returns>
        /// <exception cref="ToBeImplementedException"></exception>
        IWorkItem IWorkItemStore.GetWorkItem(Int32 id)
        {
            WorkItemImpl result = JsonWorkItem.APIFactory().GetWorkItem(id, WorkItemImpl.FromToken).Result;

            return(result);
        }