public void CustomSmartSubtransportTest(string scheme, string url)
        {
            string remoteName = "testRemote";

            var scd      = BuildSelfCleaningDirectory();
            var repoPath = Repository.Init(scd.RootedDirectoryPath);

            SmartSubtransportRegistration <MockSmartSubtransport> registration = null;

            try
            {
                // Disable server certificate validation for testing.
                // Do *NOT* enable this in production.
                ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;

                registration = GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>(scheme);
                Assert.NotNull(registration);

                using (var repo = new Repository(scd.DirectoryPath))
                {
                    Remote remote = repo.Network.Remotes.Add(remoteName, url);

                    // Set up structures for the expected results
                    // and verifying the RemoteUpdateTips callback.
                    TestRemoteInfo     expectedResults    = TestRemoteInfo.TestRemoteInstance;
                    ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);

                    // Add expected branch objects
                    foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                    {
                        expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                    }

                    // Add the expected tags
                    string[] expectedTagNames = { "blob", "commit_tree" };
                    foreach (string tagName in expectedTagNames)
                    {
                        TestRemoteInfo.ExpectedTagInfo expectedTagInfo = expectedResults.Tags[tagName];
                        expectedFetchState.AddExpectedTag(tagName, ObjectId.Zero, expectedTagInfo);
                    }

                    // Perform the actual fetch
                    repo.Network.Fetch(remote, new FetchOptions {
                        OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto
                    });

                    // Verify the expected
                    expectedFetchState.CheckUpdatedReferences(repo);
                }
            }
            finally
            {
                GlobalSettings.UnregisterSmartSubtransport(registration);

                ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
            }
        }
        public void CannotUnregisterTwice()
        {
            SmartSubtransportRegistration <MockSmartSubtransport> httpRegistration =
                GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>("http");

            GlobalSettings.UnregisterSmartSubtransport(httpRegistration);

            Assert.Throws <NotFoundException>(() =>
                                              GlobalSettings.UnregisterSmartSubtransport(httpRegistration));
        }
        public static void Unregister()
        {
            if (_registration == null)
            {
                return;
            }

            GlobalSettings.UnregisterSmartSubtransport(_registration);
            _registration = null;
        }
        public void CanUseCredentials(string scheme, string url, string user, string pass)
        {
            string remoteName = "testRemote";

            var scd = BuildSelfCleaningDirectory();

            Repository.Init(scd.RootedDirectoryPath);

            SmartSubtransportRegistration <MockSmartSubtransport> registration = null;

            try
            {
                // Disable server certificate validation for testing.
                // Do *NOT* enable this in production.
                ServicePointManager.ServerCertificateValidationCallback = certificateValidationCallback;

                registration = GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>(scheme);
                Assert.NotNull(registration);

                using (var repo = new Repository(scd.DirectoryPath))
                {
                    repo.Network.Remotes.Add(remoteName, url);

                    // Set up structures for the expected results
                    // and verifying the RemoteUpdateTips callback.
                    TestRemoteInfo     expectedResults    = TestRemoteInfo.TestRemoteInstance;
                    ExpectedFetchState expectedFetchState = new ExpectedFetchState(remoteName);

                    // Add expected branch objects
                    foreach (KeyValuePair <string, ObjectId> kvp in expectedResults.BranchTips)
                    {
                        expectedFetchState.AddExpectedBranch(kvp.Key, ObjectId.Zero, kvp.Value);
                    }

                    // Perform the actual fetch
                    Commands.Fetch(repo, remoteName, new string[0], new FetchOptions {
                        OnUpdateTips        = expectedFetchState.RemoteUpdateTipsHandler, TagFetchMode = TagFetchMode.Auto,
                        CredentialsProvider = (_user, _valid, _hostname) => new UsernamePasswordCredentials()
                        {
                            Username = user, Password = pass
                        },
                    }, null);

                    // Verify the expected
                    expectedFetchState.CheckUpdatedReferences(repo);
                }
            }
            finally
            {
                GlobalSettings.UnregisterSmartSubtransport(registration);

                ServicePointManager.ServerCertificateValidationCallback -= certificateValidationCallback;
            }
        }
        public void CannotReregisterScheme()
        {
            SmartSubtransportRegistration <MockSmartSubtransport> httpRegistration =
                GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>("http");

            try
            {
                Assert.Throws <EntryExistsException>(() =>
                                                     GlobalSettings.RegisterSmartSubtransport <MockSmartSubtransport>("http"));
            }
            finally
            {
                GlobalSettings.UnregisterSmartSubtransport(httpRegistration);
            }
        }
        public static void Register(string pathToSsh)
        {
            if (_registration != null)
            {
                return;
            }

            if (!File.Exists(pathToSsh))
            {
                throw new ArgumentException("SSH at path {0} not found.", pathToSsh);
            }

            ExePath       = pathToSsh;
            _registration = GlobalSettings.RegisterSmartSubtransport <SshExeTransport>("ssh");
        }
Exemplo n.º 7
0
 public TfsSmartSession()
 {
     httpRegistration  = GlobalSettings.RegisterSmartSubtransport <TfsSmartSubtransport> ("http");
     httpsRegistration = GlobalSettings.RegisterSmartSubtransport <TfsSmartSubtransport> ("https");
 }
		public TfsSmartSession ()
		{
			httpRegistration = GlobalSettings.RegisterSmartSubtransport<TfsSmartSubtransport> ("http");
			httpsRegistration = GlobalSettings.RegisterSmartSubtransport<TfsSmartSubtransport> ("https");
		}