Ejemplo n.º 1
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.º 2
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 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.º 6
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();
        }