Beispiel #1
0
        public void TestServerWebViewUrl_ReturnsSettingsVstsUrl()
        {
            var testVstsAccount           = "my-account";
            var exptectedServerWebViewUrl = VstsServerURL.GetVstsServerURL(testVstsAccount);
            var appSettings = Substitute.For <IAppSettings>();

            appSettings.VstsAccount.Returns(testVstsAccount);
            var systemUnderTest = new CouldNotReachServerViewModel(Substitute.For <IApplicationActions>(), appSettings);

            Assert.That(systemUnderTest.ServerWebViewUrl, Is.EqualTo(exptectedServerWebViewUrl));
        }
        public void TestGetServer_ForAccountNotInCache_CallsServerFactoryWithUri()
        {
            const string vstsAccount     = "vsts";
            var          serverUri       = VstsServerURL.GetVstsServerURL(vstsAccount);
            var          tpcFactory      = Substitute.For <ITfProjectCollectionFactory>();
            var          systemUnderTest = new TfProjectCollectionCache(tpcFactory);

            systemUnderTest.GetProjectCollection(vstsAccount);

            tpcFactory.Received().Create(serverUri);
        }
        public void TestGetServer_ForAccountInCache_DoesNotCallServerFactory()
        {
            const string vstsAccount       = "test-account";
            var          expectedServerUrl = VstsServerURL.GetVstsServerURL(vstsAccount);
            var          tpcFactory        = Substitute.For <ITfProjectCollectionFactory>();
            var          systemUnderTest   = new TfProjectCollectionCache(tpcFactory);

            systemUnderTest.GetProjectCollection(vstsAccount);
            // Check that the factory was called once by now...
            tpcFactory.Received().Create(expectedServerUrl);
            Assert.That(tpcFactory.ReceivedCalls().Count(), Is.EqualTo(1));

            systemUnderTest.GetProjectCollection(vstsAccount);

            Assert.That(tpcFactory.ReceivedCalls().Count(), Is.EqualTo(1));
        }
        public void TestGetServer_ForAccountInCache_ReturnsCachedValue()
        {
            const string vstsAccount = "omnipave";
            var          serverUri   = VstsServerURL.GetVstsServerURL(vstsAccount);
            var          tpcFactory  = Substitute.For <ITfProjectCollectionFactory>();
            var          expected    = Substitute.For <ITfProjectCollection>();

            tpcFactory.Create(serverUri).Returns(expected);
            var systemUnderTest = new TfProjectCollectionCache(tpcFactory);

            systemUnderTest.GetProjectCollection(vstsAccount);
            // Check that the factory was called once by now...
            tpcFactory.Received().Create(serverUri);
            Assert.That(tpcFactory.ReceivedCalls().Count(), Is.EqualTo(1));

            var actual = systemUnderTest.GetProjectCollection(vstsAccount);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public ITfProjectCollection GetProjectCollection(string vstsAccount)
        {
            if (vstsAccount == "")
            {
                return(NullTeamProjectCollection);
            }

            _mutex.WaitOne();
            if (!_servers.ContainsKey(vstsAccount))
            {
                var serverUrl = VstsServerURL.GetVstsServerURL(vstsAccount);
                _servers[vstsAccount] = _projectCollectionFactory.Create(serverUrl);
            }
            var tfsServer = _servers[vstsAccount];

            _mutex.ReleaseMutex();

            return(tfsServer);
        }