Example #1
0
        internal static CredentialsStore GetInstance([CallerMemberName] string callerName = "")
        {
            var instance = new CredentialsStore();

            InstanceFactory(ref instance, callerName);
            return(instance);
        }
        public static void AssemblyInitialize(TestContext context)
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");

            RestClientManager.BasicAuthorizationUsername = credentials.BasicAuthorizationUsername;
            RestClientManager.BasicAuthorizationPassword = credentials.BasicAuthorizationPassword;
        }
Example #3
0
        public void TestConstructor_LoadsAccounts()
        {
            const string account1FilePath = "c:\\account1.json";
            var          account1         = new UserAccount {
                AccountName = "Account1"
            };
            const string account2FilePath = "c:\\account2.json";
            var          account2         = new UserAccount {
                AccountName = "Account2"
            };

            _fileSystemMock.Setup(fs => fs.Directory.Exists(It.IsAny <string>())).Returns(true);
            _fileSystemMock.Setup(fs => fs.Directory.EnumerateFiles(It.IsAny <string>()))
            .Returns(new[] { account1FilePath, account2FilePath });
            _fileSystemMock.Setup(fs => fs.File.ReadAllText(account1FilePath))
            .Returns(JsonConvert.SerializeObject(account1));
            _fileSystemMock.Setup(fs => fs.File.ReadAllText(account2FilePath))
            .Returns(JsonConvert.SerializeObject(account2));

            _objectUnderTest = new CredentialsStore(_fileSystemMock.ToLazy());

            CollectionAssert.AreEquivalent(
                new[] { account1.AccountName, account2.AccountName },
                _objectUnderTest.AccountsList.Select(a => a.AccountName).ToList());
            Assert.AreEqual(account1.AccountName, _objectUnderTest.GetAccount(account1.AccountName).AccountName);
        }
Example #4
0
        public void TestConstructor_ResetsCredentialsFromDefault()
        {
            const string account1Name      = "Account1";
            const string account1FilePath  = "c:\\account1.json";
            const string expectedProjectId = "Expected Project Id";
            var          account1          = new UserAccount {
                AccountName = account1Name
            };
            var defaultCredentials =
                new DefaultCredentials {
                AccountName = account1Name, ProjectId = expectedProjectId
            };

            _fileSystemMock.Setup(fs => fs.Directory.Exists(It.IsAny <string>())).Returns(true);
            _fileSystemMock.Setup(fs => fs.Directory.EnumerateFiles(It.IsAny <string>()))
            .Returns(new[] { account1FilePath });
            _fileSystemMock.Setup(fs => fs.File.ReadAllText(account1FilePath))
            .Returns(JsonConvert.SerializeObject(account1));
            _fileSystemMock.Setup(fs => fs.File.Exists(It.IsAny <string>())).Returns(true);
            _fileSystemMock
            .Setup(
                fs => fs.File.ReadAllText(
                    It.Is <string>(
                        s => s.EndsWith(CredentialsStore.DefaultCredentialsFileName, StringComparison.Ordinal))))
            .Returns(
                JsonConvert.SerializeObject(
                    defaultCredentials));

            _objectUnderTest = new CredentialsStore(_fileSystemMock.ToLazy());

            Assert.AreEqual(account1.AccountName, _objectUnderTest.CurrentAccount.AccountName);
            Assert.AreEqual(expectedProjectId, _objectUnderTest.CurrentProjectId);
        }
Example #5
0
 public void BasicAuthorizationUsername_UnitTest()
 {
     ExecuteProperty(
         () =>
         // Create Test Instance
     {
         CredentialsStore instance = GetInstance();
         return(instance);
     },
         // Create Set Value
         instance =>
     {
         string setValue = default(String);
         BasicAuthorizationUsername_SetCondition(ref instance, ref setValue);
         return(setValue);
     },
         // Invoke Setter
         (instance, setValue) => { instance.BasicAuthorizationUsername = setValue; },
         // Validate Set Operation
         (instance, setValue) => { },
         // Invoke Getter
         instance => { return(instance.BasicAuthorizationUsername); },
         // Validate Get Operation
         (instance, setValue, getValue) => { });
 }
