Beispiel #1
0
        public void CollisionTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("CZSWMUZPSE", "vwiuflgsY22FDXpHA4lwwe5hrnUXvcyJjW3fDrpH"));
            Actor actor  = new Actor("Mufasa", "mailto:[email protected]");

            string[] stateIds      = { "The Lion King", "The Fallen King", "The New King" };
            string[] stateContents =
            {
                "Mufasa rules his country as a proud and fair king of lions, celebrating his recently newborn son Simba.",
                "Scar kills Mufasa, simply muttering the words 'Long Live the King'",
                "Simba finally realizes he must follow in his fathers footsteps to save the kingdom from the evil Scar."
            };

            string activityId = "example.com/TheLionKing";

            string[] results = target.GetActivityStateIds(activityId, actor);

            ActivityState state    = new ActivityState(activityId, stateIds[0], actor, stateContents[1], "text/plain");
            ActivityState previous = new ActivityState(activityId, stateIds[0], actor, stateContents[0], "text/plain");

            target.SaveActivityState(state);
            state.Body = stateContents[2];
            target.SaveActivityState(state, false, previous);
        }
        /// <summary>
        /// Transforms the Query object into a NameValueCollection, which will be transformed into a query string.
        /// </summary>
        /// <param name="version">The TCAPI Version to serialize the statement as.</param>
        /// <returns></returns>
        public NameValueCollection ToNameValueCollection(TCAPIVersion version)
        {
            NameValueCollection nvc       = new NameValueCollection();
            TinCanJsonConverter converter = new TinCanJsonConverter();

            if (!string.IsNullOrEmpty(verb))
            {
                nvc["verb"] = verb.ToLower();
            }
            if (targetObject != null)
            {
                nvc["object"] = converter.SerializeToJSON(targetObject);
            }
            if (!string.IsNullOrEmpty(registration))
            {
                nvc["registration"] = registration;
            }
            nvc["context"] = context.ToString();
            if (actor != null)
            {
                switch (version)
                {
                case TCAPIVersion.TinCan090:
                    nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor);
                    break;

                default:
                    nvc["actor"] = converter.SerializeToJSON(actor);
                    break;
                }
            }
            if (since != null)
            {
                nvc["since"] = since.Value.ToString();
            }
            if (until != null)
            {
                nvc["until"] = until.Value.ToString();
            }
            nvc["limit"]         = limit.ToString();
            nvc["authoritative"] = authoritative.ToString();
            nvc["sparse"]        = sparse.ToString();
            if (instructor != null)
            {
                nvc["instructor"] = converter.SerializeToJSON(instructor);
            }
            nvc["ascending"] = ascending.ToString();
            if (!string.IsNullOrEmpty(continueToken))
            {
                nvc["continueToken"] = continueToken;
            }
            nvc["historical"] = historical.ToString();


            return(nvc);
        }
Beispiel #3
0
        public void GetStatementTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI     target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            Statement actual;

            actual = target.GetStatement("c17c9b10-95d4-4579-90d2-d2d4683fb88b");
            Console.Write(converter.SerializeToJSON(actual));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #4
0
        public void GetActivityTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI    target     = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            string   activityId = "example.com"; // TODO: Initialize to an appropriate value
            Activity actual;

            actual = target.GetActivity(activityId);
            Console.Write(converter.SerializeToJSON(actual));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #5
0
        public void GetActivityProfileIdsTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI            target       = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            string           activityId   = "example.com";
            NullableDateTime since        = null;

            string[] actual;
            actual = target.GetActivityProfileIds(activityId, since);
            Console.Write(converter.SerializeToJSON(actual));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #6
0
        public void GetActorTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI target       = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            Actor partialActor = new Actor();

            partialActor.Mbox = "mailto:[email protected]";
            Actor fullActor = target.GetActor(partialActor);

            Console.Write(converter.SerializeToJSON(fullActor));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #7
0
        public void GetActorProfileTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI        target           = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            Actor        actor            = new Actor("Example", "mailto:[email protected]");
            string       profileId        = "Example";
            ActorProfile actual;

            actual = target.GetActorProfile(actor, profileId);
            Console.Write(converter.SerializeToJSON(actual));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #8
0
        public void GetActivityStateTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI         target          = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"));
            Actor         actor           = new Actor("Example", "mailto:[email protected]");
            string        activityId      = "example.com";
            string        registrationId  = null;
            string        stateId         = "Bananas";
            ActivityState actual;

            actual = target.GetActivityState(activityId, actor, stateId, registrationId);
            Console.Write(converter.SerializeToJSON(actual));
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #9
0
        public void GetStatementsTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("test", "password"), TCAPIVersion.TinCan095);
            StatementQueryObject queryObject = new StatementQueryObject();

            queryObject.Actor = new Actor("Example", "mailto:[email protected]");
            queryObject.Since = new DateTime(2013, 6, 1);
            queryObject.Limit = 50;
            int             limit = 0;
            StatementResult actual;

            actual = target.GetStatements(queryObject);
            limit  = actual.Statements.Length;
            Console.Write(converter.SerializeToJSON(actual));
            while (limit <= 50 && !string.IsNullOrEmpty(actual.More))
            {
                actual = target.GetStatements(actual.More);
                Console.Write(converter.SerializeToJSON(actual));
                limit += actual.Statements.Length;
                //break;
            }
            Assert.Inconclusive(INCONCLUSIVE_CONSOLE);
        }
