public void SmtpResponse() { SmtpResponse smtpResponse = new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation, "Blah"); SmtpServerException e = new SmtpServerException(smtpResponse); Assert.AreSame(smtpResponse, e.SmtpResponse); }
/// <summary> /// The Process_AddressAsync /// </summary> /// <param name="address">The address<see cref="string"/></param> /// <param name="expectedParsedAddress">The expectedParsedAddress<see cref="string"/></param> /// <param name="expectedResponse">The expectedResponse<see cref="StandardSmtpResponseCode"/></param> /// <returns>A <see cref="Task{T}"/> representing the async operation</returns> private async Task Process_AddressAsync(string address, string expectedParsedAddress, StandardSmtpResponseCode expectedResponse, bool asException = false, bool eightBitMessage = false) { TestMocks mocks = new TestMocks(); Mock <IMessageBuilder> message = new Mock <IMessageBuilder>(); message.SetupGet(m => m.EightBitTransport).Returns(eightBitMessage); IMessageBuilder currentMessage = null; mocks.Connection.Setup(c => c.NewMessage()).ReturnsAsync(() => { currentMessage = message.Object; return(currentMessage); }); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(() => currentMessage); MailFromVerb mailFromVerb = new MailFromVerb(); if (!asException) { await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM " + address)).ConfigureAwait(false); mocks.VerifyWriteResponse(expectedResponse); } else { SmtpServerException e = await Assert.ThrowsAsync <SmtpServerException>(() => mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM " + address))); Assert.Equal((int)expectedResponse, e.SmtpResponse.Code); } if (expectedParsedAddress != null) { message.VerifySet(m => m.From = expectedParsedAddress); } }
public void SmtpResponse() { SmtpResponse smtpResponse = new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation, "Blah"); SmtpServerException e = new SmtpServerException(smtpResponse); Assert.Same(smtpResponse, e.SmtpResponse); }
public void InnerException() { Exception innerException = new Exception(); SmtpServerException e = new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation, "Blah"), innerException); Assert.AreSame(innerException, e.InnerException); }
public void InnerException() { Exception innerException = new Exception(); SmtpServerException e = new SmtpServerException(new SmtpResponse(StandardSmtpResponseCode.ExceededStorageAllocation, "Blah"), innerException); Assert.Same(innerException, e.InnerException); }
public async Task Process_UnknownParameter_Throws() { SmtpServerException e = await Assert.ThrowsAsync <SmtpServerException>(async() => { TestMocks mocks = new TestMocks(); ParameterProcessorMap map = new ParameterProcessorMap(); await map.Process(mocks.Connection.Object, new string[] { "KEYA=VALUEA" }, true).ConfigureAwait(false); }).ConfigureAwait(false); Assert.Equal("Parameter KEYA is not recognised", e.Message); }
/// <summary> /// /// </summary> /// <param name="address">The address<see cref="string"/></param> /// <returns>A <see cref="Task{T}"/> representing the async operation</returns> private async Task TestBadAddressAsync(string address, bool asException = false) { TestMocks mocks = new TestMocks(); MemoryMessageBuilder messageBuilder = new MemoryMessageBuilder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); RcptToVerb verb = new RcptToVerb(); if (!asException) { await verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address)).ConfigureAwait(false); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); } else { SmtpServerException e = await Assert.ThrowsAsync <SmtpServerException>(() => verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address))).ConfigureAwait(false); Assert.Equal((int)StandardSmtpResponseCode.SyntaxErrorInCommandArguments, e.SmtpResponse.Code); } Assert.Equal(0, messageBuilder.Recipients.Count); }