/// <summary>
 ///A test for SaveActivityState
 ///</summary>
 //[TestMethod()]
 public void SaveActivityStateTest()
 {
     TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password"));
     ActivityState activityState = new ActivityState();
     activityState.ActivityId = "example.com";
     activityState.Actor = new Actor("Example", "mailto:[email protected]");
     activityState.Body = "This is a test input.";
     activityState.StateId = "Bananas";
     bool overwrite = false;
     ActivityState previousState = null;
     target.SaveActivityState(activityState, overwrite, previousState);
     Assert.Inconclusive(INCONCLUSIVE);
 }
 /// <summary>
 /// Saves the activity state
 /// </summary>
 /// <param name="activityState">The activity state to save</param>
 /// <param name="overwrite">Optional parameter to force overwrite</param>
 /// <param name="previousState">Optional parameter for the last known state of the activity</param>
 public void SaveActivityState(ActivityState activityState, bool overwrite, ActivityState previousState)
 {
     TinCanJsonConverter converter = new TinCanJsonConverter();
     NameValueCollection nvc = new NameValueCollection();
     string putData;
     string previousSha1 = string.Empty;
     putData = activityState.Body;
     nvc["overwrite"] = overwrite.ToString();
     nvc["activityId"] = activityState.ActivityId;
     nvc["stateId"] = activityState.StateId;
     switch (version)
     {
         case TCAPIVersion.TinCan090:
             nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)activityState.Actor);
             break;
         default:
             nvc["actor"] = converter.SerializeToJSON(activityState.Actor);
             break;
     }
     if (activityState.RegistrationId != null)
         nvc["registrationId"] = activityState.RegistrationId;
     if (previousState != null)
         previousSha1 = BitConverter.ToString(Encryption.GetSha1Hash(Encoding.UTF8.GetBytes(previousState.Body))).Replace("-", "");
     string contentType = activityState.ContentType;
     HttpMethods.PutRequest(putData, nvc, endpoint + ACTIVITY_STATE, authentification, contentType, previousSha1, versionString);
 }
        /// <summary>
        /// Test to ensure ETag collisions are not ignored.
        /// </summary>
        //[TestMethod()]
        public void CollisionTest()
        {
            TinCanJsonConverter converter = new TinCanJsonConverter();
            TCAPI target = new TCAPI("https://cloud.scorm.com/ScormEngineInterface/TCAPI/CZSWMUZPSE", 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>
 /// Saves the activity state
 /// </summary>
 /// <param name="activityState">The activity state to save</param>
 /// <param name="previousState">Optional parameter for the last known state of the activity</param>
 public void SaveActivityState(ActivityState activityState, ActivityState previousState)
 {
     SaveActivityState(activityState, true, previousState);
 }
 /// <summary>
 /// Saves the activity state
 /// </summary>
 /// <param name="activityState">The activity state to save</param>
 /// <param name="overwrite">Optional parameter to force overwrite</param>
 public void SaveActivityState(ActivityState activityState, bool overwrite)
 {
     SaveActivityState(activityState, overwrite, null);
 }
 /// <summary>
 /// Saves the activity state
 /// </summary>
 /// <param name="activityState">The activity state to save</param>
 public void SaveActivityState(ActivityState activityState)
 {
     SaveActivityState(activityState, true, null);
 }
 /// <summary>
 /// Retrieves a specific activity state
 /// </summary>
 /// <param name="activityId">The activity ID</param>
 /// <param name="actor">The actor associated with the state</param>
 /// <param name="stateId">The state document id</param>
 /// <param name="registrationId">Optional registration ID</param>
 /// <returns>The activity state</returns>
 public ActivityState GetActivityState(string activityId, Actor actor, string stateId, string registrationId)
 {
     TinCanJsonConverter converter = new TinCanJsonConverter();
     NameValueCollection nvc = new NameValueCollection();
     string getResult;
     ActivityState result = new ActivityState();
     nvc["activityId"] = activityId;
     switch (version)
     {
         case TCAPIVersion.TinCan090:
             nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor);
             break;
         default:
             nvc["actor"] = converter.SerializeToJSON(actor);
             break;
     }
     nvc["stateId"] = stateId;
     if (!string.IsNullOrEmpty(registrationId))
         nvc["registrationId"] = registrationId;
     WebHeaderCollection whc;
     getResult = HttpMethods.GetRequest(nvc, endpoint + ACTIVITY_STATE, authentification, out whc, versionString);
     if (whc != null)
         result.ContentType = whc["Content-Type"];
     result.Body = getResult;
     result.ActivityId = activityId;
     result.Actor = actor;
     result.RegistrationId = registrationId;
     result.StateId = stateId;
     return result;
 }
        public void ActivityStateTest()
        {
            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);

            //Assert.AreEqual(0, results.Length);

            ActivityState state = new ActivityState();
            state.ActivityId = activityId;
            state.Actor = actor;
            state.StateId = stateIds[0];
            state.Body = stateContents[0];

            ActivityState previous = new ActivityState();
            previous.ActivityId = activityId;
            previous.Actor = actor;
            previous.StateId = stateIds[0];
            previous.Body = stateContents[0];

            target.SaveActivityState(state, false, previous);

            //target.SaveActivityState(state);

            state.StateId = stateIds[1];
            state.Body = stateContents[1];
            target.SaveActivityState(state);

            state.StateId = stateIds[2];
            state.Body = stateContents[2];
            target.SaveActivityState(state);

            results = target.GetActivityStateIds(activityId, actor);

            Assert.AreEqual(3, results.Length);

            ActivityState asResult = target.GetActivityState(activityId, actor, stateIds[0]);
            Assert.AreEqual(stateContents[0], asResult.Body);
            asResult = target.GetActivityState(activityId, actor, stateIds[0]);

            asResult = target.GetActivityState(activityId, actor, stateIds[1]);
            Assert.AreEqual(stateContents[1], asResult.Body);

            asResult = target.GetActivityState(activityId, actor, stateIds[2]);
            Assert.AreEqual(stateContents[2], asResult.Body);

            /*
            target.DeleteActivityState(activityId, actor, stateIds[0]);
            results = target.GetActivityStateIds(activityId, actor);

            Assert.AreEqual(2, results.Length);
            target.DeleteActivityState(activityId, actor, stateIds[1]);
            target.DeleteActivityState(activityId, actor, stateIds[2]);
            */
            results = target.GetActivityStateIds(activityId, actor);
        }