Example #6
0
 public void VsoCollection_UnitTest()
 {
     ExecuteProperty(
         () =>
         // Create Test Instance
     {
         CredentialsStore instance = GetInstance();
         return(instance);
     },
         // Create Set Value
         instance =>
     {
         string setValue = default(String);
         VsoCollection_SetCondition(ref instance, ref setValue);
         return(setValue);
     },
         // Invoke Setter
         (instance, setValue) => { instance.VsoCollection = setValue; },
         // Validate Set Operation
         (instance, setValue) => { },
         // Invoke Getter
         instance => { return(instance.VsoCollection); },
         // Validate Get Operation
         (instance, setValue, getValue) => { });
 }
Example #7
0
        public void GetWorkItem_UnitTest2()
        {
            IWorkItemStore   instance    = GetTestInstance();
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            IWorkItem        actual      = instance.GetWorkItem(new Uri(credentials.VsoCollection));

            Assert.IsNotNull(actual);
        }
Example #8
0
        internal static WorkItemStore GetRealInstance()
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            var uri  = new Uri(credentials.VsoCollection);
            var tpc  = new TfsTeamProjectCollection(uri);
            var real = tpc.GetService <WorkItemStore>();

            return(real);
        }
Example #9
0
        public void TestConstructor_SkipsNonJsonFiles()
        {
            _fileSystemMock.Setup(fs => fs.Directory.Exists(It.IsAny <string>())).Returns(true);
            const string notAccountFilePath = "c:\\notAnAccount.txt";

            _fileSystemMock.Setup(fs => fs.Directory.EnumerateFiles(It.IsAny <string>()))
            .Returns(new[] { notAccountFilePath });

            _objectUnderTest = new CredentialsStore(_fileSystemMock.ToLazy());

            _fileSystemMock.Verify(fs => fs.File.ReadAllText(notAccountFilePath), Times.Never);
        }
Example #10
0
        public void TestConstructor_DoesNotThrowForInvalidDefaultCredentialsFile()
        {
            _fileSystemMock.Setup(fs => fs.File.Exists(It.IsAny <string>())).Returns(true);
            _fileSystemMock
            .Setup(
                fs => fs.File.ReadAllText(
                    It.Is <string>(
                        s => s.EndsWith(CredentialsStore.DefaultCredentialsFileName, StringComparison.Ordinal))))
            .Returns("This Is Not JSON!");

            _objectUnderTest = new CredentialsStore(_fileSystemMock.ToLazy());
        }
Example #11
0
        public void TestConstructor_ThrowsCredentialsStoreExceptionForInvalidJson()
        {
            const string account1FilePath = "c:\\account1.json";

            _fileSystemMock.Setup(fs => fs.Directory.Exists(It.IsAny <string>())).Returns(true);
            _fileSystemMock.Setup(fs => fs.Directory.EnumerateFiles(It.IsAny <string>()))
            .Returns(new[] { account1FilePath });
            _fileSystemMock.Setup(fs => fs.File.ReadAllText(account1FilePath)).Returns("This is not Json!");

            Assert.ThrowsException <CredentialsStoreException>(
                () => _objectUnderTest = new CredentialsStore(
                    _fileSystemMock.ToLazy()));
        }
        public void Read_UnitTest()
        {
            String           filePath = default(String);
            CredentialsStore _retVal  = default(CredentialsStore);

            ExecuteMethod(
                () =>
            {
                filePath = default(String);     //No Constructor
                Read_PreCondition(ref filePath);
            },
                () => { _retVal = CredentialsProvider.Read(filePath); },
                () => { Read_PostValidate(filePath, _retVal); });
        }
