Skip to content

Commit 92954dd

Browse files
committed
Merge pull request #9 from brianjmiller/master
SubStatement as 'object' in Statement handling
2 parents c41f76c + 3a13961 commit 92954dd

7 files changed

Lines changed: 281 additions & 106 deletions

File tree

TinCan/Statement.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public Statement(JObject jobj) : base(jobj) {
5050
{
5151
version = (TCAPIVersion)jobj.Value<String>("version");
5252
}
53+
54+
//
55+
// handle SubStatement as target which isn't provided by StatementBase
56+
// because SubStatements are not allowed to nest
57+
//
58+
if (jobj["object"] != null && (String)jobj["object"]["objectType"] == SubStatement.OBJECT_TYPE)
59+
{
60+
target = (SubStatement)jobj.Value<JObject>("object");
61+
}
5362
}
5463

5564
public override JObject ToJObject(TCAPIVersion version)

TinCan/StatementBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ public StatementBase(JObject jobj)
6666
{
6767
target = (Activity)jobj.Value<JObject>("object");
6868
}
69+
else if ((String)jobj["object"]["objectType"] == StatementRef.OBJECT_TYPE)
70+
{
71+
target = (StatementRef)jobj.Value<JObject>("object");
72+
}
6973
}
7074
else
7175
{

TinCanTests/RemoteLRSResourceTest.cs

Lines changed: 51 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -29,77 +29,22 @@ namespace TinCanTests
2929
class RemoteLRSResourceTest
3030
{
3131
RemoteLRS lrs;
32-
Agent agent;
33-
Verb verb;
34-
Activity activity;
35-
Activity parent;
36-
Context context;
37-
Result result;
38-
Score score;
39-
StatementRef statementRef;
40-
SubStatement subStatement;
4132

4233
[SetUp]
4334
public void Init()
4435
{
4536
Console.WriteLine("Running " + TestContext.CurrentContext.Test.FullName);
37+
38+
//
39+
// these are credentials used by the other OSS libs when building via Travis-CI
40+
// so are okay to include in the repository, if you wish to have access to the
41+
// results of the test suite then supply your own endpoint, username, and password
42+
//
4643
lrs = new RemoteLRS(
47-
"",
48-
"",
49-
""
44+
"https://cloud.scorm.com/tc/SYPGYC448W/sandbox/",
45+
"-DOzXB-DAFR1O3RAazI",
46+
"pL-Kyru9fUCFE8981N4"
5047
);
51-
52-
agent = new Agent();
53-
agent.mbox = "mailto:tincancsharp@tincanapi.com";
54-
55-
verb = new Verb("http://adlnet.gov/expapi/verbs/experienced");
56-
verb.display = new LanguageMap();
57-
verb.display.Add("en-US", "experienced");
58-
59-
activity = new Activity();
60-
activity.id = new Uri("http://tincanapi.com/TinCanCSharp/Test/Unit/0");
61-
activity.definition = new ActivityDefinition();
62-
activity.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test");
63-
activity.definition.name = new LanguageMap();
64-
activity.definition.name.Add("en-US", "Tin Can C# Tests: Unit 0");
65-
activity.definition.description = new LanguageMap();
66-
activity.definition.description.Add("en-US", "Unit test 0 in the test suite for the Tin Can C# library.");
67-
68-
parent = new Activity();
69-
parent.id = new Uri("http://tincanapi.com/TinCanCSharp/Test");
70-
parent.definition = new ActivityDefinition();
71-
parent.definition.type = new Uri("http://id.tincanapi.com/activitytype/unit-test-suite");
72-
//parent.definition.moreInfo = new Uri("http://rusticisoftware.github.io/TinCanCSharp/");
73-
parent.definition.name = new LanguageMap();
74-
parent.definition.name.Add("en-US", "Tin Can C# Tests");
75-
parent.definition.description = new LanguageMap();
76-
parent.definition.description.Add("en-US", "Unit test suite for the Tin Can C# library.");
77-
78-
statementRef = new StatementRef(Guid.NewGuid());
79-
80-
context = new Context();
81-
context.registration = Guid.NewGuid();
82-
context.statement = statementRef;
83-
context.contextActivities = new ContextActivities();
84-
context.contextActivities.parent = new List<Activity>();
85-
context.contextActivities.parent.Add(parent);
86-
87-
score = new Score();
88-
score.raw = 97;
89-
score.scaled = 0.97;
90-
score.max = 100;
91-
score.min = 0;
92-
93-
result = new Result();
94-
result.score = score;
95-
result.success = true;
96-
result.completion = true;
97-
result.duration = new TimeSpan(1, 2, 16, 43);
98-
99-
subStatement = new SubStatement();
100-
subStatement.actor = agent;
101-
subStatement.verb = verb;
102-
subStatement.target = parent;
10348
}
10449

10550
[Test]
@@ -123,9 +68,9 @@ public void TestAboutFailure()
12368
public void TestSaveStatement()
12469
{
12570
var statement = new Statement();
126-
statement.actor = agent;
127-
statement.verb = verb;
128-
statement.target = activity;
71+
statement.actor = Support.agent;
72+
statement.verb = Support.verb;
73+
statement.target = Support.activity;
12974

13075
StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
13176
Assert.IsTrue(lrsRes.success);
@@ -138,9 +83,9 @@ public void TestSaveStatementWithID()
13883
{
13984
var statement = new Statement();
14085
statement.Stamp();
141-
statement.actor = agent;
142-
statement.verb = verb;
143-
statement.target = activity;
86+
statement.actor = Support.agent;
87+
statement.verb = Support.verb;
88+
statement.target = Support.activity;
14489

14590
StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
14691
Assert.IsTrue(lrsRes.success);
@@ -152,9 +97,9 @@ public void TestSaveStatementStatementRef()
15297
{
15398
var statement = new Statement();
15499
statement.Stamp();
155-
statement.actor = agent;
156-
statement.verb = verb;
157-
statement.target = statementRef;
100+
statement.actor = Support.agent;
101+
statement.verb = Support.verb;
102+
statement.target = Support.statementRef;
158103

159104
StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
160105
Assert.IsTrue(lrsRes.success);
@@ -166,9 +111,9 @@ public void TestSaveStatementSubStatement()
166111
{
167112
var statement = new Statement();
168113
statement.Stamp();
169-
statement.actor = agent;
170-
statement.verb = verb;
171-
statement.target = subStatement;
114+
statement.actor = Support.agent;
115+
statement.verb = Support.verb;
116+
statement.target = Support.subStatement;
172117

173118
Console.WriteLine(statement.ToJSON(true));
174119

@@ -181,15 +126,15 @@ public void TestSaveStatementSubStatement()
181126
public void TestSaveStatements()
182127
{
183128
var statement1 = new Statement();
184-
statement1.actor = agent;
185-
statement1.verb = verb;
186-
statement1.target = parent;
129+
statement1.actor = Support.agent;
130+
statement1.verb = Support.verb;
131+
statement1.target = Support.parent;
187132

188133
var statement2 = new Statement();
189-
statement2.actor = agent;
190-
statement2.verb = verb;
191-
statement2.target = activity;
192-
statement2.context = context;
134+
statement2.actor = Support.agent;
135+
statement2.verb = Support.verb;
136+
statement2.target = Support.activity;
137+
statement2.context = Support.context;
193138

194139
var statements = new List<Statement>();
195140
statements.Add(statement1);
@@ -205,11 +150,11 @@ public void TestRetrieveStatement()
205150
{
206151
var statement = new TinCan.Statement();
207152
statement.Stamp();
208-
statement.actor = agent;
209-
statement.verb = verb;
210-
statement.target = activity;
211-
statement.context = context;
212-
statement.result = result;
153+
statement.actor = Support.agent;
154+
statement.verb = Support.verb;
155+
statement.target = Support.activity;
156+
statement.context = Support.context;
157+
statement.result = Support.result;
213158

214159
StatementLRSResponse saveRes = lrs.SaveStatement(statement);
215160
if (saveRes.success)
@@ -228,9 +173,9 @@ public void TestRetrieveStatement()
228173
public void TestQueryStatements()
229174
{
230175
var query = new TinCan.StatementsQuery();
231-
query.agent = agent;
232-
query.verbId = verb.id;
233-
query.activityId = parent.id;
176+
query.agent = Support.agent;
177+
query.verbId = Support.verb.id;
178+
query.activityId = Support.parent.id;
234179
query.relatedActivities = true;
235180
query.relatedAgents = true;
236181
query.format = StatementsQueryResultFormat.IDS;
@@ -264,23 +209,23 @@ public void TestMoreStatements()
264209
[Test]
265210
public void TestRetrieveStateIds()
266211
{
267-
ProfileKeysLRSResponse lrsRes = lrs.RetrieveStateIds(activity, agent);
212+
ProfileKeysLRSResponse lrsRes = lrs.RetrieveStateIds(Support.activity, Support.agent);
268213
Assert.IsTrue(lrsRes.success);
269214
}
270215

271216
[Test]
272217
public void TestRetrieveState()
273218
{
274-
StateLRSResponse lrsRes = lrs.RetrieveState("test", activity, agent);
219+
StateLRSResponse lrsRes = lrs.RetrieveState("test", Support.activity, Support.agent);
275220
Assert.IsTrue(lrsRes.success);
276221
}
277222

278223
[Test]
279224
public void TestSaveState()
280225
{
281226
var doc = new StateDocument();
282-
doc.activity = activity;
283-
doc.agent = agent;
227+
doc.activity = Support.activity;
228+
doc.agent = Support.agent;
284229
doc.id = "test";
285230
doc.content = System.Text.Encoding.UTF8.GetBytes("Test value");
286231

@@ -292,8 +237,8 @@ public void TestSaveState()
292237
public void TestDeleteState()
293238
{
294239
var doc = new StateDocument();
295-
doc.activity = activity;
296-
doc.agent = agent;
240+
doc.activity = Support.activity;
241+
doc.agent = Support.agent;
297242
doc.id = "test";
298243

299244
LRSResponse lrsRes = lrs.DeleteState(doc);
@@ -303,29 +248,29 @@ public void TestDeleteState()
303248
[Test]
304249
public void TestClearState()
305250
{
306-
LRSResponse lrsRes = lrs.ClearState(activity, agent);
251+
LRSResponse lrsRes = lrs.ClearState(Support.activity, Support.agent);
307252
Assert.IsTrue(lrsRes.success);
308253
}
309254

310255
[Test]
311256
public void TestRetrieveActivityProfileIds()
312257
{
313-
ProfileKeysLRSResponse lrsRes = lrs.RetrieveActivityProfileIds(activity);
258+
ProfileKeysLRSResponse lrsRes = lrs.RetrieveActivityProfileIds(Support.activity);
314259
Assert.IsTrue(lrsRes.success);
315260
}
316261

317262
[Test]
318263
public void TestRetrieveActivityProfile()
319264
{
320-
ActivityProfileLRSResponse lrsRes = lrs.RetrieveActivityProfile("test", activity);
265+
ActivityProfileLRSResponse lrsRes = lrs.RetrieveActivityProfile("test", Support.activity);
321266
Assert.IsTrue(lrsRes.success);
322267
}
323268

324269
[Test]
325270
public void TestSaveActivityProfile()
326271
{
327272
var doc = new ActivityProfileDocument();
328-
doc.activity = activity;
273+
doc.activity = Support.activity;
329274
doc.id = "test";
330275
doc.content = System.Text.Encoding.UTF8.GetBytes("Test value");
331276

@@ -337,7 +282,7 @@ public void TestSaveActivityProfile()
337282
public void TestDeleteActivityProfile()
338283
{
339284
var doc = new ActivityProfileDocument();
340-
doc.activity = activity;
285+
doc.activity = Support.activity;
341286
doc.id = "test";
342287

343288
LRSResponse lrsRes = lrs.DeleteActivityProfile(doc);
@@ -347,22 +292,22 @@ public void TestDeleteActivityProfile()
347292
[Test]
348293
public void TestRetrieveAgentProfileIds()
349294
{
350-
ProfileKeysLRSResponse lrsRes = lrs.RetrieveAgentProfileIds(agent);
295+
ProfileKeysLRSResponse lrsRes = lrs.RetrieveAgentProfileIds(Support.agent);
351296
Assert.IsTrue(lrsRes.success);
352297
}
353298

354299
[Test]
355300
public void TestRetrieveAgentProfile()
356301
{
357-
AgentProfileLRSResponse lrsRes = lrs.RetrieveAgentProfile("test", agent);
302+
AgentProfileLRSResponse lrsRes = lrs.RetrieveAgentProfile("test", Support.agent);
358303
Assert.IsTrue(lrsRes.success);
359304
}
360305

361306
[Test]
362307
public void TestSaveAgentProfile()
363308
{
364309
var doc = new AgentProfileDocument();
365-
doc.agent = agent;
310+
doc.agent = Support.agent;
366311
doc.id = "test";
367312
doc.content = System.Text.Encoding.UTF8.GetBytes("Test value");
368313

@@ -374,7 +319,7 @@ public void TestSaveAgentProfile()
374319
public void TestDeleteAgentProfile()
375320
{
376321
var doc = new AgentProfileDocument();
377-
doc.agent = agent;
322+
doc.agent = Support.agent;
378323
doc.id = "test";
379324

380325
LRSResponse lrsRes = lrs.DeleteAgentProfile(doc);

0 commit comments

Comments
 (0)