public void FreshenMailBoxTestWithException() { _imapWorker.Setup(false); var r = new ImapCommandResponse(); var fix = new Fixture(); fix.Customize(new AutoMoqCustomization()); var messages = fix.CreateMany<IMessageSummary>().ToList(); //first fetch throws exception - after closing and opening folders now messages are returned //this mirrors how the client has been functioning in real world tests inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(), It.IsAny<CancellationToken>())).ThrowsAsync(new ImapCommandException(r ,"The IMAP server replied to the 'FETCH' command with a 'NO' response.")) .Callback(() => { inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(), It.IsAny<CancellationToken>())).ReturnsAsync(messages); }); _imapWorker.FreshenMailBox(); inbox.Verify(x => x.CloseAsync(It.Is<bool>(y => y == false), It.IsAny<CancellationToken>()), Times.Exactly(1)); inbox.Verify(x => x.OpenAsync(It.IsAny<FolderAccess>(), It.IsAny<CancellationToken>())); }
static bool IsOkNoOrBad(string atom, out ImapCommandResponse response) { if (atom.Equals("OK", StringComparison.OrdinalIgnoreCase)) { response = ImapCommandResponse.Ok; return(true); } if (atom.Equals("NO", StringComparison.OrdinalIgnoreCase)) { response = ImapCommandResponse.No; return(true); } if (atom.Equals("BAD", StringComparison.OrdinalIgnoreCase)) { response = ImapCommandResponse.Bad; return(true); } response = ImapCommandResponse.None; return(false); }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> public ImapCommandException(ImapCommandResponse response) { Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="message">The error message.</param> public ImapCommandException(ImapCommandResponse response, string message) : base(message) { Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="message">The error message.</param> /// <param name="innerException">The inner exception.</param> public ImapCommandException(ImapCommandResponse response, string message, Exception innerException) : base(message, innerException) { Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="responseText">The human-readable response text.</param> public ImapCommandException(ImapCommandResponse response, string responseText) { ResponseText = responseText; Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> public ImapCommandException (ImapCommandResponse response) { Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="message">The error message.</param> public ImapCommandException (ImapCommandResponse response, string message) : base (message) { Response = response; }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="message">The error message.</param> /// <param name="innerException">The inner exception.</param> public ImapCommandException (ImapCommandResponse response, string message, Exception innerException) : base (message, innerException) { Response = response; }
public void FreshenMailBoxTestWithException() { //setup fake imapworker var _configuration = new Mock<ImapClientConfiguration>(); //mock client var client = new Mock<IImapClient>(); //mock inbox folder var inbox = new Mock<IMailFolder>(); //client returns mock inbox client.Setup(x => x.Inbox).Returns(inbox.Object); //mock factory factory = new Mock<IImapFactory>(); factory.Setup(x => x.GetClient()).ReturnsAsync(client.Object); //create the idler and start setup var _imapWorker = new ImapWorker(factory.Object); //setup private object var pvt = new PrivateObject(_imapMailBox); pvt.SetFieldOrProperty("_imapWorker", _imapWorker); var r = new ImapCommandResponse(); //first fetch throws exception - after closing and opening folders now messages are returned //this mirrors how the client has been functioning in real world tests inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(), It.IsAny<CancellationToken>())) .ThrowsAsync(new ImapCommandException(r, "The IMAP server replied to the 'FETCH' command with a 'NO' response.")); //* start the freshen *// var result = (Task<bool>)pvt.Invoke("FreshenMailBox"); Assert.IsFalse(result.Result); factory.Verify(x => x.GetClient(), Times.Exactly(2)); }
public void FreshenMailBoxTestWithMultipleExceptions() { _imapWorker.Setup(false); var r = new ImapCommandResponse(); var fix = new Fixture(); fix.Customize(new AutoMoqCustomization()); var messages = fix.CreateMany<IMessageSummary>().ToList(); //always throw - make sure we can't get stuck inbox.Setup(x => x.FetchAsync(It.IsAny<int>(), It.IsAny<int>(), It.IsAny<MessageSummaryItems>(), It.IsAny<CancellationToken>())) .ThrowsAsync(new ImapCommandException(r, "The IMAP server replied to the 'FETCH' command with a 'NO' response.")); var results = (List<IMessageSummary>) _imapWorker.FreshenMailBox("test").Result; inbox.Verify(x => x.CloseAsync(It.Is<bool>(y => y == false), It.IsAny<CancellationToken>()), Times.Exactly(1)); inbox.Verify(x => x.OpenAsync(It.IsAny<FolderAccess>(), It.IsAny<CancellationToken>()), Times.Exactly(1)); }
/// <summary> /// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommandException"/> class. /// </summary> /// <remarks> /// Creates a new <see cref="ImapCommandException"/>. /// </remarks> /// <param name="response">The IMAP command response.</param> /// <param name="responseText">The human-readable response text.</param> public ImapCommandException (ImapCommandResponse response, string responseText) { ResponseText = responseText; Response = response; }