//
        // Helpers
        //

        private static Mock <IWebClient> SetupFetch(ResponseOrException responseOrException,
                                                    WebHeaderCollection headers = null)
        {
            var webClient = new Mock <IWebClient>();

            webClient
            .SetupGet(x => x.Headers)
            .Returns(headers ?? new WebHeaderCollection());

            responseOrException.ReturnOrThrow(webClient.Setup(x => x.DownloadData(It.IsAny <string>())));

            return(webClient);
        }
示例#2
0
        // Set up the login process. Response-or-exception parameters provide either
        // response or exception depending on the desired behavior. The login process
        // is two phase: request iteration count, then log in receive the session id.
        // Each of the stages might fail because of the network problems or some other
        // reason.
        private static Mock <IWebClient> SetupLogin(ResponseOrException iterationsResponseOrException,
                                                    ResponseOrException loginResponseOrException = null)
        {
            var webClient = new Mock <IWebClient>();
            var sequence  = webClient.SetupSequence(x => x.UploadValues(It.IsAny <string>(),
                                                                        It.IsAny <NameValueCollection>()));

            iterationsResponseOrException.ReturnOrThrow(sequence);
            if (loginResponseOrException != null)
            {
                loginResponseOrException.ReturnOrThrow(sequence);
            }

            return(webClient);
        }
        //
        // Helpers
        //

        private static Mock <IWebClient> SetupLogout(ResponseOrException responseOrException,
                                                     WebHeaderCollection headers = null)
        {
            var webClient = new Mock <IWebClient>();

            webClient
            .SetupGet(x => x.Headers)
            .Returns(headers ?? new WebHeaderCollection());

            responseOrException.ReturnOrThrow(
                webClient.Setup(x => x.UploadValues(It.IsAny <string>(),
                                                    It.IsAny <NameValueCollection>())));

            return(webClient);
        }