private async Task TestGoodDataAsync(string[] messageData, string expectedData, bool eightBitClean) { Mocks mocks = new Mocks(); if (eightBitClean) { mocks.Connection.SetupGet(c => c.ReaderEncoding).Returns(Encoding.UTF8); } MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns((long?)null); int messageLine = 0; mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK); using (StreamReader dataReader = new StreamReader(messageBuilder.GetData(), eightBitClean ? Encoding.UTF8 : new ASCIISevenBitTruncatingEncoding())) { Assert.Equal(expectedData, dataReader.ReadToEnd()); } }
private async Task TestGoodDataAsync(string[] messageData, string expectedData, bool eightBitClean) { Mocks mocks = new Mocks(); if (eightBitClean) { mocks.Connection.SetupGet(c => c.ReaderEncoding).Returns(Encoding.UTF8); } MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny<IConnection>())).Returns((long?)null); int messageLine = 0; mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK); using (StreamReader dataReader = new StreamReader(messageBuilder.GetData(), eightBitClean ? Encoding.UTF8 : new ASCIISevenBitTruncatingEncoding())) { Assert.Equal(expectedData, dataReader.ReadToEnd()); } }
public async Task Data_NoCurrentMessage_ReturnsError() { Mocks mocks = new Mocks(); DataVerb verb = new DataVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.BadSequenceOfCommands); }
public async Task Data_AboveSizeLimit_Rejected() { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny<IConnection>())).Returns(10); string[] messageData = new string[] { new string('x', 11), "." }; int messageLine = 0; mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.ExceededStorageAllocation); }
public async Task Data_ExactlySizeLimit_Accepted() { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns(10); string[] messageData = new string[] { new string('x', 10), "." }; int messageLine = 0; mocks.Connection.Setup(c => c.ReadLineAsync()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK); }