Example #13
0
        public void ReadAllProperties_UnitTest()
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            var uri = new Uri(credentials.VsoCollection);
            var tpc = new TfsTeamProjectCollection(uri);

            tpc.EnsureAuthenticated();
            var                 workItemStore = tpc.GetService <WorkItemStore>();
            const string        wiql          = "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] FROM WorkItems";
            WorkItemCollection  real          = workItemStore.Query(wiql);
            IWorkItemCollection instance      = WorkItemCollectionWrapper.GetWrapper(real);

            ReadAllProperties(typeof(IWorkItemCollection), instance);
        }
        public void Write_UnitTest()
        {
            String           filePath    = default(String);
            CredentialsStore credentials = default(CredentialsStore);

            ExecuteMethod(
                () =>
            {
                filePath    = default(String);  //No Constructor
                credentials = new CredentialsStore();
                Write_PreCondition(ref filePath, ref credentials);
            },
                () => { CredentialsProvider.Write(filePath, credentials); },
                () => { Write_PostValidate(filePath, credentials); });
        }
Example #15
0
 public void Values_UnitTest()
 {
     ExecuteProperty(
         () =>
         // Create Test Instance
     {
         CredentialsStore instance = GetInstance();
         return(instance);
     },
         null, null, null, // No Set Accessor
         // Invoke Getter
         instance => { return(instance.Values); },
         // Validate Get Operation
         (instance, setValue, getValue) => { });
 }
Example #16
0
        public static void AssemblyInitialize(TestContext context)
        {
            //CredentialsStore credentials = new CredentialsStore();
            //credentials.BasicAuthorizationUsername = "******";
            //credentials.BasicAuthorizationPassword = "******";
            //credentials.VsoCollection = "https://*****.visualstudio.com/defaultcollection";
            //CredentialsProvider.Write(@"..\..\RestCredentials.xml", credentials);
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");

            RestClientManager.BasicAuthorizationUsername = credentials.BasicAuthorizationUsername;
            RestClientManager.BasicAuthorizationPassword = credentials.BasicAuthorizationPassword;
            VSOClientManager.VsoCollection = credentials.VsoCollection;

            StructuredExchangeLogger.Install();
        }
Example #17
0
        /// <summary>
        ///     Finds the type of the work item.
        /// </summary>
        /// <param name="workItemTypeName">Name of the work item type.</param>
        /// <returns>WorkItemType.</returns>
        internal static WorkItemType FindWorkItemType(string workItemTypeName)
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            var uri = new Uri(credentials.VsoCollection);
            var tpc = new TfsTeamProjectCollection(uri);

            tpc.EnsureAuthenticated();
            var                    workItemStore = tpc.GetService <WorkItemStore>();
            const string           projectName   = "RestPlaypen";
            Project                item          = workItemStore.Projects[projectName];
            WorkItemTypeCollection workItemTypes = item.WorkItemTypes;
            WorkItemType           workItemType  = workItemTypes.Cast <WorkItemType>().First(entry => entry.Name == workItemTypeName);

            return(workItemType);
        }
Example #18
0
        public void BeforeEach()
        {
            _defaultProject = new Project {
                ProjectId = DefaultProjectId
            };
            _defaultUserAccount = Mock.Of <IUserAccount>(ua => ua.AccountName == DefaultAccountName);

            _fileSystemMock = new Mock <IFileSystem> {
                DefaultValueProvider = DefaultValueProvider.Mock
            };

            _objectUnderTest = new CredentialsStore(_fileSystemMock.ToLazy());

            _projectIdChangedHandlerMock = new Mock <Action <object, EventArgs> >();
            _accountChangedHandlerMock   = new Mock <Action <object, EventArgs> >();
        }
        public void ReadWrite_UnitTest()
        {
            const string fileName   = "ReST_Credentiials.xml";
            var          sourceData = new CredentialsStore();

            sourceData.BasicAuthorizationUsername = "******";
            sourceData.BasicAuthorizationPassword = "******";
            sourceData.VsoCollection = "MyVsoCollection";
            Assert.AreEqual(3, sourceData.Values.Count);
            CredentialsProvider.Write(fileName, sourceData);
            CredentialsStore resultData = CredentialsProvider.Read(fileName);

            Assert.AreEqual(sourceData.BasicAuthorizationUsername, resultData.BasicAuthorizationUsername);
            Assert.AreEqual(sourceData.BasicAuthorizationPassword, resultData.BasicAuthorizationPassword);
            Assert.AreEqual(sourceData.VsoCollection, resultData.VsoCollection);
        }
