我找不到通过C#向用户故事添加标记值的语法。
使用最新的Rally API二进制文件2.0 Beta。
我能找到的最接近的例子是通过Java ( How to add Tags to a TestCase in Rally using Rally's JAVA API? ),这看起来很有帮助,但是从这个例子看,我需要访问JSONArray和JSONElement,但是我的C#部署像Rally example一样通过RestAPI使用DynamicJSONObject
,但是JSONArray
和DynamicJSONArray
(以及JSONElement
)都没有通过RestAPI引用公开。
我可以通过添加微软的System.Web.Helpers
参考来启用DynamicJSONArray
访问,但是微软的DynamicJSonArray
参考与RestAPI变体竞争……
我可以使用全名来限定restapi的变体来解决这个问题,但是我真的不想在没有清晰的视图的情况下开始这条路,如果它会导致一些东西,我通过一个微软的DyamicJSONArray
进入拉力赛DyamicJSONObject
,我怀疑它是否会有任何功能。
有没有人可以让C#代码做一些简单的事情,比如创建标记并将其分配给用户故事或测试用例?
发布于 2013-04-03 23:43:06
下面是一个简单的示例,它使用现有标记和新创建的标记来更新Story上的标记集合:
namespace RestExample_UpdateStoryTags
{
class Program
{
static void Main(string[] args)
{
//Initialize the REST API
RallyRestApi restApi;
String rallyUserName = "user@company.com";
String rallyPassword = "topsecret";
String rallyURL = "https://rally1.rallydev.com";
String wsapiVersion = "1.41";
String myWorkspaceName = "My Workspace";
restApi = new RallyRestApi(
rallyUserName,
rallyPassword,
rallyURL,
wsapiVersion
);
// Get a Reference to Target Workspace
Request workspaceRequest = new Request("workspace");
workspaceRequest.Fetch = new List<string>()
{
"Name",
"ObjectID"
};
workspaceRequest.Query = new Query("Name", Query.Operator.Equals, myWorkspaceName);
QueryResult workspaceQueryResults = restApi.Query(workspaceRequest);
var targetWorkspace = workspaceQueryResults.Results.First();
Console.WriteLine("Found Target Workspace: " + targetWorkspace["Name"]);
String workspaceRef = targetWorkspace["_ref"];
//Query for Target Tag
Request tagRequest = new Request("tag");
tagRequest.Fetch = new List<string>()
{
"Name",
"ObjectID"
};
// Query all Tags for a tag named "Montane"
tagRequest.Query = new Query("Name", Query.Operator.Equals, "Tundra");
QueryResult queryTagResults = restApi.Query(tagRequest);
var targetTagResult = queryTagResults.Results.First();
long tagOID = targetTagResult["ObjectID"];
DynamicJsonObject targetTag = restApi.GetByReference("tag", tagOID, "Name", "ObjectID");
// Query for User Story
// FormattedID of target story
String targetStoryFormattedID = "US5";
Request storyRequest = new Request("hierarchicalrequirement");
storyRequest.Fetch = new List<string>()
{
"Name",
"ObjectID",
"Iteration",
"FormattedID",
"Tags"
};
storyRequest.Query = new Query("FormattedID", Query.Operator.Equals, targetStoryFormattedID);
QueryResult queryStoryResults = restApi.Query(storyRequest);
var targetUserStory = queryStoryResults.Results.First();
Console.WriteLine("Found Target User Story: " + targetUserStory["Name"]);
// Grab collection of existing Tags
var existingTags = targetUserStory["Tags"];
// Summarize Existing Tags
Console.WriteLine("Existing Tags for Story" + targetStoryFormattedID + ": ");
foreach (var tag in existingTags)
{
Console.WriteLine(tag["Name"]);
}
long targetOID = targetUserStory["ObjectID"];
// Now do update of the User Story
// Tags collection on object is expected to be a System.Collections.ArrayList
var targetTagArray = existingTags;
targetTagArray.Add(targetTag);
DynamicJsonObject toUpdate = new DynamicJsonObject();
toUpdate["Tags"] = targetTagArray;
OperationResult updateResult = restApi.Update("HierarchicalRequirement", targetOID, toUpdate);
foreach (var error in updateResult.Errors)
{
Console.WriteLine(error.ToString());
}
// Re-read target Story
DynamicJsonObject updatedStory = restApi.GetByReference(targetUserStory["_ref"], "Tags,Name");
var updatedTags = updatedStory["Tags"];
// Summarize Updated Tags
Console.WriteLine("Updated Tags for Story" + targetStoryFormattedID + ": ");
foreach (var tag in updatedTags)
{
Console.WriteLine(tag["Name"]);
}
// Create a New Tag, and add New Tag to Story
DynamicJsonObject newTag = new DynamicJsonObject();
newTag["Name"] = "Boreal";
CreateResult createResult = restApi.Create(workspaceRef, "Tag", newTag);
// Get the ref of the created Tag
String newTagRef = createResult.Reference;
// Read the Target Tag
DynamicJsonObject newTagRead = restApi.GetByReference(newTagRef, "Name");
// Add the newly-created Tag to the Story
targetTagArray.Add(newTagRead);
toUpdate["Tags"] = targetTagArray;
updateResult = restApi.Update("HierarchicalRequirement", targetOID, toUpdate);
// Re-read target Story
updatedStory = restApi.GetByReference(targetUserStory["_ref"], "Tags,Name");
updatedTags = updatedStory["Tags"];
// Summarize Updated Tags
Console.WriteLine("Updated Tags (with newly-created Tag for Story" + targetStoryFormattedID + ": ");
foreach (var tag in updatedTags)
{
Console.WriteLine(tag["Name"]);
}
Console.ReadKey();
}
}
}
发布于 2013-04-04 20:47:36
//Based on Mark's code, below comes close... but updates still failing
//Maybe I need to try an earlier version?
String strTeam = "xxx";
String workspaceRef = "/workspace/4914063320";
String projectRef = "/project/7412041414";
//get user story
Request reqUserStory = new Request("hierarchicalrequirement");
reqUserStory.Fetch = new List<string>() { "ObjectID", "Release", "Iteration", "PlanEstimate", "Description", "Tags" };
reqUserStory.Query = new Query("Project", Query.Operator.Equals, projectRef)
.And(new Query("Name", Query.Operator.Equals, "mystoryname"));
QueryResult queryResultUS = restApi.Query(reqUserStory);
DynamicJsonObject myUserStory = new DynamicJsonObject();
myUserStory = queryResultUS.Results.FirstOrDefault();
if (null != myUserStory)
{
//get tags for user story
var existingTags = myUserStory["Tags"];
if (null != existingTags)
{
bool bFound = false;
var tagList = existingTags["_tagsNameArray"];
//look for tag
foreach (var tag in tagList)
{
String strValue = tag["Name"];
if (strValue == strTeam)
bFound = true;
}
if (!bFound)
{
//replace tags array
var targetTagArray = existingTags;
var tagList2 = targetTagArray["_tagsNameArray"];
tagList2.Add(targetTag);//even if i comment this out, update below fails...
targetTagArray["_tagsNameArray"] = tagList2;
DynamicJsonObject toUpdate = new DynamicJsonObject();
toUpdate["Tags"] = targetTagArray;
long oid = Convert.ToInt64(myUserStory["ObjectID"]);
opResultRelease = restApi.Update("hierarchicalrequirement", oid, toUpdate);
// Fails with Error: ["Could not read: Could not read referenced object 2"]
}
}
}
https://stackoverflow.com/questions/15786631
复制相似问题