Skip to content

Commit 28388b6

Browse files
committed
Merge pull request #2 from RallyTools/2.0
2.0
2 parents 8366114 + fc7b00b commit 28388b6

15 files changed

Lines changed: 504 additions & 644 deletions

Rally.RestApi.Test/HttpServiceTest.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

Rally.RestApi.Test/Rally.RestApi.Test.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
<Compile Include="QueryTest.cs" />
5858
<Compile Include="DynamicJsonSerializerTest.cs" />
5959
<Compile Include="Properties\AssemblyInfo.cs" />
60-
<Compile Include="HttpServiceTest.cs" />
6160
<Compile Include="RallyRestApiTest.cs" />
6261
<Compile Include="RefTest.cs" />
6362
<Compile Include="RequestTest.cs" />

Rally.RestApi.Test/RallyRestApiTest.cs

Lines changed: 129 additions & 153 deletions
Large diffs are not rendered by default.

Rally.RestApi.Test/RefTest.cs

Lines changed: 113 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,68 +2,140 @@
22

33
namespace Rally.RestApi.Test
44
{
5-
6-
[TestClass()]
5+
[TestClass()]
76
public class RefTest
87
{
8+
[TestMethod()]
9+
public void ShouldDetectValidRefs()
10+
{
11+
Assert.IsTrue(Ref.IsRef("/defect/1234"), "Valid relative ref");
12+
Assert.IsTrue(Ref.IsRef("/defect/1234.js"), "Valid relative ref w/ extension");
13+
Assert.IsTrue(Ref.IsRef("https://rally1.rallydev.com/slm/webservice/1.32/defect/1234"), "Valid absolute ref");
14+
Assert.IsTrue(Ref.IsRef("http://rally1.rallydev.com/slm/webservice/1.32/defect/1234.js"), "Valid absolute ref w/ extension");
15+
}
16+
17+
[TestMethod()]
18+
public void ShouldDetectValidDynatypeRefs()
19+
{
20+
Assert.IsTrue(Ref.IsRef("/portfolioitem/feature/1234"), "Valid relative ref");
21+
Assert.IsTrue(Ref.IsRef("/portfolioitem/feature/1234.js"), "Valid relative ref w/ extension");
22+
Assert.IsTrue(Ref.IsRef("https://rally1.rallydev.com/slm/webservice/1.32/portfolioitem/feature/1234"), "Valid absolute ref");
23+
Assert.IsTrue(Ref.IsRef("http://rally1.rallydev.com/slm/webservice/1.32/portfolioitem/feature/1234.js"), "Valid absolute ref w/ extension");
24+
}
25+
26+
[TestMethod()]
27+
public void ShouldDetectInvalidRefs()
28+
{
29+
Assert.IsFalse(Ref.IsRef("/defect"), "Invalid ref");
30+
Assert.IsFalse(Ref.IsRef("https://rally1.rallydev.com/slm/webservice/1.32/defect/abc.js"), "Invalid ref");
31+
Assert.IsFalse(Ref.IsRef(null), "A null ref");
32+
Assert.IsFalse(Ref.IsRef(""), "An empty string");
33+
}
34+
35+
[TestMethod()]
36+
public void ShouldReturnValidRelativeRefs()
37+
{
38+
Assert.AreEqual(Ref.GetRelativeRef("/defect/1234"), "/defect/1234", "Already relative ref");
39+
Assert.AreEqual(Ref.GetRelativeRef("/defect/1234.js"), "/defect/1234", "Already relative ref");
40+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.32/defect/1234"), "/defect/1234", "Absolute ref");
41+
}
42+
43+
[TestMethod()]
44+
public void ShouldReturnValidDynatypeRelativeRefs()
45+
{
46+
Assert.AreEqual(Ref.GetRelativeRef("/portfolioitem/feature/1234"), "/portfolioitem/feature/1234", "Already relative ref");
47+
Assert.AreEqual(Ref.GetRelativeRef("/portfolioitem/feature/1234.js"), "/portfolioitem/feature/1234", "Already relative ref");
48+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.32/portfolioitem/feature/1234"), "/portfolioitem/feature/1234", "Absolute ref");
49+
}
50+
51+
[TestMethod()]
52+
public void ShouldReturnNullRelativeRefs()
53+
{
54+
Assert.IsNull(Ref.GetRelativeRef("blah"), "Not a ref");
55+
Assert.IsNull(Ref.GetRelativeRef(""), "Empty ref");
56+
Assert.IsNull(Ref.GetRelativeRef(null), "null ref");
57+
}
58+
59+
[TestMethod()]
60+
public void ShouldReturnTypesFromRefs()
61+
{
62+
Assert.AreEqual(Ref.GetTypeFromRef("/defect/1234"), "defect", "Relative ref");
63+
Assert.AreEqual(Ref.GetTypeFromRef("/defect/1234.js"), "defect", "Relative ref with extension");
64+
Assert.AreEqual(Ref.GetTypeFromRef("https://rally1.rallydev.com/slm/webservice/1.32/defect/1234"), "defect", "Valid absolute ref");
65+
}
66+
67+
[TestMethod()]
68+
public void ShouldReturnTypesFromDynatypeRefs()
69+
{
70+
Assert.AreEqual(Ref.GetTypeFromRef("/portfolioitem/feature/1234"), "portfolioitem/feature", "Relative ref");
71+
Assert.AreEqual(Ref.GetTypeFromRef("/portfolioitem/feature/1234.js"), "portfolioitem/feature", "Relative ref with extension");
72+
Assert.AreEqual(Ref.GetTypeFromRef("https://rally1.rallydev.com/slm/webservice/1.32/portfolioitem/feature/1234"), "portfolioitem/feature", "Valid absolute ref");
73+
}
74+
75+
[TestMethod()]
76+
public void ShouldReturnNullTypesFromRefs()
77+
{
78+
Assert.IsNull(Ref.GetTypeFromRef("blah"), "Not a ref");
79+
Assert.IsNull(Ref.GetTypeFromRef(""), "Empty ref");
80+
Assert.IsNull(Ref.GetTypeFromRef(null), "null ref");
81+
}
982

83+
[TestMethod()]
84+
public void ShouldReturnOidsFromRefs()
85+
{
86+
Assert.AreEqual(Ref.GetOidFromRef("/defect/1234"), "1234", "Relative ref");
87+
Assert.AreEqual(Ref.GetOidFromRef("/defect/1234.js"), "1234", "Relative ref with extension");
88+
Assert.AreEqual(Ref.GetOidFromRef("https://rally1.rallydev.com/slm/webservice/1.32/defect/1234"), "1234", "Valid absolute ref");
89+
}
1090

11-
/// <summary>
12-
///A test for GetRelativeRef
13-
///</summary>
1491
[TestMethod()]
15-
public void GetRelativeRefTest()
92+
public void ShouldReturnOidsFromDynatypeRefs()
1693
{
17-
const string absoluteRef = "https://rally1.rallydev.com/slm/webservice/1.23/hierarchicalrequirement/415737";
18-
const string expected = "/hierarchicalrequirement/415737";
19-
var actual = Ref.GetRelativeRef(absoluteRef);
20-
Assert.AreEqual(expected, actual);
94+
Assert.AreEqual(Ref.GetOidFromRef("/portfolioitem/feature/1234"), "1234", "Relative ref");
95+
Assert.AreEqual(Ref.GetOidFromRef("/portfolioitem/feature/1234.js"), "1234", "Relative ref with extension");
96+
Assert.AreEqual(Ref.GetOidFromRef("https://rally1.rallydev.com/slm/webservice/1.32/portfolioitem/feature/1234"), "1234", "Valid absolute ref");
2197
}
2298

23-
/// <summary>
24-
///A test for GetRelativeRef
25-
///</summary>
2699
[TestMethod()]
27-
public void GetRelativeRefJsExtentionTest()
100+
public void ShouldReturnNullOidsFromRefs()
28101
{
29-
const string absoluteRef = "https://rally1.rallydev.com/slm/webservice/1.23/hierarchicalrequirement/415737.js";
30-
const string expected = "/hierarchicalrequirement/415737";
31-
var actual = Ref.GetRelativeRef(absoluteRef);
32-
Assert.AreEqual(expected, actual);
102+
Assert.IsNull(Ref.GetOidFromRef("blah"), "Not a ref");
103+
Assert.IsNull(Ref.GetOidFromRef(""), "Empty ref");
104+
Assert.IsNull(Ref.GetOidFromRef(null), "null ref");
33105
}
34106

35-
/// <summary>
36-
///A test for GetRelativeRef
37-
///</summary>
38107
[TestMethod()]
39-
public void GetRelativeRefWithRelativeRef()
40-
{
41-
const string expected = "/hierarchicalrequirement/415737";
42-
var actual = Ref.GetRelativeRef(expected);
43-
Assert.AreEqual(expected, actual);
108+
public void ShouldSupportWsapiVersionXinRefs()
109+
{
110+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/x/portfolioitem/feature/1234"), "/portfolioitem/feature/1234", "Valid absolute version x dynatype ref");
111+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/x/defect/1234"), "/defect/1234", "Valid absolute version x ref");
44112
}
45113

46-
/// <summary>
47-
///A test for GetTypeFromRef
48-
///</summary>
49114
[TestMethod()]
50-
public void GetTypeFromRefTest()
115+
public void ShouldSupportWorkspacePermissionRefs()
51116
{
52-
const string reference = "/defect/12342.js";
53-
const string expected = "defect";
54-
string actual = Ref.GetTypeFromRef(reference);
55-
Assert.AreEqual(expected, actual);
117+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.38/workspacepermission/123u456w1"), "/workspacepermission/123u456w1", "Valid workspace permission ref");
118+
Assert.AreEqual(Ref.GetOidFromRef("/workspacepermission/123u456w1.js"), "123u456w1", "Get oid from workspace permission ref");
119+
Assert.AreEqual(Ref.GetTypeFromRef("/workspacepermission/123u456w1.js"), "workspacepermission", "Get type from workspace permission ref");
56120
}
57121

58-
/// <summary>
59-
///A test for GetOidFromRef
60-
///</summary>
61122
[TestMethod()]
62-
public void GetOidFromRefTest()
123+
public void ShouldSupportProjectPermissionRefs()
63124
{
64-
const string reference = "/defect/12342.js";
65-
long actual = Ref.GetOidFromRef(reference);
66-
Assert.AreEqual(12342L, actual);
125+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.38/projectpermission/123u456p1"), "/projectpermission/123u456p1", "Valid project permission ref");
126+
Assert.AreEqual(Ref.GetOidFromRef("/projectpermission/123u456p1.js"), "123u456p1", "Get oid from project permission ref");
127+
Assert.AreEqual(Ref.GetTypeFromRef("/projectpermission/123u456p1.js"), "projectpermission", "Get type from project permission ref");
128+
}
129+
130+
[TestMethod()]
131+
public void ShouldSupportCollectionRefs()
132+
{
133+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.38/defect/1234/tasks"), "/defect/1234/tasks", "Valid collection ref");
134+
Assert.AreEqual(Ref.GetRelativeRef("/defect/1234/tasks"), "/defect/1234/tasks", "Valid relative collection ref");
135+
Assert.AreEqual(Ref.GetRelativeRef("https://rally1.rallydev.com/slm/webservice/1.38/portfolioitem/feature/1234/children"), "/portfolioitem/feature/1234/children", "Valid dynatype collection ref");
136+
Assert.AreEqual(Ref.GetRelativeRef("/portfolioitem/feature/1234/children"), "/portfolioitem/feature/1234/children", "Valid dynatype relative collection ref");
137+
Assert.AreEqual(Ref.GetRelativeRef("/attributedefinition/-12345/allowedvalues"), "/attributedefinition/-12345/allowedvalues", "Valid negative oid collection ref");
67138
}
68139
}
69140
}
141+

Rally.RestApi.Test/RequestTest.cs

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,6 @@ namespace Rally.RestApi.Test
66
[TestClass()]
77
public class RequestTest
88
{
9-
10-
/// <summary>
11-
///A test for Request Constructor
12-
///</summary>
13-
[TestMethod()]
14-
public void RequestConstructor()
15-
{
16-
const string artifactName = "Defect";
17-
const string key = "Key";
18-
var fetch = new List<string>() { "Name" };
19-
const int limit = 500;
20-
const int pageSize = 1;
21-
const string order = "Name";
22-
const string project = "/Project/1243";
23-
const bool projectScopeDown = true;
24-
const bool projectScopeUp = true;
25-
const string workSpace = "workspace/1243";
26-
const int start = 200;
27-
var query = new Query("Field", Query.Operator.Equals, "Value");
28-
var target = new AdhocRequest(artifactName, key)
29-
{
30-
Fetch = fetch,
31-
Limit = limit,
32-
PageSize = pageSize,
33-
Order = order,
34-
Project = project,
35-
ProjectScopeDown = projectScopeDown,
36-
ProjectScopeUp = projectScopeUp,
37-
Query = query,
38-
Start = start,
39-
Workspace = workSpace
40-
41-
};
42-
Assert.AreEqual(key, target.Key);
43-
Assert.AreEqual(artifactName, target.ArtifactName);
44-
Assert.AreEqual(fetch[0], target.Fetch[0]);
45-
Assert.AreEqual(fetch.Count, target.Fetch.Count);
46-
Assert.AreEqual(limit, target.Limit);
47-
Assert.AreEqual(pageSize, target.PageSize);
48-
Assert.AreEqual(start, target.Start);
49-
Assert.AreEqual(limit, target.Limit);
50-
Assert.AreEqual(order, target.Order);
51-
Assert.AreEqual(query, target.Query);
52-
Assert.AreEqual(project, target.Project);
53-
Assert.AreEqual(projectScopeDown, target.ProjectScopeDown);
54-
Assert.AreEqual(projectScopeUp, target.ProjectScopeUp);
55-
Assert.AreEqual(workSpace, target.Workspace);
56-
57-
}
58-
59-
/// <summary>
60-
///A test for Request Constructor
61-
///</summary>
62-
[TestMethod()]
63-
public void RequestConstructorDefault()
64-
{
65-
66-
var query = new Query("Field", Query.Operator.Equals, "Value");
67-
var target = new AdhocRequest("type", "key");
68-
Assert.AreEqual(0, target.Fetch.Count);
69-
Assert.AreEqual(Request.MAX_PAGE_SIZE, target.Limit);
70-
Assert.AreEqual(Request.MAX_PAGE_SIZE, target.PageSize);
71-
Assert.AreEqual(1, target.Start);
72-
Assert.IsNull(target.Order);
73-
Assert.IsNull(target.Query);
74-
Assert.IsNull(target.Project);
75-
Assert.IsNull(target.ProjectScopeDown);
76-
Assert.IsNull(target.ProjectScopeUp);
77-
Assert.IsNull(target.Workspace);
78-
79-
}
80-
819
[TestMethod]
8210
public void Clone()
8311
{
@@ -96,30 +24,41 @@ public void Clone()
9624
}
9725

9826
[TestMethod]
99-
public void TestEndpointNameSubscription()
27+
public void TestEndpointSubscription()
10028
{
10129
var request = new Request("Subscription");
10230
request.Fetch = new List<string>() { "Name" };
10331

104-
Assert.AreEqual("subscriptions", request.EndpointName);
32+
Assert.AreEqual("/subscriptions", request.Endpoint);
10533
}
10634

10735
[TestMethod]
108-
public void TestEndpointNameUser()
36+
public void TestEndpointUser()
10937
{
11038
var request = new Request("User");
11139
request.Fetch = new List<string>() { "FirstName" };
11240

113-
Assert.AreEqual("users", request.EndpointName);
41+
Assert.AreEqual("/users", request.Endpoint);
11442
}
11543

11644
[TestMethod]
117-
public void TestEndpointNameDefect()
45+
public void TestEndpointDefect()
11846
{
11947
var request = new Request("Defect");
12048
request.Fetch = new List<string>() { "Name" };
12149

122-
Assert.AreEqual("defect", request.EndpointName);
50+
Assert.AreEqual("/defect", request.Endpoint);
51+
}
52+
53+
[TestMethod]
54+
public void TestEndpointCollection()
55+
{
56+
DynamicJsonObject collection = new DynamicJsonObject();
57+
collection["_ref"] = "https://rally1.rallydev.com/slm/webservice/v2.0/defect/12345/tasks";
58+
59+
var request = new Request(collection);
60+
61+
Assert.AreEqual("/defect/12345/tasks", request.Endpoint);
12362
}
12463
}
12564
}

0 commit comments

Comments
 (0)