/// <summary>
 ///A test for SaveActorProfile
 ///</summary>
 //[TestMethod()]
 public void SaveActorProfileTest()
 {
     TCAPI target = new TCAPI("http://cloud.scorm.com/ScormEngineInterface/TCAPI/public", new BasicHTTPAuth("test", "password"));
     ActorProfile actorProfile = new ActorProfile();
     actorProfile.Actor = new Actor("Example", "mailto:[email protected]");
     actorProfile.ProfileId = "Example";
     actorProfile.Body = "This is some test";
     ActorProfile previousProfile = new ActorProfile();
     previousProfile.Actor = new Actor("Example", "mailto:[email protected]");
     previousProfile.ProfileId = "Example";
     previousProfile.Body = "Hello";
     bool overwrite = true;
     target.SaveActorProfile(actorProfile, previousProfile, overwrite);
     Assert.Inconclusive(INCONCLUSIVE);
 }
        /// <summary>
        /// A test for pushing and storing Actor Profiles, then deleting them.
        /// </summary>
        /// <remarks>This test should use a dummy actor, not a real one!</remarks>
        //[TestMethod()]
        public void ActorProfileTest()
        {
            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[] 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);
        }
 /// <summary>
 /// Saves an actor profile
 /// </summary>
 /// <param name="actorProfile">The actor profile instance</param>
 /// <param name="previousProfile">The last instance of the actor profile</param>
 /// <param name="overwrite">Flag to force overwrite of the previous profile</param>
 public void SaveActorProfile(ActorProfile actorProfile, ActorProfile previousProfile)
 {
     SaveActorProfile(actorProfile, previousProfile, false);
 }
 /// <summary>
 /// Saves an actor profile
 /// </summary>
 /// <param name="actorProfile">The actor profile instance</param>
 /// <param name="previousProfile">The last instance of the actor profile</param>
 /// <param name="overwrite">Flag to force overwrite of the previous profile</param>
 public void SaveActorProfile(ActorProfile actorProfile, ActorProfile previousProfile, bool overwrite)
 {
     TinCanJsonConverter converter = new TinCanJsonConverter();
     NameValueCollection nvc = new NameValueCollection();
     string putData = actorProfile.Body;
     nvc["profileId"] = actorProfile.ProfileId;
     switch (version)
     {
         case TCAPIVersion.TinCan090:
             nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)previousProfile.Actor);
             break;
         default:
             nvc["actor"] = converter.SerializeToJSON(previousProfile.Actor);
             break;
     }
     nvc["overwrite"] = overwrite.ToString();
     string previousSha1 = string.Empty;
     if (previousProfile != null)
         previousSha1 = BitConverter.ToString(Encryption.GetSha1Hash(Encoding.UTF8.GetBytes(previousProfile.Body))).Replace("-", "");
     string contentType = actorProfile.ContentType;
     HttpMethods.PutRequest(putData, nvc, endpoint + ACTOR_PROFILE, authentification, contentType, previousSha1, versionString);
 }
 /// <summary>
 /// Retrieves an Actor profile
 /// </summary>
 /// <param name="actor">The actor that owns the profile</param>
 /// <param name="profileId">The profile document key</param>
 /// <returns></returns>
 public ActorProfile GetActorProfile(Actor actor, string profileId)
 {
     ActorProfile result = new ActorProfile();
     string getResult;
     TinCanJsonConverter converter = new TinCanJsonConverter();
     NameValueCollection nvc = new NameValueCollection();
     switch (version)
     {
         case TCAPIVersion.TinCan090:
             nvc["actor"] = converter.SerializeToJSON((Model.TinCan090.Actor)actor);
             break;
         default:
             nvc["actor"] = converter.SerializeToJSON(actor);
             break;
     }
     nvc["profileId"] = profileId;
     WebHeaderCollection whc;
     getResult = HttpMethods.GetRequest(nvc, endpoint + ACTOR_PROFILE, authentification, out whc, versionString);
     if (whc != null)
         result.ContentType = whc["Content-Type"];
     result.ProfileId = profileId;
     result.Actor = actor;
     result.Body = getResult;
     return result;
 }