Ejemplo n.º 1
0
        public void SendBody_NotAHeadOrGetRequest_Void()
        {
            //Arrange
            var httpResponse             = MockRepository.GenerateMock <HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock <IHttpResponseHeaderHelper>();
            var transmitEntityStrategy   = MockRepository.GenerateMock <ITransmitEntityStrategy>();
            var requestHttpMethod        = HttpMethod.Options;

            var firstStartRange = 0L;
            var firstEndRange   = 499L;

            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange   = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange   = 999L;

            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange   = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            var ex = Assert.Throws <Exception>(() => multiPartEntityResponse.SendBody(requestHttpMethod, httpResponse, transmitEntityStrategy));
        }
Ejemplo n.º 2
0
        public void SendHeaders_EntityCompressionDeflateRequestedCompressionGzip_Void()
        {
            //Arrange
            var httpResponse             = MockRepository.GenerateMock <HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock <IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock <IEntity>();
            var responseCompressionType = ResponseCompressionType.GZip;
            var entityCompressionType   = ResponseCompressionType.Deflate;

            var firstStartRange = 0L;
            var firstEndRange   = 499L;
            var firstRangeItem  = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange   = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange   = 999L;
            var secondRangeItem  = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange   = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            var ex = Assert.Throws <Exception>(() => multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity));
        }
