public override void Write(byte[] buffer, int offset, int count) { CheckDisposed(); Assert.AreNotEqual(SmtpReplayState.SendResponse, state, "Trying to write when a command has already been given."); sent.Write(buffer, offset, count); if (sent.Length >= commands[index].Command.Length) { var command = Encoding.UTF8.GetString(sent.GetBuffer(), 0, (int)sent.Length); if (state == SmtpReplayState.WaitForCommand) { Assert.AreEqual(commands[index].Command, command, "Commands did not match."); stream = GetResourceStream(commands[index].Resource); state = SmtpReplayState.SendResponse; } else if (command == "\r\n.\r\n") { stream = GetResourceStream(commands[index].Resource); state = SmtpReplayState.SendResponse; } sent.SetLength(0); } }
public SmtpReplayStream(IList <SmtpReplayCommand> commands, bool asyncIO) { stream = GetResourceStream(commands[0].Resource); state = SmtpReplayState.SendResponse; this.commands = commands; this.asyncIO = asyncIO; }
public override int Read(byte[] buffer, int offset, int count) { CheckDisposed(); if (asyncIO) { Assert.IsTrue(isAsync, "Trying to Read in an async unit test."); } else { Assert.IsFalse(isAsync, "Trying to ReadAsync in a non-async unit test."); } Assert.AreEqual(SmtpReplayState.SendResponse, state, "Trying to read when no command given."); Assert.IsNotNull(stream, "Trying to read when no data available."); int nread = stream.Read(buffer, offset, count); if (stream.Position == stream.Length) { state = commands[index].Command == "DATA\r\n" ? SmtpReplayState.WaitForEndOfData : SmtpReplayState.WaitForCommand; stream.Dispose(); stream = null; index++; } return(nread); }
public override void Write(byte[] buffer, int offset, int count) { CheckDisposed(); if (asyncIO) { Assert.IsTrue(isAsync, "Trying to Write in an async unit test."); } else { Assert.IsFalse(isAsync, "Trying to WriteAsync in a non-async unit test."); } Assert.AreNotEqual(SmtpReplayState.SendResponse, state, "Trying to write when a command has already been given."); sent.Write(buffer, offset, count); if (sent.Length >= commands[index].Command.Length) { if (state == SmtpReplayState.WaitForCommand) { var command = Encoding.UTF8.GetString(sent.GetBuffer(), 0, (int)sent.Length); if (command.StartsWith("MAIL FROM:", StringComparison.Ordinal)) { var startIndex = command.IndexOf(" SIZE=", StringComparison.Ordinal); if (index != -1) { int endIndex = startIndex + " SIZE=".Length; while (command[endIndex] != ' ' && command[endIndex] != '\r') { endIndex++; } command = command.Remove(startIndex, endIndex - startIndex); } } Assert.AreEqual(commands[index].Command, command, "Commands did not match."); stream = GetResourceStream(commands[index].Resource); state = SmtpReplayState.SendResponse; sent.SetLength(0); } else if (sent.Length > 5) { var command = Encoding.ASCII.GetString(sent.GetBuffer(), (int)sent.Length - 5, 5); if (command == "\r\n.\r\n") { stream = GetResourceStream(commands[index].Resource); state = SmtpReplayState.SendResponse; sent.SetLength(0); } } } }
public SmtpReplayStream(IList<SmtpReplayCommand> commands) { stream = GetResourceStream (commands[0].Resource); state = SmtpReplayState.SendResponse; this.commands = commands; }
public override void Write(byte[] buffer, int offset, int count) { CheckDisposed (); Assert.AreNotEqual (SmtpReplayState.SendResponse, state, "Trying to write when a command has already been given."); var command = Encoding.UTF8.GetString (buffer, offset, count); if (state == SmtpReplayState.WaitForCommand) { Assert.AreEqual (commands[index].Command, command, "Commands did not match."); stream = GetResourceStream (commands[index].Resource); state = SmtpReplayState.SendResponse; } else if (command == "\r\n.\r\n") { stream = GetResourceStream (commands[index].Resource); state = SmtpReplayState.SendResponse; } }
public override int Read(byte[] buffer, int offset, int count) { CheckDisposed (); Assert.AreEqual (SmtpReplayState.SendResponse, state, "Trying to read when no command given."); Assert.IsNotNull (stream, "Trying to read when no data available."); int nread = stream.Read (buffer, offset, count); if (stream.Position == stream.Length) { state = commands[index].Command == "DATA\r\n" ? SmtpReplayState.WaitForEndOfData : SmtpReplayState.WaitForCommand; stream.Dispose (); stream = null; index++; } return nread; }