|
2 | 2 |
|
3 | 3 | namespace Rally.RestApi.Test |
4 | 4 | { |
5 | | - |
6 | | - [TestClass()] |
| 5 | + [TestClass()] |
7 | 6 | public class RefTest |
8 | 7 | { |
| 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 | + } |
9 | 82 |
|
| 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 | + } |
10 | 90 |
|
11 | | - /// <summary> |
12 | | - ///A test for GetRelativeRef |
13 | | - ///</summary> |
14 | 91 | [TestMethod()] |
15 | | - public void GetRelativeRefTest() |
| 92 | + public void ShouldReturnOidsFromDynatypeRefs() |
16 | 93 | { |
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"); |
21 | 97 | } |
22 | 98 |
|
23 | | - /// <summary> |
24 | | - ///A test for GetRelativeRef |
25 | | - ///</summary> |
26 | 99 | [TestMethod()] |
27 | | - public void GetRelativeRefJsExtentionTest() |
| 100 | + public void ShouldReturnNullOidsFromRefs() |
28 | 101 | { |
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"); |
33 | 105 | } |
34 | 106 |
|
35 | | - /// <summary> |
36 | | - ///A test for GetRelativeRef |
37 | | - ///</summary> |
38 | 107 | [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"); |
44 | 112 | } |
45 | 113 |
|
46 | | - /// <summary> |
47 | | - ///A test for GetTypeFromRef |
48 | | - ///</summary> |
49 | 114 | [TestMethod()] |
50 | | - public void GetTypeFromRefTest() |
| 115 | + public void ShouldSupportWorkspacePermissionRefs() |
51 | 116 | { |
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"); |
56 | 120 | } |
57 | 121 |
|
58 | | - /// <summary> |
59 | | - ///A test for GetOidFromRef |
60 | | - ///</summary> |
61 | 122 | [TestMethod()] |
62 | | - public void GetOidFromRefTest() |
| 123 | + public void ShouldSupportProjectPermissionRefs() |
63 | 124 | { |
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"); |
67 | 138 | } |
68 | 139 | } |
69 | 140 | } |
| 141 | + |
0 commit comments