예제 #1
0
 public void DeleteProfile()
 {
     using (var tester = new SharedCredentialsFileTestFixture(SessionProfileText + Environment.NewLine + BasicProfileCredentialsText))
     {
         tester.CredentialsFile.UnregisterProfile("session_profile");
         tester.AssertCredentialsFileContents(BasicProfileCredentialsText);
     }
 }
예제 #2
0
        public void RenameProfile(bool addUniqueKey)
        {
            var profileText = BasicProfileTextForCopyAndRename;

            if (addUniqueKey)
            {
                profileText += "toolkit_artifact_guid=" + UniqueKey;
            }

            using (var tester = new SharedCredentialsFileTestFixture(profileText))
            {
                // read the profile
                CredentialProfile before;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile("basic_profile", out before));

                // rename it
                tester.CredentialsFile.RenameProfile("basic_profile", "basic_profile2");

                // make sure there isn't one with the original name
                CredentialProfile profile1Reread;
                Assert.IsFalse(tester.CredentialsFile.TryGetProfile("basic_profile", out profile1Reread));

                // make sure one with the new name exists
                CredentialProfile after;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile("basic_profile2", out after));
                Assert.AreNotEqual(before.Name, after.Name);

                // make sure the unique key is the same as before the rename
                if (addUniqueKey)
                {
                    Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(before));
                }
                else
                {
                    Assert.IsNull(CredentialProfileUtils.GetUniqueKey(before));
                }
                Assert.AreEqual(CredentialProfileUtils.GetUniqueKey(before), CredentialProfileUtils.GetUniqueKey(after));

                // make sure everything is the same, except for the name
                ReflectionHelpers.Invoke(after, "Name", before.Name);
                Assert.AreEqual(before, after);

                // make sure comments and other properties are unchanged after the rename
                tester.AssertCredentialsFileContents(profileText.Replace("basic_profile", "basic_profile2"));
            }
        }
예제 #3
0
        public void CopyProfile(bool addUniqueKey, bool addAnotherSection, bool useSameName)
        {
            var profileText = BasicProfileTextForCopyAndRename;
            var fromName    = "basic_profile";
            var toName      = fromName + (useSameName ? "" : "2");

            if (addUniqueKey)
            {
                profileText += "toolkit_artifact_guid=" + UniqueKey + Environment.NewLine;
            }

            var anotherSection = addAnotherSection ? "[another_section]" + Environment.NewLine + "propertyx=valuex" + Environment.NewLine : "";

            using (var tester = new SharedCredentialsFileTestFixture(profileText + anotherSection))
            {
                // read the profile
                CredentialProfile profile1;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(fromName, out profile1));

                // copy it
                tester.CredentialsFile.CopyProfile(fromName, toName);

                // make sure the original is untouched
                CredentialProfile profile1Reread;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(fromName, out profile1Reread));
                Assert.AreEqual(profile1, profile1Reread);

                // make sure the copy exists
                CredentialProfile profile2;
                Assert.IsTrue(tester.CredentialsFile.TryGetProfile(toName, out profile2));

                if (useSameName)
                {
                    Assert.AreEqual(profile1.Name, profile2.Name);
                }
                else
                {
                    Assert.AreNotEqual(profile1.Name, profile2.Name);
                }


                if (addUniqueKey)
                {
                    if (useSameName)
                    {
                        Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(profile1));
                        Assert.AreEqual(CredentialProfileUtils.GetUniqueKey(profile1), CredentialProfileUtils.GetUniqueKey(profile2));
                    }
                    else
                    {
                        Assert.AreEqual(UniqueKey.ToString("D"), CredentialProfileUtils.GetUniqueKey(profile1));
                        Assert.AreNotEqual(CredentialProfileUtils.GetUniqueKey(profile1), CredentialProfileUtils.GetUniqueKey(profile2));
                    }
                }
                else
                {
                    Assert.IsNull(CredentialProfileUtils.GetUniqueKey(profile1));
                    Assert.IsNull(CredentialProfileUtils.GetUniqueKey(profile2));
                }

                var contentsAfter = profileText;

                if (!useSameName)
                {
                    // make sure the comments and everything got copied
                    contentsAfter = (contentsAfter + anotherSection).TrimEnd() + Environment.NewLine;
                    if (addUniqueKey)
                    {
                        contentsAfter += profileText.Replace(fromName, toName)
                                         .Replace(CredentialProfileUtils.GetUniqueKey(profile1).ToString(), CredentialProfileUtils.GetUniqueKey(profile2).ToString()).TrimEnd();
                    }
                    else
                    {
                        contentsAfter += profileText.Replace(fromName, toName);
                    }
                }

                tester.AssertCredentialsFileContents(contentsAfter);

                // make sure everything else on the copy is the same as the original
                string profile1Guid = CredentialProfileUtils.GetUniqueKey(profile1);
                CredentialProfileUtils.SetUniqueKey(profile2, profile1Guid == null ? (Guid?)null : new Guid(profile1Guid));
                ReflectionHelpers.Invoke(profile2, "Name", profile1.Name);
                Assert.AreEqual(profile1, profile2);

                //make sure the additional key came along
                var value1 = CredentialProfileUtils.GetProperty(profile1, "property");
                var value2 = CredentialProfileUtils.GetProperty(profile2, "property");
                Assert.AreEqual("value", value1);
                Assert.AreEqual(value1, value2);
            }
        }