Example #20
0
 partial void Write_PreCondition(ref String filePath, ref CredentialsStore credentials)
 {
     filePath = "TestingOutputCredentials.xml";
 }
Example #21
0
 partial void VsoCollection_SetCondition(ref CredentialsStore instance, ref String setValue);
Example #22
0
 partial void Values_SetCondition(ref CredentialsStore instance, ref Dictionary <String, String> setValue);
Example #23
0
 partial void ToString_PreCondition(CredentialsStore instance);
Example #24
0
 partial void ToString_PostValidate(ref CredentialsStore instance, String _retVal);
Example #25
0
 partial void GetType_PreCondition(CredentialsStore instance);
Example #26
0
 partial void GetType_PostValidate(ref CredentialsStore instance, Type _retVal);
Example #27
0
 partial void GetHashCode_PreCondition(CredentialsStore instance);
Example #28
0
 partial void GetHashCode_PostValidate(ref CredentialsStore instance, Int32 _retVal);
Example #29
0
        static partial void RealInstanceFactory(ref IMetadataRowSets real, string callerName)
        {
            CredentialsStore credentials = CredentialsProvider.Read(@"..\..\..\RestCredentials.xml");
            var uri = new Uri(credentials.VsoCollection);
            var tpc = new TfsTeamProjectCollection(uri);

            var workitemserver = tpc.GetService <WorkItemServer>();
            var workitemstore  = tpc.GetService <WorkItemStore>();
            var id             = 1;
            var workitem       = workitemstore.GetWorkItem(id);


            // When you call update you need to pass the revision number that you want to update.
            // Most of the time ist t makes sense to use the latest revision, which is stored in the Rev property
            var revision = workitem.Rev.ToString();
            var date     = DateTime.Today;

            // Create the xml package that is needed when calling the server to update a readonly field.
            // Make sure you pass in the date using XmlConvert.ToString(date, XmlDateTimeSerializationMode.Local)
            // You won't get the correct date if you just call date.ToString()
            var sb = new StringBuilder();

            sb.Append("<Package>");
            sb.AppendFormat("<UpdateWorkItem ObjectType='WorkItem' BypassRules='1' WorkItemID='{0}' Revision='{1}'>", id, revision);
            sb.Append("<Columns>");
            sb.AppendFormat("<Column Column='System.CreatedDate' Type='DateTime'><Value>{0}</Value></Column>",
                            XmlConvert.ToString(date, XmlDateTimeSerializationMode.Local));
            sb.Append("</Columns></UpdateWorkItem></Package>");

            /* This is what the XML looks like
             *  <Package>
             *    <UpdateWorkItem ObjectType='WorkItem' BypassRules='1' WorkItemID='1279424' Revision='11'>
             *      <Columns>
             *         <Column Column='System.CreatedDate' Type='DateTime'><Value>1/1/2012 1:01:01 AM</Value></Column>
             *      </Columns>
             *    </UpdateWorkItem>
             *  </Package>
             */


            // Initialize the params that are needed for the service call
            var mthe = new MetadataTableHaveEntry[0];

            // Load the xml string into an XmlDocument so you can pull the document Element that
            // the service call needs
            var x = new XmlDocument();

            x.LoadXml(sb.ToString());


            IMetadataRowSets metadata;
            string           dbStamp;
            int        count;
            DateTime   asOfDate;
            string     requestId = "";
            XmlElement psQuery   = (XmlElement)x.FirstChild;
            bool       useMaster = true;

            workitemserver.QueryWorkitemCount(requestId, psQuery, useMaster, out count, out asOfDate, new MetadataTableHaveEntry[] {}, out dbStamp, out metadata);

            real = metadata;
        }
Example #30
0
 static partial void InstanceFactory(ref CredentialsStore instance, [CallerMemberName] string callerName = "");