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 SmtpResponse(StandardSmtpResponseCode code, string message, params object[] args) : this((int)code, message, args) { }
/// <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); } }
/// <summary> /// /// </summary> /// <param name="responseCode">The responseCode<see cref="StandardSmtpResponseCode"/></param> public void VerifyWriteResponseAsync(StandardSmtpResponseCode responseCode) { this.Connection.Verify(c => c.WriteResponse(It.Is <SmtpResponse>(r => r.Code == (int)responseCode))); }
public void VerifyWriteResponse(StandardSmtpResponseCode responseCode) { Connection.Verify(c => c.WriteResponse(It.Is<SmtpResponse>(r => r.Code == (int)responseCode))); }
public void VerifyWriteResponse(StandardSmtpResponseCode responseCode) { VerifyWriteResponse(responseCode, Times.Once()); }
/// <summary> /// /// </summary> /// <param name="responseCode">The responseCode<see cref="StandardSmtpResponseCode"/></param> public void VerifyWriteResponse(StandardSmtpResponseCode responseCode, Times times) { this.Connection.Verify(c => c.WriteResponse(It.Is <SmtpResponse>(r => r.Code == (int)responseCode)), times); }
public SmtpResponse(StandardSmtpResponseCode code, string message, params object[] args) : this((int) code, message, args) { }