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()); } }
private async Task TestBadAddressAsync(string address) { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); RcptToVerb verb = new RcptToVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); Assert.Equal(0, messageBuilder.To.Count); }
private async Task TestGoodAddressAsync(string address, string expectedAddress) { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); RcptToVerb verb = new RcptToVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK); Assert.Equal(expectedAddress, messageBuilder.To.First()); }
private async Task TestBadAddressAsync(string address) { var mocks = new Mocks(); var messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); var verb = new RcptToVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); Assert.Equal(0, messageBuilder.To.Count); }
private async Task TestGoodAddressAsync(string address, string expectedAddress) { var mocks = new Mocks(); var messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); var verb = new RcptToVerb(); await verb.ProcessAsync(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.Ok); Assert.Equal(expectedAddress, messageBuilder.To.First()); }
private void TestBadAddress(string address) { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); RcptToVerb verb = new RcptToVerb(); verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponse(StandardSmtpResponseCode.SyntaxErrorInCommandArguments); Assert.AreEqual(0, messageBuilder.To.Count); }
private void TestGoodAddress(string address, string expectedAddress) { Mocks mocks = new Mocks(); MemoryMessage.Builder messageBuilder = new MemoryMessage.Builder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); RcptToVerb verb = new RcptToVerb(); verb.Process(mocks.Connection.Object, new SmtpCommand("TO " + address)); mocks.VerifyWriteResponse(StandardSmtpResponseCode.OK); Assert.AreEqual(expectedAddress, messageBuilder.To.First()); }
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); }
public void 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.ReadLine()).Returns(() => messageData[messageLine++]); DataVerb verb = new DataVerb(); verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponse(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponse(StandardSmtpResponseCode.ExceededStorageAllocation); }