本文整理汇总了C#中ImapPseudoServer.Start方法的典型用法代码示例。如果您正苦于以下问题:C# ImapPseudoServer.Start方法的具体用法?C# ImapPseudoServer.Start怎么用?C# ImapPseudoServer.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImapPseudoServer
的用法示例。
在下文中一共展示了ImapPseudoServer.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
}
示例2: 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
}
}
示例3: 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()));
}
}
示例4: 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());
}
}
示例5: 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()));
}
}
示例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());
}
}
示例7: 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) {
}
}
}
}
示例8: 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));
}
示例9: 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);
}
}
示例10: 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);
}
}
}
示例11: 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());
}
}
示例12: 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);
}
}
}
示例13: TestGetResponseNo
public void TestGetResponseNo()
{
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 = "SUBSCRIBE";
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");
// SUBSCRIBE
server.EnqueueResponse("0002 NO failure\r\n");
// LOGOUT
server.EnqueueResponse("* BYE logging out\r\n" +
"0003 OK done\r\n");
try {
using (var response = request.GetResponse()) {
}
}
catch (WebException ex) {
Assert.AreEqual(WebExceptionStatus.ProtocolError, ex.Status);
Assert.IsNotNull(ex.Response);
Assert.IsInstanceOfType(typeof(ImapWebResponse),ex.Response);
var r = ex.Response as ImapWebResponse;
Assert.IsNotNull(r.Result);
}
server.DequeueRequest(); // CAPABILITY
server.DequeueRequest(); // LOGIN
StringAssert.Contains("SUBSCRIBE", server.DequeueRequest());
}
}
示例14: TestGetResponseKeepAliveTrue
public void TestGetResponseKeepAliveTrue()
{
using (var server = new ImapPseudoServer()) {
server.Start();
for (var req = 0; req < 3; req++) {
/*
* request/response
*/
var request = WebRequest.Create(string.Format("imap://{0}/", server.HostPort)) as ImapWebRequest;
request.Timeout = 1000;
request.Method = "NOOP";
request.KeepAlive = true;
if (req == 0) {
// 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");
}
else if (req == 1) {
// NOOP
server.EnqueueResponse("0003 OK done\r\n");
}
else if (req == 2) {
// NOOP
server.EnqueueResponse("0004 OK done\r\n");
}
using (var response = request.GetResponse()) {
}
if (req == 0) {
server.DequeueRequest(); // CAPABILITY
server.DequeueRequest(); // LOGIN
}
StringAssert.Contains("NOOP", server.DequeueRequest(), "request #{0}", req);
}
}
}
示例15: TestGetResponseKeepAliveFalse
public void TestGetResponseKeepAliveFalse()
{
using (var server = new ImapPseudoServer()) {
for (var req = 0; req < 3; 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 = 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()) {
}
server.DequeueRequest(); // CAPABILITY
server.DequeueRequest(); // LOGIN
StringAssert.Contains("NOOP", server.DequeueRequest(), "request #{0}", req);
StringAssert.Contains("LOGOUT", server.DequeueRequest(), "request #{0}", req);
server.Stop();
}
}
}