private void TestGoodData(string[] messageData, string expectedData) { Mocks mocks = new Mocks(); Message message = new Message(mocks.Session.Object); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(message); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).Returns((long?)null); 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.OK); using (StreamReader dataReader = new StreamReader(message.GetData(), Encoding.ASCII)) { Assert.AreEqual(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 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 static void SetDataVerb(XElement Element, string Name, DataVerb Value) { XElement ValElement = new XElement(CDO.Namespace + Name); SetDataVerb(ValElement, Value); Element.Add(ValElement); }
public static void SetDataVerb(XElement Element, DataVerb Value) { XElement El = new XElement(CDO.Namespace + "dataverb"); El.Value = Value.ToString(); Element.Add(El); }
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 void MessageAboveFixedSize() { Mocks mocks = new Mocks(); Message message = new Message(mocks.Session.Object); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(message); 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); }
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 async Task Data_AboveSizeLimit_Rejected() { TestMocks mocks = new TestMocks(); MemoryMessageBuilder messageBuilder = new MemoryMessageBuilder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).ReturnsAsync(10); string[] messageData = new string[] { new string('x', 11), "." }; int messageLine = 0; mocks.Connection.Setup(c => c.ReadLine()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")).ConfigureAwait(false); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.ExceededStorageAllocation); }
public void MessageInsideFixedSize() { Mocks mocks = new Mocks(); Message message = new Message(mocks.Session.Object); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(message); 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.ReadLine()).Returns(() => messageData[messageLine++]); DataVerb verb = new DataVerb(); verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponse(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponse(StandardSmtpResponseCode.OK); }
private void TestGoodData(string[] messageData, string expectedData) { Mocks mocks = new Mocks(); Message message = new Message(mocks.Session.Object); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(message); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny<IConnection>())).Returns((long?)null); 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.OK); using (StreamReader dataReader = new StreamReader(message.GetData(), Encoding.ASCII)) { Assert.AreEqual(expectedData, dataReader.ReadToEnd()); } }
/// <summary> /// /// </summary> /// <param name="messageData">The messageData<see cref="string"/></param> /// <param name="expectedData">The expectedData<see cref="string"/></param> /// <returns>A <see cref="Task{T}"/> representing the async operation</returns> private async Task TestGoodDataAsync(string[] messageData, string expectedData) { TestMocks mocks = new TestMocks(); MemoryMessageBuilder messageBuilder = new MemoryMessageBuilder(); mocks.Connection.SetupGet(c => c.CurrentMessage).Returns(messageBuilder); mocks.ServerBehaviour.Setup(b => b.GetMaximumMessageSize(It.IsAny <IConnection>())).ReturnsAsync((long?)null); int messageLine = 0; mocks.Connection.Setup(c => c.ReadLine()).Returns(() => Task.FromResult(messageData[messageLine++])); DataVerb verb = new DataVerb(); await verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")).ConfigureAwait(false); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.StartMailInputEndWithDot); mocks.VerifyWriteResponseAsync(StandardSmtpResponseCode.OK); using (StreamReader dataReader = new StreamReader(await messageBuilder.GetData().ConfigureAwait(false), Encoding.UTF8)) { Assert.Equal(expectedData, dataReader.ReadToEnd()); } }
public void Data_NoCurrentMessage_ReturnsError() { Mocks mocks = new Mocks(); DataVerb verb = new DataVerb(); verb.Process(mocks.Connection.Object, new SmtpCommand("DATA")); mocks.VerifyWriteResponse(StandardSmtpResponseCode.BadSequenceOfCommands); }