Skip to content

Commit 4fc38ed

Browse files
committed
Merge pull request #12 from brianjmiller/master
Correct use of result.duration and "registration" for State documents
2 parents 92954dd + 0c8f61c commit 4fc38ed

8 files changed

Lines changed: 110 additions & 9 deletions

File tree

Doc/Doc.shfbproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Argument Key="logoAlignment" Value="left" xmlns="" />
2727
<Argument Key="maxVersionParts" Value="" xmlns="" />
2828
</TransformComponentArguments>
29-
<BuildAssemblerVerbosity>OnlyWarningsAndErrors</BuildAssemblerVerbosity>
29+
<BuildAssemblerVerbosity>OnlyErrors</BuildAssemblerVerbosity>
3030
<HelpFileFormat>Website</HelpFileFormat>
3131
<IndentHtml>False</IndentHtml>
3232
<KeepLogFile>True</KeepLogFile>
@@ -49,6 +49,7 @@
4949
<FeedbackEMailLinkText>support%40tincanapi.com</FeedbackEMailLinkText>
5050
<FeedbackEMailAddress>support%40tincanapi.com</FeedbackEMailAddress>
5151
<CopyrightText>2014 Rustici Software</CopyrightText>
52+
<MissingTags>AutoDocumentCtors, AutoDocumentDispose</MissingTags>
5253
</PropertyGroup>
5354
<!-- There are no properties for these groups. AnyCPU needs to appear in order for Visual Studio to perform
5455
the build. The others are optional common platform types that may appear. -->

TinCan/Documents/StateDocument.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public class StateDocument : Document
2121
{
2222
public Activity activity { get; set; }
2323
public Agent agent { get; set; }
24-
public Guid registration { get; set; }
24+
public Nullable<Guid> registration { get; set; }
2525
}
2626
}

