Exemplo n.º 1
0
 public ImapReplayStream(IList <ImapReplayCommand> commands, bool asyncIO, bool testUnixFormat = false)
 {
     stream = GetResponseStream(commands[0]);
     state  = ImapReplayState.SendResponse;
     this.testUnixFormat = testUnixFormat;
     this.commands       = commands;
     this.asyncIO        = asyncIO;
 }
Exemplo n.º 2
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            if (asyncIO)
            {
                if (count != 6 || Encoding.ASCII.GetString(buffer, offset, count) != "DONE\r\n")
                {
                    Assert.IsTrue(isAsync, "Trying to Write in an async unit test.");
                }
                else
                {
                    done = true;
                }
            }
            else
            {
                if (count != 6 || Encoding.ASCII.GetString(buffer, offset, count) != "DONE\r\n")
                {
                    Assert.IsFalse(isAsync, "Trying to WriteAsync in a non-async unit test.");
                }
                else
                {
                    done = true;
                }
            }

            Assert.AreEqual(ImapReplayState.WaitForCommand, state, "Trying to write when a command has already been given.");

            sent.Write(buffer, offset, count);

            if (sent.Length >= commands[index].CommandBuffer.Length)
            {
                var command = GetSentCommand();

                Assert.AreEqual(commands[index].Command, command, "Commands did not match.");

                if (stream != null)
                {
                    stream.Dispose();
                }

                stream = GetResponseStream(commands[index]);
                state  = ImapReplayState.SendResponse;
                sent.SetLength(0);
            }
        }
Exemplo n.º 3
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            Assert.AreEqual(ImapReplayState.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 = ImapReplayState.WaitForCommand;
                index++;
            }

            return(nread);
        }
Exemplo n.º 4
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            if (state != ImapReplayState.SendResponse)
            {
                var command = Latin1.GetString(sent.GetBuffer(), 0, (int)sent.Length);

                Assert.AreEqual(ImapReplayState.SendResponse, state, "Trying to read before command received. Sent so far: {0}", command);
            }
            Assert.IsNotNull(stream, "Trying to read when no data available.");

            int nread = stream.Read(buffer, offset, count);

            if (stream.Position == stream.Length)
            {
                state = ImapReplayState.WaitForCommand;
                index++;
            }

            return(nread);
        }
Exemplo n.º 5
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            Assert.AreEqual(ImapReplayState.WaitForCommand, 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 = Latin1.GetString(sent.GetBuffer(), 0, (int)sent.Length);

                Assert.AreEqual(commands[index].Command, command, "Commands did not match.");

                if (stream != null)
                {
                    stream.Dispose();
                }

                stream = GetResponseStream(commands[index]);
                state  = ImapReplayState.SendResponse;
                sent.SetLength(0);
            }
        }
Exemplo n.º 6
0
        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.");
            }

            if (state != ImapReplayState.SendResponse)
            {
                if (index >= commands.Count)
                {
                    return(0);
                }

                var command = GetSentCommand();

                Assert.AreEqual(ImapReplayState.SendResponse, state, "Trying to read before command received. Sent so far: {0}", command);
            }
            Assert.IsNotNull(stream, "Trying to read when no data available.");

            int nread = stream.Read(buffer, offset, count);

            if (stream.Position == stream.Length)
            {
                state = ImapReplayState.WaitForCommand;
                index++;
            }

            return(nread);
        }
Exemplo n.º 7
0
		public ImapReplayStream (IList<ImapReplayCommand> commands, bool testUnixFormat)
		{
			stream = GetResponseStream (commands[0]);
			state = ImapReplayState.SendResponse;
			this.testUnixFormat = testUnixFormat;
			this.commands = commands;
		}
Exemplo n.º 8
0
		public override void Write (byte[] buffer, int offset, int count)
		{
			CheckDisposed ();

			Assert.AreEqual (ImapReplayState.WaitForCommand, 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 = Latin1.GetString (sent.GetBuffer (), 0, (int) sent.Length);

				Assert.AreEqual (commands[index].Command, command, "Commands did not match.");

				if (stream != null)
					stream.Dispose ();

				stream = GetResponseStream (commands[index]);
				state = ImapReplayState.SendResponse;
				sent.SetLength (0);
			}
		}
Exemplo n.º 9
0
		public override int Read (byte[] buffer, int offset, int count)
		{
			CheckDisposed ();

			if (state != ImapReplayState.SendResponse) {
				var command = Latin1.GetString (sent.GetBuffer (), 0, (int) sent.Length);

				Assert.AreEqual (ImapReplayState.SendResponse, state, "Trying to read before command received. Sent so far: {0}", command);
			}
			Assert.IsNotNull (stream, "Trying to read when no data available.");

			int nread = stream.Read (buffer, offset, count);

			if (stream.Position == stream.Length) {
				state = ImapReplayState.WaitForCommand;
				index++;
			}

			return nread;
		}
Exemplo n.º 10
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            CheckDisposed ();

            Assert.AreEqual (ImapReplayState.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 = ImapReplayState.WaitForCommand;
                index++;
            }

            return nread;
        }