public void TestBufferOverflowMultipleRuns()
        {
            TestParser parser = new TestParser(128);

            parser.AddBytes(createWhiteSpaceArray(100), 0, 100);
            Assert.Throws <Exceptions.RequestEntityTooLargeException>(
                delegate() { parser.AddBytes(createWhiteSpaceArray(29), 0, 29); }
                );
        }
        public void TestSplitLineEndRecognition()
        {
            TestParser parser = new TestParser(128);

            byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);
            int    crIndex     = Array.IndexOf <byte>(requestData, 13);

            System.Diagnostics.Trace.Assert(crIndex != -1);

            parser.AddBytes(requestData, 0, crIndex + 1);
            Assert.Throws <Exceptions.RequestEntityTooLargeException>(
                delegate() {
                parser.AddBytes(requestData, crIndex + 1, requestData.Length - crIndex);
            }
                );
        }
    public void TestBufferOverflowSingleRun() {
      TestParser parser = new TestParser(128);

      Assert.Throws<Exceptions.RequestEntityTooLargeException>(
        delegate() { parser.AddBytes(createWhiteSpaceArray(129), 0, 129); }
      );
    }
        public void TestExampleRequest()
        {
            TestParser parser = new TestParser(512);

            byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);

            parser.AddBytes(requestData, 0, requestData.Length);
        }
        public void TestExampleRequestWithStartIndex()
        {
            TestParser parser = new TestParser(512);

            byte[] requestData       = Encoding.ASCII.GetBytes(exampleRequest);
            byte[] paddedRequestData = createWhiteSpaceArray(requestData.Length + 512);
            Array.Copy(requestData, 0, paddedRequestData, 512, requestData.Length);

            parser.AddBytes(paddedRequestData, 512, requestData.Length);
        }
        public void TestInvalidCharactersInRequest()
        {
            TestParser parser = new TestParser(128);

            byte[] requestData = Encoding.ASCII.GetBytes("GET /something HTTP/1.1\r\n");
            requestData[6] = 10;
            requestData[9] = 13;

            Assert.Throws <Exceptions.BadRequestException>(
                delegate() { parser.AddBytes(requestData, 0, requestData.Length); }
                );
        }
    public void TestInvalidCharactersInRequest() {
      TestParser parser = new TestParser(128);

      byte[] requestData = Encoding.ASCII.GetBytes("GET /something HTTP/1.1\r\n");
      requestData[6] = 10;
      requestData[9] = 13;

      Assert.Throws<Exceptions.BadRequestException>(
        delegate() { parser.AddBytes(requestData, 0, requestData.Length); }
      );
    }
    public void TestExampleRequest() {
      TestParser parser = new TestParser(512);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);

      parser.AddBytes(requestData, 0, requestData.Length);
    }
    public void TestExampleRequestWithStartIndex() {
      TestParser parser = new TestParser(512);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);
      byte[] paddedRequestData = createWhiteSpaceArray(requestData.Length + 512);
      Array.Copy(requestData, 0, paddedRequestData, 512, requestData.Length);

      parser.AddBytes(paddedRequestData, 512, requestData.Length);
    }
    public void TestSplitLineEndRecognition() {
      TestParser parser = new TestParser(128);

      byte[] requestData = Encoding.ASCII.GetBytes(exampleRequest);
      int crIndex = Array.IndexOf<byte>(requestData, 13);
      System.Diagnostics.Trace.Assert(crIndex != -1);

      parser.AddBytes(requestData, 0, crIndex + 1);
      Assert.Throws<Exceptions.RequestEntityTooLargeException>(
        delegate() {
          parser.AddBytes(requestData, crIndex + 1, requestData.Length - crIndex);
        }
      );
    }