• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ImapPseudoServer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ImapPseudoServer的典型用法代码示例。如果您正苦于以下问题:C# ImapPseudoServer类的具体用法?C# ImapPseudoServer怎么用?C# ImapPseudoServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ImapPseudoServer类属于命名空间,在下文中一共展示了ImapPseudoServer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestCreateSessionAppropriateMechanismNotFound

        public void TestCreateSessionAppropriateMechanismNotFound()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var credential = new NetworkCredential("user", "pass");
            var requestUri = new Uri(string.Format("imap://{0}/", server.HostPort));
            var request = WebRequest.Create(requestUri) as ImapWebRequest;

            request.Credentials = credential;
            request.UseTlsIfAvailable = true;
            request.KeepAlive = false;
            request.Timeout = 1000;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("* CAPABILITY IMAP4rev1 LOGINDISABLED\r\n" +
                               "0000 OK done\r\n");

            try {
              using (var response = request.GetResponse()) {
              }
            }
            catch (WebException ex) {
              WebExceptionAssertion(WebExceptionStatus.RequestCanceled, ex);
            }

            server.DequeueRequest(); // CAPABILITY
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:31,代码来源:ImapSessionManager.cs


示例2: TestAuthenticateInsecureLoginDisallowed

        public void TestAuthenticateInsecureLoginDisallowed()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var prof = new Profile(new NetworkCredential("user", "pass"), "user;auth=*", server.HostPort);

            prof.UsingSaslMechanisms = new[] {"LOGIN", "PLAIN", "CRAM-MD5"};
            prof.AllowInsecureLogin = false;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("* CAPABILITY IMAP4rev1 AUTH=X-UNKNOWN AUTH=DIGEST-MD5 AUTH=CRAM-MD5 AUTH=NTLM AUTH=PLAIN AUTH=LOGIN\r\n" +
                               "0000 OK done\r\n");
            // AUTHENTICATE CRAM-MD5 response
            server.EnqueueResponse("+ PDQwMDEzNDQxMTIxNDM1OTQuMTI3MjQ5OTU1MEBsb2NhbGhvc3Q+\r\n");
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");

            using (var session = ImapSessionCreator.CreateSession(prof, null, null)) {
              Assert.AreEqual(ImapSessionState.Authenticated, session.State);
              Assert.AreEqual(prof.Authority, session.Authority);
            }

            server.DequeueRequest(); // CAPABILITY
            StringAssert.Contains("AUTHENTICATE CRAM-MD5", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:29,代码来源:ImapSessionCreator.cs


示例3: TestGetResponseStreamResponseHasNoStream

        public void TestGetResponseStreamResponseHasNoStream()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;

            request.Timeout = 1000;
            request.Method = ImapWebRequestMethods.NoOp;
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");
            // NOOP
            server.EnqueueResponse("0002 OK done\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0003 OK done\r\n");

            using (var response = request.GetResponse()) {
              try {
            response.GetResponseStream();
            Assert.Fail("InvalidOperationException not thrown");
              }
              catch (InvalidOperationException) {
              }
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:35,代码来源:ImapWebResponse.cs


示例4: TestAuthenticateAnonymousMechanismSpecified

        public void TestAuthenticateAnonymousMechanismSpecified()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var prof = new Profile(null, "user%40imap.example.net;auth=anonymous", server.HostPort);

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("* CAPABILITY IMAP4rev1 AUTH=ANONYMOUS\r\n" +
                               "0000 OK done\r\n");
            // AUTHENTICATE response
            server.EnqueueResponse("+ \r\n");
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");

            using (var session = ImapSessionCreator.CreateSession(prof, null, null)) {
              Assert.AreEqual(ImapSessionState.Authenticated, session.State);
              Assert.AreEqual(prof.Authority, session.Authority);
            }

            server.DequeueRequest(); // CAPABILITY
            StringAssert.Contains("AUTHENTICATE ANONYMOUS", server.DequeueRequest());
            StringAssert.Contains("[email protected]", Base64.GetDecodedString(server.DequeueRequest()));
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:27,代码来源:ImapSessionCreator.cs


示例5: TestAuthenticateAnonymousMechanismSpecifiedAuthenticationFailure

        public void TestAuthenticateAnonymousMechanismSpecifiedAuthenticationFailure()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var prof = new Profile(null, "user%40imap.example.net;auth=anonymous", server.HostPort);

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("* CAPABILITY IMAP4rev1 AUTH=ANONYMOUS\r\n" +
                               "0000 OK done\r\n");
            // AUTHENTICATE response
            server.EnqueueResponse("+ \r\n");
            server.EnqueueResponse("0001 NO done\r\n");

            try {
              Assert.IsNull(ImapSessionCreator.CreateSession(prof, null, null));
              Assert.Fail("ImapAuthenticationException not thrown");
            }
            catch (ImapAuthenticationException ex) {
              Assert.IsNull(ex.InnerException);
              Assert.IsNotNull(ex.Result);
              Assert.AreEqual(Protocol.Client.ImapCommandResultCode.No, ex.Result.Code);
            }

            server.DequeueRequest(); // CAPABILITY
            StringAssert.Contains("AUTHENTICATE ANONYMOUS", server.DequeueRequest());
            StringAssert.Contains("[email protected]", Base64.GetDecodedString(server.DequeueRequest()));
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:31,代码来源:ImapSessionCreator.cs


示例6: TestBeginGetResponse

        public void TestBeginGetResponse()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;

            request.Method = "NOOP";
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK [CAPABILITY IMAP4rev1] ready\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // NOOP
            server.EnqueueResponse("0001 OK done\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0002 OK done\r\n");

            var asyncState = "async state";
            var asyncResult = request.BeginGetResponse(null, asyncState);

            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(asyncResult.AsyncState, asyncState);

            using (var response = request.EndGetResponse(asyncResult)) {
            }

            StringAssert.Contains("LOGIN", server.DequeueRequest());
            StringAssert.Contains("NOOP", server.DequeueRequest());
            StringAssert.Contains("LOGOUT", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:35,代码来源:ImapWebRequest.cs


示例7: TestGetCopyResponseCreateDestinationMailboxFailure

        public void TestGetCopyResponseCreateDestinationMailboxFailure()
        {
            using (var server = new ImapPseudoServer()) {
            var methodResponses = new[] {
              // UID SEARCH
              "* SEARCH 3 4 5\r\n" +
              "0003 OK done\r\n",
              // UID COPY
              "0004 NO [TRYCREATE] failed\r\n",
              // CREATE
              "0005 NO failed\r\n",
            };

            var presetRequest = (Action<ImapWebRequest>)delegate(ImapWebRequest req) {
              req.AllowCreateMailbox = true;
              req.DestinationUri = new Uri(req.RequestUri.GetLeftPart(UriPartial.Path) + "/コピー先メールボックス");
            };

            Request(server, ImapWebRequestMethods.Copy, new[] {"IMAP4REV1"}, "?UNSEEN", methodResponses, presetRequest, delegate(ImapWebRequest request, ImapWebResponse response) {
              Assert.AreEqual(request.RequestUri, response.ResponseUri);

              Assert.IsNotNull(response);
              Assert.IsNotNull(response.Result);
              Assert.IsTrue(response.Result.Failed);
            });

            StringAssert.EndsWith("UID SEARCH UNSEEN\r\n", server.DequeueRequest());
            StringAssert.EndsWith("UID COPY 3,4,5 \"INBOX/&MLMw1DD8UUgw4TD8MOsw3DDDMK8wuQ-\"\r\n", server.DequeueRequest());
            StringAssert.EndsWith("CREATE \"INBOX/&MLMw1DD8UUgw4TD8MOsw3DDDMK8wuQ-\"\r\n", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:31,代码来源:ImapSearchMessageWebRequest.cs


示例8: TestGetCopyResponseCopyUidResponseExists

        public void TestGetCopyResponseCopyUidResponseExists()
        {
            using (var server = new ImapPseudoServer()) {
            var methodResponses = new[] {
              // UID SEARCH
              "* SEARCH 3 4 5\r\n" +
              "0003 OK done\r\n",
              // UID COPY
              "0004 OK [COPYUID 38505 3,4,5 3956:3958] done\r\n"
            };

            var presetRequest = (Action<ImapWebRequest>)delegate(ImapWebRequest req) {
              req.AllowCreateMailbox = false;
              req.DestinationUri = new Uri(req.RequestUri.GetLeftPart(UriPartial.Path) + "/コピー先メールボックス");
            };

            Request(server, ImapWebRequestMethods.Copy, new[] {"IMAP4rev1"}, "?UNSEEN", methodResponses, presetRequest, delegate(ImapWebRequest request, ImapWebResponse response) {
              Assert.AreEqual(new Uri(string.Format("{0}/INBOX/コピー先メールボックス;UIDVALIDITY=38505?UID 3956:3958", request.RequestUri.GetLeftPart(UriPartial.Authority))),
                response.ResponseUri);

              Assert.IsNotNull(response);
              Assert.IsNotNull(response.Result);
              Assert.IsTrue(response.Result.Succeeded);

              Assert.IsNotNull(response.Mailboxes);
              Assert.AreEqual(0, response.Mailboxes.Length);
            });

            StringAssert.EndsWith("UID SEARCH UNSEEN\r\n", server.DequeueRequest());
            StringAssert.EndsWith("UID COPY 3,4,5 \"INBOX/&MLMw1DD8UUgw4TD8MOsw3DDDMK8wuQ-\"\r\n", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:32,代码来源:ImapSearchMessageWebRequest.cs


示例9: TestCreateSessionInternalError

        public void TestCreateSessionInternalError()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var credential = new NetworkCredential("user", "pass");
            var request = WebRequest.Create(string.Format("imap://{0};[email protected]{1}/", credential.UserName, server.HostPort)) as ImapWebRequest;

            request.Credentials = credential;
            request.KeepAlive = false;
            request.UsingSaslMechanisms = new[] {"DIGEST-MD5"};
            request.Timeout = 1000;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY response
            server.EnqueueResponse("* CAPABILITY IMAP4rev1 AUTH=DIGEST-MD5 AUTH=CRAM-MD5 AUTH=NTLM AUTH=PLAIN AUTH=LOGIN\r\n" +
                               "0000 OK done\r\n");
            // AUTHENTICATE DIGEST-MD5 response
            server.EnqueueResponse("+ xxx-invalid-response-xxx\r\n");

            try {
              using (var response = request.GetResponse()) {
              }
            }
            catch (WebException ex) {
              WebExceptionAssertion(WebExceptionStatus.UnknownError, ex);
              Assert.IsInstanceOfType(typeof(ImapException), ex.InnerException);
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:31,代码来源:ImapSessionManager.cs


示例10: TestGetCopyResponseDestinationUriNotSet

        public void TestGetCopyResponseDestinationUriNotSet()
        {
            using (var server = new ImapPseudoServer()) {
            var methodResponses = new string[] {};

            Request(server, ImapWebRequestMethods.Copy, methodResponses, delegate(ImapWebRequest request, ImapWebResponse response) {
              Assert.Fail("InvalidOperationException not thrown");
            });
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:10,代码来源:ImapFetchMessageWebRequest.cs


示例11: Setup

        public void Setup()
        {
            server = new ImapPseudoServer();
              server.Start();

              host = server.ServerEndPoint.Address.ToString();
              port = server.ServerEndPoint.Port;

              credential = new NetworkCredential(username, password, host);
              uri = new Uri(string.Format("{0}://{1}@{2}:{3}",
                                  ImapUri.UriSchemeImap,
                                  username,
                                  host,
                                  port));
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:15,代码来源:ImapSessionTestsBase.cs


示例12: TestBeginGetRequestStreamCallback

        public void TestBeginGetRequestStreamCallback()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");
            // APPEND
            server.EnqueueResponse("+ continue\r\n");
            server.EnqueueResponse(string.Empty);

            var request = WebRequest.Create(string.Format("imap://{0}/INBOX", server.HostPort)) as ImapWebRequest;

            request.Method = "APPEND";
            request.Timeout = 3000;
            request.ReadWriteTimeout = 3000;
            request.AllowInsecureLogin = true;

            var asyncResult = request.BeginGetRequestStream((AsyncCallback)BeginGetRequestStreamCallbackProc, request);

            Thread.Sleep(100); // XXX

            if (!asyncResult.AsyncWaitHandle.WaitOne(5000))
              Assert.Fail("wait time out");

            server.EnqueueResponse("0002 OK done\r\n");

            using (var response = request.GetResponse()) {
            }

            server.DequeueRequest(); // CAPABILITY
            server.DequeueRequest(); // LOGIN

            var appendCommand = server.DequeueAll();

            StringAssert.StartsWith("0002 APPEND \"INBOX\" ", appendCommand);
            StringAssert.EndsWith(" {12}\r\ntest message\r\n", appendCommand);
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:45,代码来源:ImapMailboxWebRequest.cs


示例13: TestCreateSessionConnectFailure

        public void TestCreateSessionConnectFailure()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var credential = new NetworkCredential("user", "pass");
            var request = WebRequest.Create(string.Format("imap://{0}@{1}/", credential.UserName, server.HostPort)) as ImapWebRequest;

            request.Timeout = 500;

            server.Stop();

            try {
              using (var response = request.GetResponse()) {
              }
            }
            catch (WebException ex) {
              WebExceptionAssertion(WebExceptionStatus.ConnectFailure, ex);
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:21,代码来源:ImapSessionManager.cs


示例14: TestBeginGetResponseCallback

        public void TestBeginGetResponseCallback()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;

            request.Method = "NOOP";
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK [CAPABILITY IMAP4rev1] ready\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");

            var asyncResult = request.BeginGetResponse(BeginGetResponseCallbackProc, request);

            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(asyncResult.AsyncState, request);

            Thread.Sleep(1000);

            StringAssert.Contains("LOGIN", server.DequeueRequest());

            // NOOP
            server.EnqueueResponse("0001 OK done\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0002 OK done\r\n");

            if (!asyncResult.AsyncWaitHandle.WaitOne(5000))
              Assert.Fail("not completed");

            StringAssert.Contains("NOOP", server.DequeueRequest());
            StringAssert.Contains("LOGOUT", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:38,代码来源:ImapWebRequest.cs


示例15: TestGetXListResponse

        public void TestGetXListResponse()
        {
            using (var server = new ImapPseudoServer()) {
            var methodResponse = "* XLIST (\\HasNoChildren \\Starred) \"/\" \"[Gmail]/&MLkwvzD8TtgwTQ-\"\r\n" +
                             "0002 OK done\r\n";

            Request(server, ImapWebRequestMethods.XList, new[] {"IMAP4rev1", "XLIST"}, methodResponse, delegate(ImapWebRequest request, ImapWebResponse response) {
              Assert.IsNotNull(response);

              Assert.AreEqual(response.ResponseUri, request.RequestUri);

              Assert.IsNotNull(response.Result);
              Assert.IsTrue(response.Result.Succeeded);

              Assert.IsNotNull(response.Mailboxes);
              Assert.AreEqual(1, response.Mailboxes.Length);

              Assert.AreEqual(new Uri(request.RequestUri, "[Gmail]/スター付き"), response.Mailboxes[0].Url);
            });

            StringAssert.Contains("XLIST \"\" *", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:23,代码来源:ImapServerWebRequest.cs


示例16: TestBeginConnectException

        public void TestBeginConnectException()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            using (var client = new ImapClient(server.Host, server.Port, "user")) {
              client.Profile.Timeout = 250;

              Assert.IsFalse(client.IsConnected);

              var asyncResult = client.BeginConnect("pass");

              try {
            client.EndConnect(asyncResult);
            Assert.Fail("ImapConnectionException not thrown");
              }
              catch (ImapConnectionException) {
            Assert.IsNull((client.Profile as IImapSessionProfile).Credentials);
              }

              Assert.IsFalse(client.IsConnected);
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:24,代码来源:ImapClient.cs


示例17: KeepAliveAndDisconnected

        private void KeepAliveAndDisconnected(bool disconnectFromServer)
        {
            using (var server = new ImapPseudoServer()) {
            for (var req = 0; req < 2; req++) {
              server.Start();

              /*
               * request/response
               */
              var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;

              request.Timeout = 1000;
              request.Method = "NOOP";
              request.KeepAlive = true;

              // greeting
              server.EnqueueResponse("* OK ready\r\n");
              // CAPABILITY
              server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                                 "0000 OK done\r\n");
              // LOGIN
              server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                                 "0001 OK done\r\n");
              // NOOP
              server.EnqueueResponse("0002 OK done\r\n");

              using (var response = request.GetResponse()) {
              }

              server.DequeueRequest(); // CAPABILITY
              server.DequeueRequest(); // LOGIN
              StringAssert.Contains("NOOP", server.DequeueRequest(), "request #{0}", req);

              if (disconnectFromServer) {
            server.Stop();
              }
              else {
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                                   "0003 OK done\r\n");

            ImapSessionManager.DisconnectFrom(request.RequestUri);

            server.DequeueRequest(); // LOGOUT

            server.Stop();
              }
            }
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:50,代码来源:ImapWebRequest.cs


示例18: TestGetResponseOk

        public void TestGetResponseOk()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;

            request.Timeout = 1000;
            request.Method = "NOOP";
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");
            // NOOP
            server.EnqueueResponse("0002 OK done\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0003 OK done\r\n");

            using (var response = request.GetResponse()) {
              Assert.IsNotNull(response);
              Assert.IsInstanceOfType(typeof(ImapWebResponse), response);

              var r = response as ImapWebResponse;

              Assert.IsNotNull(r.Result);
            }

            server.DequeueRequest(); // CAPABILITY
            server.DequeueRequest(); // LOGIN
            StringAssert.Contains("NOOP", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:39,代码来源:ImapWebRequest.cs


示例19: TestGetResponseNoWithUnxpectedResponseCode

        public void TestGetResponseNoWithUnxpectedResponseCode()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/INBOX", server.HostPort)) as ImapWebRequest;

            request.Timeout = 1000;
            request.Method = "SELECT";
            request.ExpectedErrorResponseCodes = new[] {ImapResponseCode.PrivacyRequired};
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");
            // SELECT
            server.EnqueueResponse("0002 NO [NOPERM] failed\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0003 OK done\r\n");

            try {
              using (var response = request.GetResponse() as ImapWebResponse) {
            Assert.Fail("WebException not thrown");
              }
            }
            catch (WebException ex) {
              Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status);

              var response = ex.Response as ImapWebResponse;

              Assert.IsNotNull(response);
              Assert.AreEqual(response.ResponseCode, ImapResponseCode.NoPerm);
            }

            server.DequeueRequest(); // CAPABILITY
            server.DequeueRequest(); // LOGIN
            StringAssert.EndsWith("SELECT \"INBOX\"\r\n", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:45,代码来源:ImapWebRequest.cs


示例20: TestGetResponseNoWithExpectedResponseCode

        public void TestGetResponseNoWithExpectedResponseCode()
        {
            using (var server = new ImapPseudoServer()) {
            server.Start();

            var request = WebRequest.Create(string.Format("imap://{0}/INBOX", server.HostPort)) as ImapWebRequest;

            request.Timeout = 1000;
            request.Method = "SELECT";
            request.ExpectedErrorResponseCodes = new[] {ImapResponseCode.PrivacyRequired};
            request.KeepAlive = false;

            // greeting
            server.EnqueueResponse("* OK ready\r\n");
            // CAPABILITY
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0000 OK done\r\n");
            // LOGIN
            server.EnqueueResponse("* CAPABILITY IMAP4rev1\r\n" +
                               "0001 OK done\r\n");
            // SELECT
            server.EnqueueResponse("0002 NO [PRIVACYREQUIRED] failed\r\n");
            // LOGOUT
            server.EnqueueResponse("* BYE logging out\r\n" +
                               "0003 OK done\r\n");

            using (var response = request.GetResponse() as ImapWebResponse) {
              Assert.IsTrue(response.Result.Failed);
            }

            server.DequeueRequest(); // CAPABILITY
            server.DequeueRequest(); // LOGIN
            StringAssert.EndsWith("SELECT \"INBOX\"\r\n", server.DequeueRequest());
              }
        }
开发者ID:pengyancai,项目名称:cs-util,代码行数:35,代码来源:ImapWebRequest.cs



注:本文中的ImapPseudoServer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ImmutableArray类代码示例发布时间:2022-05-24
下一篇:
C# ImageView类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap