/// <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); } }
private void Process_Address(string address, string expectedParsedAddress, StandardSmtpResponseCode expectedResponse) { Mocks mocks = new Mocks(); Mock <IMessageBuilder> message = new Mock <IMessageBuilder>(); IMessageBuilder currentMessage = null; mocks.Connection.Setup(c => c.NewMessage()).Returns(() => { currentMessage = message. Object; return (currentMessage); } ); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(() => currentMessage); MailFromVerb mailFromVerb = new MailFromVerb(); mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM " + address)); mocks.VerifyWriteResponse(expectedResponse); message.VerifySet(m => m.From = expectedParsedAddress); }
public async Task Process_MissingAddress_ErrorResponse() { TestMocks mocks = new TestMocks(); MailFromVerb mailFromVerb = new MailFromVerb(); await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM")).ConfigureAwait(false); mocks.VerifyWriteResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); }
public void Process_MissingAddress_ErrorResponse() { Mocks mocks = new Mocks(); MailFromVerb mailFromVerb = new MailFromVerb(); mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM")); mocks.VerifyWriteResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); }
public async Task Process_AlreadyGivenFrom_ErrorResponse() { TestMocks mocks = new TestMocks(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(new Mock <IMessageBuilder>().Object); MailFromVerb mailFromVerb = new MailFromVerb(); await mailFromVerb.Process(mocks.Connection.Object, new SmtpCommand("FROM <*****@*****.**>")).ConfigureAwait(false); mocks.VerifyWriteResponse(StandardSmtpResponseCode.BadSequenceOfCommands); }