private void SpecificProviderIsCalled(
            Mock <IGZipStreamProvider> gZipStreamProvider,
            Mock <IDeflateStreamProvider> deflateStreamProvider,
            string compressionMethod)
        {
            var compressionDeterminer = new Mock <ICompressionTypeDeterminer>();
            var logWriter             = new Mock <ILogWriter>();

            compressionDeterminer.Setup(
                a => a.IsCompressedWithEncodingType(
                    It.IsAny <HttpRequest>(),
                    It.Is <string>(a => a.Equals(compressionMethod))))
            .Returns(true);

            var decompressorProvider = new DecompressorProvider(
                compressionDeterminer.Object,
                gZipStreamProvider.Object,
                deflateStreamProvider.Object,
                logWriter.Object
                );

            var request = new HttpRequestMockObjectsProvider().HttpRequest;
            var headers = new Mock <IHeaderDictionary> ();


            headers.Setup(a => a[It.Is <string> (a => a.Equals(CompressionTypeDeterminer.ContentEncodingHeader, StringComparison.InvariantCultureIgnoreCase))])
            .Returns(CompressionTypeDeterminer.ContentEncodingGzip);

            request.Setup(a => a.Headers)
            .Returns(headers.Object);

            decompressorProvider.GetDecompressor(request.Object);
        }
        public void UnknownCompressionMethodThrowsException()
        {
            var compressionDeterminer = new Mock <ICompressionTypeDeterminer>();
            var gZipStreamProvider    = new Mock <IGZipStreamProvider>();
            var deflateStreamProvider = new Mock <IDeflateStreamProvider>();
            var logWriter             = new Mock <ILogWriter>();

            compressionDeterminer.Setup(
                a => a.IsCompressedWithEncodingType(
                    It.IsAny <HttpRequest>(),
                    It.Is <string>(a => a.Equals("blah"))))
            .Returns(true);

            var decompressorProvider = new DecompressorProvider(
                compressionDeterminer.Object,
                gZipStreamProvider.Object,
                deflateStreamProvider.Object,
                logWriter.Object
                );

            var request = new HttpRequestMockObjectsProvider().HttpRequest;
            var headers = new Mock <IHeaderDictionary> ();


            headers.Setup(a => a[It.Is <string> (a => a.Equals(CompressionTypeDeterminer.ContentEncodingHeader, StringComparison.InvariantCultureIgnoreCase))])
            .Returns(CompressionTypeDeterminer.ContentEncodingGzip);

            request.Setup(a => a.Headers)
            .Returns(headers.Object);

            Assert.Throws <Exception>(() => decompressorProvider.GetDecompressor(request.Object));
        }
コード例 #3
0
        public void MissingEncodingHeaderReportedAsUncompressed()
        {
            var request = new HttpRequestMockObjectsProvider().HttpRequest;
            var headers = new Mock <IHeaderDictionary> ();
            var keys    = new Mock <ICollection <string> > ();

            keys.Setup(a => a.Contains(It.Is <string> (a => a.Equals(CompressionTypeDeterminer.ContentEncodingHeader, StringComparison.InvariantCultureIgnoreCase))))
            .Returns(false);

            headers.Setup(a => a.Keys)
            .Returns(keys.Object);

            request.Setup(a => a.Headers)
            .Returns(headers.Object);

            Assert.False(new CompressionTypeDeterminer().IsCompressed(request.Object));
        }
コード例 #4
0
        private bool TestSpecificCompressionMethod(string sampleSpelling, Func <HttpRequest, bool> determinerFn)
        {
            var request = new HttpRequestMockObjectsProvider().HttpRequest;
            var headers = new Mock <IHeaderDictionary> ();
            var keys    = new Mock <ICollection <string> > ();

            keys.Setup(a => a.Contains(It.Is <string> (a => a.Equals(CompressionTypeDeterminer.ContentEncodingHeader, StringComparison.InvariantCultureIgnoreCase))))
            .Returns(true);

            headers.Setup(a => a.Keys)
            .Returns(keys.Object);

            headers.Setup(a => a[It.Is <string> (a => a.Equals(CompressionTypeDeterminer.ContentEncodingHeader, StringComparison.InvariantCultureIgnoreCase))])
            .Returns(sampleSpelling);

            request.Setup(a => a.Headers)
            .Returns(headers.Object);

            return(determinerFn(request.Object));
        }