public async Task TestRetrieveStatement()
        {
            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;

            StatementLRSResponse saveRes = await lrs.SaveStatement(statement);

            if (saveRes.success)
            {
                StatementLRSResponse retRes = await lrs.RetrieveStatement(saveRes.content.id.Value);

                Assert.True(retRes.success);
                Console.WriteLine("TestRetrieveStatement - statement: " + retRes.content.ToJSON(true));
            }
            else
            {
                // TODO: skipped?
            }
        }
Beispiel #2
0
        public void TestJObjectCtrSubStatement()
        {
            JObject cfg = new JObject();
            cfg.Add("actor", Support.agent.ToJObject());
            cfg.Add("verb", Support.verb.ToJObject());
            cfg.Add("object", Support.subStatement.ToJObject());

            Statement obj = new Statement(cfg);
            Assert.IsInstanceOf<Statement>(obj);
            Assert.IsInstanceOf<SubStatement>(obj.target);
        }
        public void TestSaveStatementWithID()
        {
            var statement = new Statement();
            statement.Stamp();
            statement.actor = Support.agent;
            statement.verb = Support.verb;
            statement.target = Support.activity;

            StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
            Assert.IsTrue(lrsRes.success);
            Assert.AreEqual(statement, lrsRes.content);
        }
Beispiel #4
0
        public void TestEmptyCtr()
        {
            Statement obj = new Statement();
            Assert.IsInstanceOf<Statement>(obj);
            Assert.IsNull(obj.id);
            Assert.IsNull(obj.actor);
            Assert.IsNull(obj.verb);
            Assert.IsNull(obj.target);
            Assert.IsNull(obj.result);
            Assert.IsNull(obj.context);
            Assert.IsNull(obj.version);
            Assert.IsNull(obj.timestamp);
            Assert.IsNull(obj.stored);

            StringAssert.AreEqualIgnoringCase("{\"version\":\"1.0.1\"}", obj.ToJSON());
        }
Beispiel #5
0
        public StatementLRSResponse VoidStatement(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 SaveStatement(voidStatement);
        }
Beispiel #6
0
        public StatementLRSResponse SaveStatement(Statement statement)
        {
            var r = new StatementLRSResponse();
            var req = new MyHTTPRequest();
            req.queryParams = new Dictionary<String, String>();
            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));

            var res = MakeSyncRequest(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 void TestRetrieveStatement()
        {
            var statement = new TinCan.Statement();
            statement.Stamp();
            statement.actor = agent;
            statement.verb = verb;
            statement.target = activity;
            statement.context = context;
            statement.result = result;

            StatementLRSResponse saveRes = lrs.SaveStatement(statement);
            if (saveRes.success)
            {
                StatementLRSResponse retRes = lrs.RetrieveStatement(saveRes.content.id.Value);
                Assert.IsTrue(retRes.success);
                Console.WriteLine("TestRetrieveStatement - statement: " + retRes.content.ToJSON(true));
            }
            else
            {
                // TODO: skipped?
            }
        }
        public void TestSaveStatements()
        {
            var statement1 = new Statement();
            statement1.actor = agent;
            statement1.verb = verb;
            statement1.target = parent;

            var statement2 = new Statement();
            statement2.actor = agent;
            statement2.verb = verb;
            statement2.target = activity;
            statement2.context = context;

            var statements = new List<Statement>();
            statements.Add(statement1);
            statements.Add(statement2);

            StatementsResultLRSResponse lrsRes = lrs.SaveStatements(statements);
            Assert.IsTrue(lrsRes.success);
            // TODO: check statements match and ids not null
        }
        public void TestSaveStatementSubStatement()
        {
            var statement = new Statement();
            statement.Stamp();
            statement.actor = agent;
            statement.verb = verb;
            statement.target = subStatement;

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

            StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
            Assert.IsTrue(lrsRes.success);
            Assert.AreEqual(statement, lrsRes.content);
        }
        public void TestSaveStatementStatementRef()
        {
            var statement = new Statement();
            statement.Stamp();
            statement.actor = agent;
            statement.verb = verb;
            statement.target = statementRef;

            StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
            Assert.IsTrue(lrsRes.success);
            Assert.AreEqual(statement, lrsRes.content);
        }
        public void TestSaveStatement()
        {
            var statement = new Statement();
            statement.actor = agent;
            statement.verb = verb;
            statement.target = activity;

            StatementLRSResponse lrsRes = lrs.SaveStatement(statement);
            Assert.IsTrue(lrsRes.success);
            Assert.AreEqual(statement, lrsRes.content);
            Assert.IsNotNull(lrsRes.content.id);
        }