Пример #1
0
        public void UploadTheGistToGitHub()
        {
            var gitHubSender = new MockGitHubSender();
            var gistApi = new UploadsGists { GitHubSender = gitHubSender };

            gistApi.Upload("file3.cs", "My oh my");

            gitHubSender.SentAGist.Should().Be.True();
        }
Пример #2
0
        public void GistUrlWillBeAvaible()
        {
            string actualUrl = null;

            var gitHubSender = new MockGitHubSender() { ResultingUrl = "http://gist.github.com/123" };
            var gistApi = new UploadsGists { GitHubSender = gitHubSender };

            gistApi.Uploaded = url => actualUrl = url;
            gistApi.Upload("file3.cs", "My oh my");

            actualUrl.Should().Equal("http://gist.github.com/123");
        }
Пример #3
0
        public void CompleteOccursAtTheEnd()
        {
            var wasSuccessful = false;

            var uploads = new UploadsGists();

            uploads.Uploaded = url => wasSuccessful = true;

            uploads.Upload("asdf", "qwer");

            wasSuccessful.Should().Be.True();
        }
Пример #4
0
        public void WillBeSentWithAppliedCredentials()
        {
            var gitHubSender = new MockGitHubSender();

            var uploads = new UploadsGists { GitHubSender = gitHubSender };

            var credentials = new GitHubUserCredentials("something", "secret");
            uploads.UseCredentials(credentials);

            uploads.Upload("file4.cs", "gee wizz");

            gitHubSender.LastCredentialsApplied.Should().Equal(credentials);
        }
Пример #5
0
        public void WillAllowUsToGetInvolvedWhenCredentialsAreBad()
        {
            var sender = new MockGitHubSender();
            sender.FailWith("Blah");

            var uploads = new UploadsGists();
            uploads.GitHubSender = sender;

            var didTellUs = false;
            uploads.CredentialsAreBad = () => didTellUs = true;

            uploads.Upload("asdf", "asdF");

            didTellUs.Should().Be.True();
        }
Пример #6
0
        /// <summary>
        /// This function is the callback used to execute a command when the a menu item is clicked.
        /// See the Initialize method to see how the menu item is associated to this function using
        /// the OleMenuCommandService service and the MenuCommand class.
        /// </summary>
        private void CreateGist(object sender, EventArgs e)
        {
            var view = GetActiveTextView();

            if (NotReadyRockAndRoll(view)) return;

            var content = GetCurrentContentForGist(view);
            var fileName = GetCurrentFilenameForGist();

            var credentials = GetGitHubCredentials();

            NotifyUserThat("Creating gist for {0}", fileName);

            if (credentials == GitHubCredentials.Anonymous)
            {
                NotifyUserThat("Cancelled Gist");
                return;
            }

            var uploadsGists = new UploadsGists
                                   {
                                       GitHubSender = new HttpGitHubSender(),
                                       CredentialsAreBad = () =>
                                                               {
                                                                   NotifyUserThat("Gist not created.  Invalid GitHub Credentials");
                                                                   new CachesGitHubCredentials().AssureNotCached();
                                                               },
                                       Uploaded = url =>
                                                      {
                                                          Clipboard.SetText(url);
                                                          new CachesGitHubCredentials().Cache(credentials);

                                                          NotifyUserThat("Gist created successfully.  Url placed in the clipboard.");
                                                      }
                                   };

            uploadsGists.UseCredentials(credentials);

            uploadsGists.Upload(fileName, content);
        }