TinCan/RemoteLRS.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ public StateLRSResponse RetrieveState(String id, Activity activity, Agent agent,
552552
state.activity = activity;
553553
state.agent = agent;
554554

555+
if (registration != null)
556+
{
557+
queryParams.Add("registration", registration.ToString());
558+
state.registration = registration;
559+
}
560+
555561
var resp = GetDocument("activities/state", queryParams, state);
556562
if (resp.status != HttpStatusCode.OK && resp.status != HttpStatusCode.NotFound)
557563
{
@@ -570,6 +576,10 @@ public LRSResponse SaveState(StateDocument state)
570576
queryParams.Add("stateId", state.id);
571577
queryParams.Add("activityId", state.activity.id.ToString());
572578
queryParams.Add("agent", state.agent.ToJSON(version));
579+
if (state.registration != null)
580+
{
581+
queryParams.Add("registration", state.registration.ToString());
582+
}
573583

574584
return SaveDocument("activities/state", queryParams, state);
575585
}

TinCan/Result.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Result : JsonModel
2525
public Nullable<Boolean> completion { get; set; }
2626
public Nullable<Boolean> success { get; set; }
2727
public String response { get; set; }
28-
public TimeSpan duration { get; set; }
28+
public Nullable<TimeSpan> duration { get; set; }
2929
public Score score { get; set; }
3030
public Extensions extensions { get; set; }
3131

@@ -78,7 +78,7 @@ public override JObject ToJObject(TCAPIVersion version) {
7878
}
7979
if (duration != null)
8080
{
81-
result.Add("duration", XmlConvert.ToString(duration));
81+
result.Add("duration", XmlConvert.ToString((TimeSpan)duration));
8282
}
8383
if (score != null)
8484
{

TinCan/TCAPIVersion.cs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,33 @@ public sealed class TCAPIVersion
2323
//public static readonly TCAPIVersion V102 = new TCAPIVersion("1.0.2");
2424
public static readonly TCAPIVersion V101 = new TCAPIVersion("1.0.1");
2525
public static readonly TCAPIVersion V100 = new TCAPIVersion("1.0.0");
26+
public static readonly TCAPIVersion V095 = new TCAPIVersion("0.95");
27+
public static readonly TCAPIVersion V090 = new TCAPIVersion("0.9");
2628

2729
public static TCAPIVersion latest()
2830
{
2931
return V101;
3032
}
3133

34+
private static Dictionary<String, TCAPIVersion> known;
3235
private static Dictionary<String, TCAPIVersion> supported;
3336

37+
public static Dictionary<String, TCAPIVersion> GetKnown()
38+
{
39+
if (known != null) {
40+
return known;
41+
}
42+
43+
known = new Dictionary<String, TCAPIVersion>();
44+
//known.Add("1.0.2", V102);
45+
known.Add("1.0.1", V101);
46+
known.Add("1.0.0", V100);
47+
known.Add("0.95", V095);
48+
known.Add("0.9", V090);
49+
50+
return known;
51+
}
52+
3453
public static Dictionary<String, TCAPIVersion> GetSupported()
3554
{
3655
if (supported != null) {
@@ -47,10 +66,10 @@ public static Dictionary<String, TCAPIVersion> GetSupported()
4766

4867
public static explicit operator TCAPIVersion(String vStr)
4968
{
50-
var s = GetSupported();
69+
var s = GetKnown();
5170
if (!s.ContainsKey(vStr))
5271
{
53-
throw new ArgumentException("Unsupported version: " + vStr);
72+
throw new ArgumentException("Unrecognized version: " + vStr);
5473
}
5574

5675
return s[vStr];

TinCanTests/RemoteLRSResourceTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public void Init()
4141
// results of the test suite then supply your own endpoint, username, and password
4242
//
4343
lrs = new RemoteLRS(
44-
"https://cloud.scorm.com/tc/SYPGYC448W/sandbox/",
45-
"-DOzXB-DAFR1O3RAazI",
46-
"pL-Kyru9fUCFE8981N4"
44+
"https://cloud.scorm.com/tc/U2S4SI5FY0/sandbox/",
45+
"Nja986GYE1_XrWMmFUE",
46+
"Bd9lDr1kjaWWY6RID_4"
4747
);
4848
}
4949

TinCanTests/ResultTest.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2015 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 System;
19+
using NUnit.Framework;
20+
using Newtonsoft.Json.Linq;
21+
using TinCan;
22+
using TinCan.Json;
23+
24+
[TestFixture]
25+
class ResultTest
26+
{
27+
[Test]
28+
public void TestEmptyCtr()
29+
{
30+
var obj = new Result();
31+
Assert.IsInstanceOf<Result>(obj);
32+
Assert.IsNull(obj.completion);
33+
Assert.IsNull(obj.success);
34+
Assert.IsNull(obj.response);
35+
Assert.IsNull(obj.duration);
36+
Assert.IsNull(obj.score);
37+
Assert.IsNull(obj.extensions);
38+
39+
StringAssert.AreEqualIgnoringCase("{}", obj.ToJSON());
40+
}
41+
42+
[Test]
43+
public void TestJObjectCtr()
44+
{
45+
var cfg = new JObject();
46+
cfg.Add("completion", true);
47+
cfg.Add("success", true);
48+
cfg.Add("response", "Yes");
49+
50+
var obj = new Result(cfg);
51+
Assert.IsInstanceOf<Result>(obj);
52+
Assert.That(obj.completion, Is.EqualTo(true));
53+
Assert.That(obj.success, Is.EqualTo(true));
54+
Assert.That(obj.response, Is.EqualTo("Yes"));
55+
}
56+
57+
[Test]
58+
public void TestStringOfJSONCtr()
59+
{
60+
var json = "{\"success\": true, \"completion\": true, \"response\": \"Yes\"}";
61+
var strOfJson = new StringOfJSON(json);
62+
63+
var obj = new Result(strOfJson);
64+
Assert.IsInstanceOf<Result>(obj);
65+
Assert.That(obj.success, Is.EqualTo(true));
66+
Assert.That(obj.completion, Is.EqualTo(true));
67+
Assert.That(obj.response, Is.EqualTo("Yes"));
68+
}
69+
}
70+
}

TinCanTests/TinCanTests.csproj

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

0 commit comments

Comments
 (0)