From 5d1b8d87fafe4d33a3e12813a2283adadda5681d Mon Sep 17 00:00:00 2001 From: limey98 Date: Wed, 23 Dec 2015 00:10:44 +0000 Subject: [PATCH] Added async versions of all the network functions in RemoteLRS --- .gitattributes | 1 + TinCan/RemoteLRS.cs | 547 ++++++++++++++++++++++++++- TinCan/TinCan.csproj | 11 +- TinCan/packages.config | 2 +- TinCanTests/RemoteLRSResourceTest.cs | 321 ++++++++++++++++ TinCanTests/TinCanTests.csproj | 14 +- TinCanTests/packages.config | 2 +- 7 files changed, 883 insertions(+), 15 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..07764a7 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/TinCan/RemoteLRS.cs b/TinCan/RemoteLRS.cs index af04955..24ff5cc 100644 --- a/TinCan/RemoteLRS.cs +++ b/TinCan/RemoteLRS.cs @@ -18,6 +18,7 @@ limitations under the License. using System.IO; using System.Net; using System.Text; +using System.Threading.Tasks; using System.Web; using Newtonsoft.Json.Linq; using TinCan.Documents; @@ -81,7 +82,7 @@ public MyHTTPResponse(HttpWebResponse webResp) } } - private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req) + private HttpWebRequest PreprocessRequest(MyHTTPRequest req) { String url; if (req.resource.StartsWith("http", StringComparison.InvariantCultureIgnoreCase)) @@ -91,7 +92,8 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req) else { url = endpoint.ToString(); - if (! url.EndsWith("/") && ! req.resource.StartsWith("/")) { + if (!url.EndsWith("/") && !req.resource.StartsWith("/")) + { url += "/"; } url += req.resource; @@ -149,6 +151,12 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req) } } + return webReq; + } + + private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req) + { + HttpWebRequest webReq = PreprocessRequest(req); MyHTTPResponse resp; try @@ -178,6 +186,38 @@ private MyHTTPResponse MakeSyncRequest(MyHTTPRequest req) return resp; } + private async Task MakeAsyncRequest(MyHTTPRequest req) + { + HttpWebRequest webReq = PreprocessRequest(req); + MyHTTPResponse resp; + + try + { + using (var webResp = await webReq.GetResponseAsync()) + { + resp = new MyHTTPResponse((HttpWebResponse)webResp); + } + } + catch (WebException ex) + { + if (ex.Response != null) + { + using (var webResp = (HttpWebResponse)ex.Response) + { + resp = new MyHTTPResponse(webResp); + } + } + else + { + resp = new MyHTTPResponse(); + resp.content = Encoding.UTF8.GetBytes("Web exception without '.Response'"); + } + resp.ex = ex; + } + + return resp; + } + /// /// See http://www.yoda.arachsys.com/csharp/readbinary.html no license found /// @@ -249,7 +289,6 @@ private MyHTTPResponse GetDocument(String resource, Dictionary q return res; } - private ProfileKeysLRSResponse GetProfileKeys(String resource, Dictionary queryParams) { var r = new ProfileKeysLRSResponse(); @@ -280,7 +319,6 @@ private ProfileKeysLRSResponse GetProfileKeys(String resource, Dictionary queryParams, Document document) { var r = new LRSResponse(); @@ -305,7 +343,6 @@ private LRSResponse SaveDocument(String resource, Dictionary que return r; } - private LRSResponse DeleteDocument(String resource, Dictionary queryParams) { var r = new LRSResponse(); @@ -328,7 +365,6 @@ private LRSResponse DeleteDocument(String resource, Dictionary q return r; } - private StatementLRSResponse GetStatement(Dictionary queryParams) { var r = new StatementLRSResponse(); @@ -353,6 +389,127 @@ private StatementLRSResponse GetStatement(Dictionary queryParams return r; } + private async Task GetDocumentAsync(String resource, Dictionary queryParams, Document document) + { + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = resource; + req.queryParams = queryParams; + + var res = await MakeAsyncRequest(req); + if (res.status == HttpStatusCode.OK) + { + document.content = res.content; + document.contentType = res.contentType; + document.timestamp = res.lastModified; + document.etag = res.etag; + } + + return res; + } + private async Task GetProfileKeysAsync(String resource, Dictionary queryParams) + { + var r = new ProfileKeysLRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = resource; + req.queryParams = queryParams; + + var res = await MakeAsyncRequest(req); + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + + var keys = JArray.Parse(Encoding.UTF8.GetString(res.content)); + if (keys.Count > 0) + { + r.content = new List(); + foreach (JToken key in keys) + { + r.content.Add((String)key); + } + } + + return r; + } + private async Task SaveDocumentAsync(String resource, Dictionary queryParams, Document document) + { + var r = new LRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "PUT"; + req.resource = resource; + req.queryParams = queryParams; + req.contentType = document.contentType; + req.content = document.content; + + var res = await MakeAsyncRequest(req); + if (res.status != HttpStatusCode.NoContent) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + + return r; + } + private async Task DeleteDocumentAsync(String resource, Dictionary queryParams) + { + var r = new LRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "DELETE"; + req.resource = resource; + req.queryParams = queryParams; + + var res = await MakeAsyncRequest(req); + if (res.status != HttpStatusCode.NoContent) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + + return r; + } + private async Task GetStatementAsync(Dictionary queryParams) + { + var r = new StatementLRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = "statements"; + req.queryParams = queryParams; + + MyHTTPResponse res = await MakeAsyncRequest(req); + + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + r.content = new Statement(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content))); + + return r; + } + public AboutLRSResponse About() { var r = new AboutLRSResponse(); @@ -375,7 +532,6 @@ public AboutLRSResponse About() return r; } - public StatementLRSResponse SaveStatement(Statement statement) { var r = new StatementLRSResponse(); @@ -540,6 +696,199 @@ public StatementsResultLRSResponse MoreStatements(StatementsResult result) return r; } + + public async Task AboutAsync() + { + var r = new AboutLRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = "about"; + + var res = await MakeAsyncRequest(req); + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + r.content = new About(Encoding.UTF8.GetString(res.content)); + + return r; + } + public async Task SaveStatementAsync(Statement statement) + { + var r = new StatementLRSResponse(); + var req = new MyHTTPRequest(); + req.queryParams = new Dictionary(); + req.resource = "statements"; + + if (statement.id == null) + { + req.method = "POST"; + } + else + { + req.method = "PUT"; + req.queryParams.Add("statementId", statement.id.ToString()); + } + + req.contentType = "application/json"; + req.content = Encoding.UTF8.GetBytes(statement.ToJSON(version)); + + MyHTTPResponse res = await MakeAsyncRequest(req); + + if (statement.id == null) + { + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + var ids = JArray.Parse(Encoding.UTF8.GetString(res.content)); + statement.id = new Guid((String)ids[0]); + } + else + { + if (res.status != HttpStatusCode.NoContent) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + } + + r.success = true; + r.content = statement; + + return r; + } + public async Task VoidStatementAsync(Guid id, Agent agent) + { + var voidStatement = new Statement + { + actor = agent, + verb = new Verb + { + id = new Uri("http://adlnet.gov/expapi/verbs/voided"), + display = new LanguageMap() + }, + target = new StatementRef { id = id } + }; + voidStatement.verb.display.Add("en-US", "voided"); + + return await SaveStatementAsync(voidStatement); + } + public async Task SaveStatementsAsync(List statements) + { + var r = new StatementsResultLRSResponse(); + + var req = new MyHTTPRequest(); + req.resource = "statements"; + req.method = "POST"; + req.contentType = "application/json"; + + var jarray = new JArray(); + foreach (Statement st in statements) + { + jarray.Add(st.ToJObject(version)); + } + req.content = Encoding.UTF8.GetBytes(jarray.ToString()); + + MyHTTPResponse res = await MakeAsyncRequest(req); + + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + var ids = JArray.Parse(Encoding.UTF8.GetString(res.content)); + for (int i = 0; i < ids.Count; i++) + { + statements[i].id = new Guid((String)ids[i]); + } + + r.success = true; + r.content = new StatementsResult(statements); + + return r; + } + public async Task RetrieveStatementAsync(Guid id) + { + var queryParams = new Dictionary(); + queryParams.Add("statementId", id.ToString()); + + return await GetStatementAsync(queryParams); + } + public async Task RetrieveVoidedStatementAsync(Guid id) + { + var queryParams = new Dictionary(); + queryParams.Add("voidedStatementId", id.ToString()); + + return await GetStatementAsync(queryParams); + } + public async Task QueryStatementsAsync(StatementsQuery query) + { + var r = new StatementsResultLRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = "statements"; + req.queryParams = query.ToParameterMap(version); + + MyHTTPResponse res = await MakeAsyncRequest(req); + + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content))); + + return r; + } + public async Task MoreStatementsAsync(StatementsResult result) + { + var r = new StatementsResultLRSResponse(); + + var req = new MyHTTPRequest(); + req.method = "GET"; + req.resource = endpoint.GetLeftPart(UriPartial.Authority); + if (!req.resource.EndsWith("/")) + { + req.resource += "/"; + } + req.resource += result.more; + + MyHTTPResponse res = await MakeAsyncRequest(req); + + if (res.status != HttpStatusCode.OK) + { + r.success = false; + r.httpException = res.ex; + r.SetErrMsgFromBytes(res.content); + return r; + } + + r.success = true; + r.content = new StatementsResult(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content))); + + return r; + } // TODO: since param public ProfileKeysLRSResponse RetrieveStateIds(Activity activity, Agent agent, Nullable registration = null) @@ -626,6 +975,90 @@ public LRSResponse ClearState(Activity activity, Agent agent, Nullable reg return DeleteDocument("activities/state", queryParams); } + public async Task RetrieveStateIdsAsync(Activity activity, Agent agent, Nullable registration = null) + { + var queryParams = new Dictionary(); + queryParams.Add("activityId", activity.id.ToString()); + queryParams.Add("agent", agent.ToJSON(version)); + if (registration != null) + { + queryParams.Add("registration", registration.ToString()); + } + + return await GetProfileKeysAsync("activities/state", queryParams); + } + public async Task RetrieveStateAsync(String id, Activity activity, Agent agent, Nullable registration = null) + { + var r = new StateLRSResponse(); + + var queryParams = new Dictionary(); + queryParams.Add("stateId", id); + queryParams.Add("activityId", activity.id.ToString()); + queryParams.Add("agent", agent.ToJSON(version)); + + var state = new StateDocument(); + state.id = id; + state.activity = activity; + state.agent = agent; + + if (registration != null) + { + queryParams.Add("registration", registration.ToString()); + state.registration = registration; + } + + var resp = await GetDocumentAsync("activities/state", queryParams, state); + if (resp.status != HttpStatusCode.OK && resp.status != HttpStatusCode.NotFound) + { + r.success = false; + r.httpException = resp.ex; + r.SetErrMsgFromBytes(resp.content); + return r; + } + r.success = true; + r.content = state; + + return r; + } + public async Task SaveStateAsync(StateDocument state) + { + var queryParams = new Dictionary(); + queryParams.Add("stateId", state.id); + queryParams.Add("activityId", state.activity.id.ToString()); + queryParams.Add("agent", state.agent.ToJSON(version)); + if (state.registration != null) + { + queryParams.Add("registration", state.registration.ToString()); + } + + return await SaveDocumentAsync("activities/state", queryParams, state); + } + public async Task DeleteStateAsync(StateDocument state) + { + var queryParams = new Dictionary(); + queryParams.Add("stateId", state.id); + queryParams.Add("activityId", state.activity.id.ToString()); + queryParams.Add("agent", state.agent.ToJSON(version)); + if (state.registration != null) + { + queryParams.Add("registration", state.registration.ToString()); + } + + return await DeleteDocumentAsync("activities/state", queryParams); + } + public async Task ClearStateAsync(Activity activity, Agent agent, Nullable registration = null) + { + var queryParams = new Dictionary(); + queryParams.Add("activityId", activity.id.ToString()); + queryParams.Add("agent", agent.ToJSON(version)); + if (registration != null) + { + queryParams.Add("registration", registration.ToString()); + } + + return await DeleteDocumentAsync("activities/state", queryParams); + } + // TODO: since param public ProfileKeysLRSResponse RetrieveActivityProfileIds(Activity activity) { @@ -677,6 +1110,56 @@ public LRSResponse DeleteActivityProfile(ActivityProfileDocument profile) return DeleteDocument("activities/profile", queryParams); } + public async Task RetrieveActivityProfileIdsAsync(Activity activity) + { + var queryParams = new Dictionary(); + queryParams.Add("activityId", activity.id.ToString()); + + return await GetProfileKeysAsync("activities/profile", queryParams); + } + public async Task RetrieveActivityProfileAsync(String id, Activity activity) + { + var r = new ActivityProfileLRSResponse(); + + var queryParams = new Dictionary(); + queryParams.Add("profileId", id); + queryParams.Add("activityId", activity.id.ToString()); + + var profile = new ActivityProfileDocument(); + profile.id = id; + profile.activity = activity; + + var resp = await GetDocumentAsync("activities/profile", queryParams, profile); + if (resp.status != HttpStatusCode.OK && resp.status != HttpStatusCode.NotFound) + { + r.success = false; + r.httpException = resp.ex; + r.SetErrMsgFromBytes(resp.content); + return r; + } + r.success = true; + r.content = profile; + + return r; + } + public async Task SaveActivityProfileAsync(ActivityProfileDocument profile) + { + var queryParams = new Dictionary(); + queryParams.Add("profileId", profile.id); + queryParams.Add("activityId", profile.activity.id.ToString()); + + return await SaveDocumentAsync("activities/profile", queryParams, profile); + } + public async Task DeleteActivityProfileAsync(ActivityProfileDocument profile) + { + var queryParams = new Dictionary(); + queryParams.Add("profileId", profile.id); + queryParams.Add("activityId", profile.activity.id.ToString()); + // TODO: need to pass Etag? + + return await DeleteDocumentAsync("activities/profile", queryParams); + } + // TODO: since param public ProfileKeysLRSResponse RetrieveAgentProfileIds(Agent agent) { @@ -727,5 +1210,55 @@ public LRSResponse DeleteAgentProfile(AgentProfileDocument profile) return DeleteDocument("agents/profile", queryParams); } + + public async Task RetrieveAgentProfileIdsAsync(Agent agent) + { + var queryParams = new Dictionary(); + queryParams.Add("agent", agent.ToJSON(version)); + + return await GetProfileKeysAsync("agents/profile", queryParams); + } + public async Task RetrieveAgentProfileAsync(String id, Agent agent) + { + var r = new AgentProfileLRSResponse(); + + var queryParams = new Dictionary(); + queryParams.Add("profileId", id); + queryParams.Add("agent", agent.ToJSON(version)); + + var profile = new AgentProfileDocument(); + profile.id = id; + profile.agent = agent; + + var resp = await GetDocumentAsync("agents/profile", queryParams, profile); + if (resp.status != HttpStatusCode.OK && resp.status != HttpStatusCode.NotFound) + { + r.success = false; + r.httpException = resp.ex; + r.SetErrMsgFromBytes(resp.content); + return r; + } + r.success = true; + r.content = profile; + + return r; + } + public async Task SaveAgentProfileAsync(AgentProfileDocument profile) + { + var queryParams = new Dictionary(); + queryParams.Add("profileId", profile.id); + queryParams.Add("agent", profile.agent.ToJSON(version)); + + return await SaveDocumentAsync("agents/profile", queryParams, profile); + } + public async Task DeleteAgentProfileAsync(AgentProfileDocument profile) + { + var queryParams = new Dictionary(); + queryParams.Add("profileId", profile.id); + queryParams.Add("agent", profile.agent.ToJSON(version)); + // TODO: need to pass Etag? + + return await DeleteDocumentAsync("agents/profile", queryParams); + } } } diff --git a/TinCan/TinCan.csproj b/TinCan/TinCan.csproj index 1fe1a35..1b7abce 100644 --- a/TinCan/TinCan.csproj +++ b/TinCan/TinCan.csproj @@ -9,8 +9,9 @@ Properties TinCan TinCan - v3.5 + v4.5 512 + true @@ -21,6 +22,7 @@ prompt 4 bin\Debug\TinCan.XML + false pdbonly @@ -29,6 +31,7 @@ TRACE prompt 4 + false true @@ -39,10 +42,12 @@ AnyCPU prompt MinimumRecommendedRules.ruleset + false - - ..\packages\Newtonsoft.Json.6.0.2\lib\net35\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True diff --git a/TinCan/packages.config b/TinCan/packages.config index 62fcc5b..505e588 100644 --- a/TinCan/packages.config +++ b/TinCan/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/TinCanTests/RemoteLRSResourceTest.cs b/TinCanTests/RemoteLRSResourceTest.cs index d6e0f58..bd9a43b 100644 --- a/TinCanTests/RemoteLRSResourceTest.cs +++ b/TinCanTests/RemoteLRSResourceTest.cs @@ -24,6 +24,7 @@ namespace TinCanTests using TinCan.Documents; using TinCan.Json; using TinCan.LRSResponses; + using System.Threading.Tasks; [TestFixture] class RemoteLRSResourceTest @@ -339,5 +340,325 @@ public void TestDeleteAgentProfile() LRSResponse lrsRes = lrs.DeleteAgentProfile(doc); Assert.IsTrue(lrsRes.success); } + + + + [Test] + public void TestAboutAsync() + { + Task lrsRes = lrs.AboutAsync(); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestAboutAsyncFailure() + { + lrs.endpoint = new Uri("http://cloud.scorm.com/tc/3TQLAI9/sandbox/"); + + Task lrsRes = lrs.AboutAsync(); + lrsRes.Wait(); + Assert.IsFalse(lrsRes.Result.success); + Console.WriteLine("TestAboutFailure - errMsg: " + lrsRes.Result.errMsg); + } + + [Test] + public void TestSaveStatementAsync() + { + var statement = new Statement(); + statement.actor = Support.agent; + statement.verb = Support.verb; + statement.target = Support.activity; + + Task lrsRes = lrs.SaveStatementAsync(statement); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.AreEqual(statement, lrsRes.Result.content); + Assert.IsNotNull(lrsRes.Result.content.id); + } + + [Test] + public void TestSaveStatementWithIDAsync() + { + var statement = new Statement(); + statement.Stamp(); + statement.actor = Support.agent; + statement.verb = Support.verb; + statement.target = Support.activity; + + Task lrsRes = lrs.SaveStatementAsync(statement); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.AreEqual(statement, lrsRes.Result.content); + } + + [Test] + public void TestSaveStatementStatementRefAsync() + { + var statement = new Statement(); + statement.Stamp(); + statement.actor = Support.agent; + statement.verb = Support.verb; + statement.target = Support.statementRef; + + Task lrsRes = lrs.SaveStatementAsync(statement); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.AreEqual(statement, lrsRes.Result.content); + } + + [Test] + public void TestSaveStatementSubStatementAsync() + { + var statement = new Statement(); + statement.Stamp(); + statement.actor = Support.agent; + statement.verb = Support.verb; + statement.target = Support.subStatement; + + Console.WriteLine(statement.ToJSON(true)); + + Task lrsRes = lrs.SaveStatementAsync(statement); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.AreEqual(statement, lrsRes.Result.content); + } + + [Test] + public void TestVoidStatementAsync() + { + Guid toVoid = Guid.NewGuid(); + Task lrsRes = lrs.VoidStatementAsync(toVoid, Support.agent); + lrsRes.Wait(); + + Assert.IsTrue(lrsRes.Result.success, "LRS response successful"); + Assert.AreEqual(new Uri("http://adlnet.gov/expapi/verbs/voided"), lrsRes.Result.content.verb.id, "voiding statement uses voided verb"); + Assert.AreEqual(toVoid, ((StatementRef)lrsRes.Result.content.target).id, "voiding statement target correct id"); + } + + [Test] + public void TestSaveStatementsAsync() + { + var statement1 = new Statement(); + statement1.actor = Support.agent; + statement1.verb = Support.verb; + statement1.target = Support.parent; + + var statement2 = new Statement(); + statement2.actor = Support.agent; + statement2.verb = Support.verb; + statement2.target = Support.activity; + statement2.context = Support.context; + + var statements = new List(); + statements.Add(statement1); + statements.Add(statement2); + + Task lrsRes = lrs.SaveStatementsAsync(statements); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + // TODO: check statements match and ids not null + } + + [Test] + public void TestRetrieveStatementAsync() + { + var statement = new TinCan.Statement(); + statement.Stamp(); + statement.actor = Support.agent; + statement.verb = Support.verb; + statement.target = Support.activity; + statement.context = Support.context; + statement.result = Support.result; + + Task saveRes = lrs.SaveStatementAsync(statement); + saveRes.Wait(); + if (saveRes.Result.success) + { + Task retRes = lrs.RetrieveStatementAsync(saveRes.Result.content.id.Value); + Assert.IsTrue(retRes.Result.success); + Console.WriteLine("TestRetrieveStatement - statement: " + retRes.Result.content.ToJSON(true)); + } + else + { + // TODO: skipped? + } + } + + [Test] + public void TestQueryStatementsAsync() + { + var query = new TinCan.StatementsQuery(); + query.agent = Support.agent; + query.verbId = Support.verb.id; + query.activityId = Support.parent.id; + query.relatedActivities = true; + query.relatedAgents = true; + query.format = StatementsQueryResultFormat.IDS; + query.limit = 10; + + Task lrsRes = lrs.QueryStatementsAsync(query); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Console.WriteLine("TestQueryStatements - statement count: " + lrsRes.Result.content.statements.Count); + } + + [Test] + public void TestMoreStatementsAsync() + { + var query = new TinCan.StatementsQuery(); + query.format = StatementsQueryResultFormat.IDS; + query.limit = 2; + + Task queryRes = lrs.QueryStatementsAsync(query); + queryRes.Wait(); + if (queryRes.Result.success && queryRes.Result.content.more != null) + { + Task moreRes = lrs.MoreStatementsAsync(queryRes.Result.content); + moreRes.Wait(); + Assert.IsTrue(moreRes.Result.success); + Console.WriteLine("TestMoreStatements - statement count: " + moreRes.Result.content.statements.Count); + } + else + { + // TODO: skipped? + } + } + + [Test] + public void TestRetrieveStateIdsAsync() + { + Task lrsRes = lrs.RetrieveStateIdsAsync(Support.activity, Support.agent); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestRetrieveStateAsync() + { + Task lrsRes = lrs.RetrieveStateAsync("test", Support.activity, Support.agent); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.IsInstanceOf(lrsRes.Result.content); + } + + [Test] + public void TestSaveStateAsync() + { + var doc = new StateDocument(); + doc.activity = Support.activity; + doc.agent = Support.agent; + doc.id = "test"; + doc.content = System.Text.Encoding.UTF8.GetBytes("Test value"); + + Task lrsRes = lrs.SaveStateAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestDeleteStateAsync() + { + var doc = new StateDocument(); + doc.activity = Support.activity; + doc.agent = Support.agent; + doc.id = "test"; + + Task lrsRes = lrs.DeleteStateAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestClearStateAsync() + { + Task lrsRes = lrs.ClearStateAsync(Support.activity, Support.agent); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestRetrieveActivityProfileIdsAsync() + { + Task lrsRes = lrs.RetrieveActivityProfileIdsAsync(Support.activity); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestRetrieveActivityProfileAsync() + { + Task lrsRes = lrs.RetrieveActivityProfileAsync("test", Support.activity); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.IsInstanceOf(lrsRes.Result.content); + } + + [Test] + public void TestSaveActivityProfileAsync() + { + var doc = new ActivityProfileDocument(); + doc.activity = Support.activity; + doc.id = "test"; + doc.content = System.Text.Encoding.UTF8.GetBytes("Test value"); + + Task lrsRes = lrs.SaveActivityProfileAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestDeleteActivityProfileAsync() + { + var doc = new ActivityProfileDocument(); + doc.activity = Support.activity; + doc.id = "test"; + + Task lrsRes = lrs.DeleteActivityProfileAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestRetrieveAgentProfileIdsAsync() + { + Task lrsRes = lrs.RetrieveAgentProfileIdsAsync(Support.agent); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestRetrieveAgentProfileAsync() + { + Task lrsRes = lrs.RetrieveAgentProfileAsync("test", Support.agent); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + Assert.IsInstanceOf(lrsRes.Result.content); + } + + [Test] + public void TestSaveAgentProfileAsync() + { + var doc = new AgentProfileDocument(); + doc.agent = Support.agent; + doc.id = "test"; + doc.content = System.Text.Encoding.UTF8.GetBytes("Test value"); + + Task lrsRes = lrs.SaveAgentProfileAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } + + [Test] + public void TestDeleteAgentProfileAsync() + { + var doc = new AgentProfileDocument(); + doc.agent = Support.agent; + doc.id = "test"; + + Task lrsRes = lrs.DeleteAgentProfileAsync(doc); + lrsRes.Wait(); + Assert.IsTrue(lrsRes.Result.success); + } } } \ No newline at end of file diff --git a/TinCanTests/TinCanTests.csproj b/TinCanTests/TinCanTests.csproj index e9b5141..3f650b1 100644 --- a/TinCanTests/TinCanTests.csproj +++ b/TinCanTests/TinCanTests.csproj @@ -9,8 +9,9 @@ Properties TinCanTests TinCanTests - v3.5 + v4.5 512 + AnyCPU @@ -21,6 +22,7 @@ DEBUG;TRACE prompt 4 + false AnyCPU @@ -30,6 +32,7 @@ TRACE prompt 4 + false @@ -42,10 +45,12 @@ AnyCPU prompt MinimumRecommendedRules.ruleset + false - - ..\packages\Newtonsoft.Json.6.0.2\lib\net35\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll + True ..\packages\NUnitTestAdapter.2.0.0\lib\nunit.core.dll @@ -93,6 +98,9 @@ + + +