Beispiel #10
0
        public void ActorProfileTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI target = new TCAPI(new Uri("http://cloud.scorm.com/tc/public"), new BasicHTTPAuth("CZSWMUZPSE", "vwiuflgsY22FDXpHA4lwwe5hrnUXvcyJjW3fDrpH"));
            Actor actor  = new Actor("Mufasa", "mailto:[email protected]");

            string[] profileIds      = { "The Lion King", "The Fallen King", "The New King" };
            string[] profileContents =
            {
                "Mufasa rules his country as a proud and fair king of lions, celebrating his recently newborn son Simba.",
                "Scar kills Mufasa, simply muttering the words 'Long Live the King'",
                "Simba finally realizes he must follow in his fathers footsteps to save the kingdom from the evil Scar."
            };

            // Clear all existing profiles.
            target.DeleteAllActorProfile(actor);

            NullableDateTime since = null;

            string[] actual;
            actual = target.GetActorProfileIds(actor, since);

            Assert.AreEqual(0, actual.Length);

            /* Save a new actor profile */
            ActorProfile p1 = new ActorProfile();

            p1.Actor     = actor;
            p1.ProfileId = profileIds[0];
            p1.Body      = profileContents[0];
            ActorProfile pp = new ActorProfile();

            pp.ProfileId = profileIds[0];
            pp.Actor     = actor;
            pp.Body      = profileContents[0];
            target.SaveActorProfile(p1, pp, true);
            actual = target.GetActorProfileIds(actor, since);

            Assert.AreEqual(1, actual.Length);

            p1.ProfileId = profileIds[1];
            p1.Body      = profileContents[1];
            pp.ProfileId = profileIds[1];
            target.SaveActorProfile(p1, pp, true);
            actual = target.GetActorProfileIds(actor, since);

            Assert.AreEqual(2, actual.Length);

            p1.ProfileId = profileIds[2];
            p1.Body      = profileContents[2];
            pp.ProfileId = profileIds[2];
            target.SaveActorProfile(p1, pp, true);
            actual = target.GetActorProfileIds(actor);

            Assert.AreEqual(3, actual.Length);

            // Ensure all the posted data matches

            ActorProfile pResult = target.GetActorProfile(actor, profileIds[0]);

            Assert.AreEqual(profileContents[0], pResult.Body);

            pResult = target.GetActorProfile(actor, profileIds[1]);
            Assert.AreEqual(profileContents[1], pResult.Body);

            pResult = target.GetActorProfile(actor, profileIds[2]);
            Assert.AreEqual(profileContents[2], pResult.Body);

            target.DeleteActorProfile(actor, profileIds[0]);
            actual = target.GetActorProfileIds(actor);

            Assert.AreEqual(2, actual.Length);

            target.DeleteAllActorProfile(actor);
            actual = target.GetActorProfileIds(actor);

            Assert.AreEqual(0, actual.Length);
        }
 public void TearDown()
 {
     converter = null;
 }
 public void SetUp()
 {
     converter = new TinCanJsonConverter();
 }
        /// <summary>
        /// Transforms the Query object into a NameValueCollection, which will be transformed into a query string.
        /// </summary>
        /// <param name="version">The TCAPI Version to serialize the statement as.</param>
        /// <returns></returns>
        public NameValueCollection ToNameValueCollection(TCAPIVersion version)
        {
            NameValueCollection nvc = new NameValueCollection();
            TinCanJsonConverter converter = new TinCanJsonConverter();

            if (!string.IsNullOrEmpty(verb))
                nvc["verb"] = verb.ToLower();
            if (targetObject != null)
                nvc["object"] = converter.SerializeToJSON(targetObject);
            if (!string.IsNullOrEmpty(registration))
                nvc["registration"] = registration;
            nvc["context"] = context.ToString();
            if (actor != null)
                switch( version)
                {
                    case TCAPIVersion.TinCan090:
                        nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor);
                        break;
                    default:
                        nvc["actor"] = converter.SerializeToJSON(actor);
                        break;
                }
            if (since != null)
                nvc["since"] = since.Value.ToString();
            if (until != null)
                nvc["until"] = until.Value.ToString();
            nvc["limit"] = limit.ToString();
            nvc["authoritative"] = authoritative.ToString();
            nvc["sparse"] = sparse.ToString();
            if (instructor != null)
                nvc["instructor"] = converter.SerializeToJSON(instructor);
            nvc["ascending"] = ascending.ToString();
            if (!string.IsNullOrEmpty(continueToken))
                nvc["continueToken"] = continueToken;
            nvc["historical"] = historical.ToString();

            return nvc;
        }