コード例 #1
0
 public MockWebonaryClient(WebonaryClient.WebonaryException exceptionResponse, byte[] responseContents, HttpStatusCode responseStatus)
 {
     _exceptionResponse = exceptionResponse;
     _responseContents  = responseContents;
     Headers            = new WebHeaderCollection();
     ResponseStatusCode = responseStatus;
 }
コード例 #2
0
        public void UploadToWebonaryReportsLackingPermissionsToUpload()
        {
            var ex = new WebonaryClient.WebonaryException(new WebException("Unable to connect to Webonary.  Please check your username and password and your Internet connection."));

            ex.StatusCode = HttpStatusCode.BadRequest;
            using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, ex, null))
            {
                var view = new MockWebonaryDlg()
                {
                    Model = new UploadToWebonaryModel(m_mediator)
                    {
                        SiteName = "test-india",
                        UserName = "******",
                        Password = "******"
                    }
                };
                controller.UploadToWebonary("../../Src/xWorks/xWorksTests/lubwisi-d-new.zip", view.Model, view);
                Assert.That(view.StatusStrings.Any(s => s.Contains("Unable to connect to Webonary.  Please check your username and password and your Internet connection.")));
            }
        }
コード例 #3
0
        public void UploadToWebonaryReportsIncorrectSiteName()
        {
            // Test for a successful response indicating that a redirect should happen
            using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, null, new byte[] {}, HttpStatusCode.Found))
            {
                var view = new MockWebonaryDlg()
                {
                    Model = new UploadToWebonaryModel(m_mediator)
                    {
                        SiteName = "test",
                        UserName = "******",
                        Password = "******"
                    }
                };
                controller.UploadToWebonary("fakefile.zip", view.Model, view);
                Assert.That(view.StatusStrings.Any(s => s.Contains("Error: There has been an error accessing webonary. Is your sitename correct?")));
            }

            // Test with an exception which indicates a redirect should happen
            var redirectException = new WebonaryClient.WebonaryException(new WebException("Redirected."));

            redirectException.StatusCode = HttpStatusCode.Redirect;
            using (var controller = new MockUploadToWebonaryController(Cache, m_mediator, redirectException, new byte[] { }))
            {
                var view = new MockWebonaryDlg()
                {
                    Model = new UploadToWebonaryModel(m_mediator)
                    {
                        SiteName = "test",
                        UserName = "******",
                        Password = "******"
                    }
                };
                controller.UploadToWebonary("fakefile.zip", view.Model, view);
                Assert.That(view.StatusStrings.Any(s => s.Contains("Error: There has been an error accessing webonary. Is your sitename correct?")));
            }
        }
コード例 #4
0
 /// <summary>
 /// Tests using this constructor do not need to be marked [ByHand]; an exception, response, and response code can all be set.
 /// </summary>
 public MockUploadToWebonaryController(FdoCache cache, Mediator mediator, WebonaryClient.WebonaryException exceptionResponse,
                                       byte[] responseContents, HttpStatusCode responseStatus = HttpStatusCode.OK) : base(cache, mediator)
 {
     CreateWebClient = () => new MockWebonaryClient(exceptionResponse, responseContents, responseStatus);
 }