Skip to content

Commit 887ffda

Browse files
committed
Merge pull request #20 from RusticiSoftware/tfo/improvement/activityid-uri-string
Switch to String from Uri for Representing Activity IDs
2 parents dd1794a + 9615d4f commit 887ffda

5 files changed

Lines changed: 79 additions & 7 deletions

File tree

TinCan/Activity.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ public class Activity : JsonModel, StatementTarget
2424
public static readonly String OBJECT_TYPE = "Activity";
2525
public String ObjectType { get { return OBJECT_TYPE; } }
2626

27-
public Uri id { get; set; }
27+
private string _id;
28+
public string id
29+
{
30+
get { return _id; }
31+
set
32+
{
33+
Uri uri = new Uri(value);
34+
_id = value;
35+
}
36+
}
37+
2838
public ActivityDefinition definition { get; set; }
2939

3040
public Activity() { }
@@ -35,7 +45,9 @@ public Activity(JObject jobj)
3545
{
3646
if (jobj["id"] != null)
3747
{
38-
id = new Uri(jobj.Value<String>("id"));
48+
string idFromJSON = jobj.Value<String>("id");
49+
Uri uri = new Uri(idFromJSON);
50+
id = idFromJSON;
3951
}
4052
if (jobj["definition"] != null)
4153
{
@@ -50,7 +62,7 @@ public override JObject ToJObject(TCAPIVersion version)
5062

5163
if (id != null)
5264
{
53-
result.Add("id", id.ToString());
65+
result.Add("id", id);
5466
}
5567
if (definition != null)
5668
{

TinCan/StatementsQuery.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ public class StatementsQuery
2525

2626
public Agent agent { get; set; }
2727
public Uri verbId { get; set; }
28-
public Uri activityId { get; set; }
28+
private string _activityId;
29+
public string activityId {
30+
get { return _activityId; }
31+
set
32+
{
33+
Uri uri = new Uri(value);
34+
_activityId = value;
35+
}
36+
}
2937
public Nullable<Guid> registration { get; set; }
3038
public Nullable<Boolean> relatedActivities { get; set; }
3139
public Nullable<Boolean> relatedAgents { get; set; }
@@ -51,7 +59,7 @@ public Dictionary<String, String> ToParameterMap (TCAPIVersion version)
5159
}
5260
if (activityId != null)
5361
{
54-
result.Add("activity", activityId.ToString());
62+
result.Add("activity", activityId);
5563
}
5664
if (registration != null)
5765
{

TinCanTests/ActivityTest.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Copyright 2014 Rustici Software
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
namespace TinCanTests
17+
{
18+
using NUnit.Framework;
19+
using TinCan;
20+
21+
[TestFixture]
22+
class ActivityTest
23+
{
24+
[Test]
25+
public void TestActivityIdTrailingSlash()
26+
{
27+
var activity = new Activity();
28+
string noTrailingSlash = "http://foo";
29+
activity.id = noTrailingSlash;
30+
Assert.AreEqual(noTrailingSlash, activity.id);
31+
}
32+
33+
[Test]
34+
public void TestActivityIdCase()
35+
{
36+
var activity = new Activity();
37+
string mixedCase = "http://fOO";
38+
activity.id = mixedCase;
39+
Assert.AreEqual(mixedCase, activity.id);
40+
}
41+
42+
[Test]
43+
[ExpectedException("System.UriFormatException")]
44+
public void TestActivityIdInvalidUri()
45+
{
46+
var activity = new Activity();
47+
string invalid = "foo";
48+
activity.id = invalid;
49+
}
50+
}
51+
}

TinCanTests/Support.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static Support () {
4040
verb.display.Add("en-US", "experienced");
4141

4242
activity = new Activity();
43-
activity.id = new Uri("http://tincanapi.com/TinCanCSharp/Test/Unit/0");
43+
activity.id = "http://tincanapi.com/TinCanCSharp/Test/Unit/0";
4444
activity.definition = new ActivityDefinition();
4545
activity.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test");
4646
activity.definition.name = new LanguageMap();
@@ -49,7 +49,7 @@ static Support () {
4949
activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");
5050

5151
parent = new Activity();
52-
parent.id = new Uri("http://tincanapi.com/TinCanCSharp/Test");
52+
parent.id = "http://tincanapi.com/TinCanCSharp/Test";
5353
parent.definition = new ActivityDefinition();
5454
parent.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite");
5555
//parent.definition.moreInfo = new Uri("http://rusticisoftware.github.io/TinCanCSharp/");

TinCanTests/TinCanTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Reference Include="System.XML" />
7272
</ItemGroup>
7373
<ItemGroup>
74+
<Compile Include="ActivityTest.cs" />
7475
<Compile Include="AgentTest.cs" />
7576
<Compile Include="ResultTest.cs" />
7677
<Compile Include="Support.cs" />

0 commit comments

Comments
 (0)