Ejemplo n.º 3
0
        public void SendHeaders_EntityCompressionNoneRequestedCompressionGzip_Void()
        {
            //Arrange
            var httpResponse             = MockRepository.GenerateMock <HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock <IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock <IEntity>();
            var responseCompressionType = ResponseCompressionType.GZip;
            var entityCompressionType   = ResponseCompressionType.None;

            var firstStartRange = 0L;
            var firstEndRange   = 499L;
            var firstRangeItem  = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange   = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange   = 999L;
            var secondRangeItem  = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange   = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            httpResponse.Stub(x => x.Filter).PropertyBehavior();
            httpResponse.Filter = new MemoryStream();

            httpResponseHeaderHelper.Expect(x => x.SetContentEncoding(httpResponse, responseCompressionType));
            httpResponse.Expect(x => x.ContentType = EntityResponseMultiPart.MultipartContenttype);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);

            multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity);

            //Assert
            httpResponseHeaderHelper.VerifyAllExpectations();
            httpResponse.VerifyAllExpectations();

            Assert.IsInstanceOf(typeof(GZipStream), httpResponse.Filter);
        }
        public void SendHeaders_EntityCompressionNoneRequestedCompressionGzip_Void()
        {
            //Arrange
            var httpResponse = MockRepository.GenerateMock<HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock<IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock<IEntity>();
            var responseCompressionType = ResponseCompressionType.GZip;
            var entityCompressionType = ResponseCompressionType.None;

            var firstStartRange = 0L;
            var firstEndRange = 499L;
            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange = 999L;
            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            httpResponse.Stub(x => x.Filter).PropertyBehavior();
            httpResponse.Filter = new MemoryStream();

            httpResponseHeaderHelper.Expect(x => x.SetContentEncoding(httpResponse, responseCompressionType));
            httpResponse.Expect(x => x.ContentType = EntityResponseMultiPart.MultipartContenttype);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity);

            //Assert
            httpResponseHeaderHelper.VerifyAllExpectations();
            httpResponse.VerifyAllExpectations();

            Assert.IsInstanceOf(typeof(GZipStream), httpResponse.Filter);
        }
        public void SendBody_NotAHeadOrGetRequest_Void()
        {
            //Arrange
            var httpResponse = MockRepository.GenerateMock<HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock<IHttpResponseHeaderHelper>();
            var transmitEntityStrategy = MockRepository.GenerateMock<ITransmitEntityStrategy>();
            var requestHttpMethod = HttpMethod.Options;

            var firstStartRange = 0L;
            var firstEndRange = 499L;

            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange = 999L;

            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            var ex = Assert.Throws<Exception>(() => multiPartEntityResponse.SendBody(requestHttpMethod, httpResponse, transmitEntityStrategy));
        }
        public void SendBody_HeadRequest_Void()
        {
            //Arrange
            var httpResponse = MockRepository.GenerateMock<HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock<IHttpResponseHeaderHelper>();
            var transmitEntityStrategy = MockRepository.GenerateMock<ITransmitEntityStrategy>();
            var entity = MockRepository.GenerateMock<IEntity>();
            var output = MockRepository.GenerateMock<TextWriter>();
            var requestHttpMethod = HttpMethod.Head;

            var contentType = "image/gif";
            var contentLength = 1000L;

            var firstStartRange = 0L;
            var firstEndRange = 499L;
            var firstBytesToRead = firstEndRange - firstStartRange + 1;
            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange = 999L;
            var secondBytesToRead = secondEndRange - secondStartRange + 1;
            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            var firstHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentType + ": " + contentType + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + firstStartRange + "-" + firstEndRange + "/" + contentLength + "\r\n"
                + "\r\n";

            var secondHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentType + ": " + contentType + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + secondStartRange + "-" + secondEndRange + "/" + contentLength + "\r\n"
                + "\r\n";

            var footer = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "--\r\n";

            transmitEntityStrategy.Stub(x => x.Entity).Return(entity);
            entity.Stub(x => x.ContentType).Return(contentType);
            entity.Stub(x => x.ContentLength).Return(contentLength);
            httpResponse.Stub(x => x.Output).Return(output);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            multiPartEntityResponse.SendBody(requestHttpMethod, httpResponse, transmitEntityStrategy);

            //Assert
            output.AssertWasNotCalled(x => x.Write(firstHeader));
            transmitEntityStrategy.AssertWasNotCalled(x => x.Transmit(httpResponse, firstStartRange, firstBytesToRead));

            output.AssertWasNotCalled(x => x.Write(secondHeader));
            transmitEntityStrategy.AssertWasNotCalled(x => x.Transmit(httpResponse, secondStartRange, secondBytesToRead));

            output.AssertWasNotCalled(x => x.Write(footer));
        }
        public void SendHeaders_EntityCompressionDeflateRequestedCompressionGzip_Void()
        {
            //Arrange
            var httpResponse = MockRepository.GenerateMock<HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock<IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock<IEntity>();
            var responseCompressionType = ResponseCompressionType.GZip;
            var entityCompressionType = ResponseCompressionType.Deflate;

            var firstStartRange = 0L;
            var firstEndRange = 499L;
            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange = 999L;
            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            var ex = Assert.Throws<Exception>(() => multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity));
        }
        public void SendHeaders_EntityCompressionMatchesRequestedCompression_Void()
        {
            //Arrange
            var httpResponse = MockRepository.GenerateMock<HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock<IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock<IEntity>();
            var responseCompressionType = ResponseCompressionType.None;
            var entityLength = 1000L;
            var entityType = "image/gif";
            var entityCompressionType = ResponseCompressionType.None;
            
            var firstStartRange = 0L;
            var firstEndRange = 499L;
            var firstRangeItem = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange = 999L;
            var secondRangeItem = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            var firstHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentType + ": " + entityType + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + firstStartRange + "-" + firstEndRange + "/" + entityLength + "\r\n"
                + "\r\n";

            var secondHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentType + ": " + entityType + "\r\n"
                + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + secondStartRange + "-" + secondEndRange + "/" + entityLength + "\r\n"
                + "\r\n";

            var footer = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "--\r\n";

            var contentLength = firstHeader.Length + firstEndRange - firstStartRange + 1
                + secondHeader.Length + secondEndRange - secondStartRange + 1
                + footer.Length;

            entity.Stub(x => x.ContentType).Return(entityType);
            entity.Stub(x => x.ContentLength).Return(entityLength);
            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            httpResponseHeaderHelper.Expect(x => x.SetContentEncoding(httpResponse, responseCompressionType));
            httpResponseHeaderHelper.Expect(x => x.AppendHeader(httpResponse, EntityResponseMultiPart.HttpHeaderContentLength, contentLength.ToString()));
            httpResponse.Expect(x => x.ContentType = EntityResponseMultiPart.MultipartContenttype);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);
            multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity);

            //Assert
            httpResponseHeaderHelper.VerifyAllExpectations();
            httpResponse.VerifyAllExpectations();
        }
