Skip to content

Commit 0cc73f0

Browse files
author
Freddie O'Connell
committed
Because of how the xAPI spec handles Activity ID comparision, we
can't rely on System.Uri, which normalizes URI's passed to the string constructor. So, e.g., "http://foo" would become "http://foo/", which is considered a different Activity ID. Instead, we now use String as a representation of Activity IDs, preferring only to validate via Uri.
1 parent c38178a commit 0cc73f0

3 files changed

Lines changed: 26 additions & 6 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: 9 additions & 1 deletion
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; }

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/");

0 commit comments

Comments
 (0)