Ejemplo n.º 9
0
        public void SendBody_HeadRequest_Void()
        {
            //Arrange
            var httpResponse             = MockRepository.GenerateMock <HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock <IHttpResponseHeaderHelper>();
            var transmitEntityStrategy   = MockRepository.GenerateMock <ITransmitEntityStrategy>();
            var entity            = MockRepository.GenerateMock <IEntity>();
            var output            = MockRepository.GenerateMock <TextWriter>();
            var requestHttpMethod = HttpMethod.Head;

            var contentType   = "image/gif";
            var contentLength = 1000L;

            var firstStartRange  = 0L;
            var firstEndRange    = 499L;
            var firstBytesToRead = firstEndRange - firstStartRange + 1;
            var firstRangeItem   = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange   = firstEndRange
            };

            var secondStartRange  = 500L;
            var secondEndRange    = 999L;
            var secondBytesToRead = secondEndRange - secondStartRange + 1;
            var secondRangeItem   = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange   = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            var firstHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                              + EntityResponseMultiPart.HttpHeaderContentType + ": " + contentType + "\r\n"
                              + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + firstStartRange + "-" + firstEndRange + "/" + contentLength + "\r\n"
                              + "\r\n";

            var secondHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                               + EntityResponseMultiPart.HttpHeaderContentType + ": " + contentType + "\r\n"
                               + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + secondStartRange + "-" + secondEndRange + "/" + contentLength + "\r\n"
                               + "\r\n";

            var footer = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "--\r\n";

            transmitEntityStrategy.Stub(x => x.Entity).Return(entity);
            entity.Stub(x => x.ContentType).Return(contentType);
            entity.Stub(x => x.ContentLength).Return(contentLength);
            httpResponse.Stub(x => x.Output).Return(output);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);

            multiPartEntityResponse.SendBody(requestHttpMethod, httpResponse, transmitEntityStrategy);

            //Assert
            output.AssertWasNotCalled(x => x.Write(firstHeader));
            transmitEntityStrategy.AssertWasNotCalled(x => x.Transmit(httpResponse, firstStartRange, firstBytesToRead));

            output.AssertWasNotCalled(x => x.Write(secondHeader));
            transmitEntityStrategy.AssertWasNotCalled(x => x.Transmit(httpResponse, secondStartRange, secondBytesToRead));

            output.AssertWasNotCalled(x => x.Write(footer));
        }
Ejemplo n.º 10
0
        public void SendHeaders_EntityCompressionMatchesRequestedCompression_Void()
        {
            //Arrange
            var httpResponse             = MockRepository.GenerateMock <HttpResponseBase>();
            var httpResponseHeaderHelper = MockRepository.GenerateMock <IHttpResponseHeaderHelper>();
            var entity = MockRepository.GenerateMock <IEntity>();
            var responseCompressionType = ResponseCompressionType.None;
            var entityLength            = 1000L;
            var entityType            = "image/gif";
            var entityCompressionType = ResponseCompressionType.None;

            var firstStartRange = 0L;
            var firstEndRange   = 499L;
            var firstRangeItem  = new RangeItem
            {
                StartRange = firstStartRange,
                EndRange   = firstEndRange
            };

            var secondStartRange = 500L;
            var secondEndRange   = 999L;
            var secondRangeItem  = new RangeItem
            {
                StartRange = secondStartRange,
                EndRange   = secondEndRange
            };

            var rangeItems = new[] { firstRangeItem, secondRangeItem };

            var firstHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                              + EntityResponseMultiPart.HttpHeaderContentType + ": " + entityType + "\r\n"
                              + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + firstStartRange + "-" + firstEndRange + "/" + entityLength + "\r\n"
                              + "\r\n";

            var secondHeader = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "\r\n"
                               + EntityResponseMultiPart.HttpHeaderContentType + ": " + entityType + "\r\n"
                               + EntityResponseMultiPart.HttpHeaderContentRange + ": " + EntityResponseMultiPart.Bytes + " " + secondStartRange + "-" + secondEndRange + "/" + entityLength + "\r\n"
                               + "\r\n";

            var footer = "\r\n--" + EntityResponseMultiPart.MultipartBoundary + "--\r\n";

            var contentLength = firstHeader.Length + firstEndRange - firstStartRange + 1
                                + secondHeader.Length + secondEndRange - secondStartRange + 1
                                + footer.Length;

            entity.Stub(x => x.ContentType).Return(entityType);
            entity.Stub(x => x.ContentLength).Return(entityLength);
            entity.Stub(x => x.CompressionType).Return(entityCompressionType);

            httpResponseHeaderHelper.Expect(x => x.SetContentEncoding(httpResponse, responseCompressionType));
            httpResponseHeaderHelper.Expect(x => x.AppendHeader(httpResponse, EntityResponseMultiPart.HttpHeaderContentLength, contentLength.ToString()));
            httpResponse.Expect(x => x.ContentType = EntityResponseMultiPart.MultipartContenttype);

            //Act
            var multiPartEntityResponse = new EntityResponseMultiPart(httpResponseHeaderHelper, rangeItems);

            multiPartEntityResponse.SendHeaders(httpResponse, responseCompressionType, entity);

            //Assert
            httpResponseHeaderHelper.VerifyAllExpectations();
            httpResponse.VerifyAllExpectations();
        }