public void WithCompressionSizeThreshold_AnyValidLong_ReturnsSame()
        {
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithCompressionSizeThreshold(1000);

            Assert.AreSame(subject, result);
        }
        public void WithAlwaysCompress_AnyValidBool_ReturnsSame()
        {
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithAlwaysCompress(true);

            Assert.AreSame(subject, result);
        }
 public CompressingClientConfiguration(CompressingClientConfiguration other)
 {
     this.CompressionProvider      = other.CompressionProvider;
     this.CompressionSizeThreshold = other.CompressionSizeThreshold;
     this.AlwaysCompress           = other.AlwaysCompress;
     this.MessageParser            = other.MessageParser;
 }
        public void Initialize_ObjectFromEmptyCtorAndObjectFromOther_AreEquivalent()
        {
            var subject = new CompressingClientConfiguration();
            var result  = new CompressingClientConfiguration(subject);

            Assert.AreEqual(subject.ToJson(), result.ToJson());
        }
        public void WithCompressionLevel_AnyValidCompressionLevel_ReturnsSame()
        {
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithCompressionLevel(CompressionLevel.High);

            Assert.AreEqual(subject, result);
        }
        public void WithAlwaysCompress_False_MessageParserIsInstanceOfDefaultMessageParser()
        {
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithAlwaysCompress(false)
                          .MessageParser;

            Assert.IsInstanceOf <DefaultMessageParser>(result);
        }
        public void WithAlwaysCompress_True_MessageParserIsInstanceOfImplicitCompressionMessageParser()
        {
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithAlwaysCompress(true)
                          .MessageParser;

            Assert.IsInstanceOf <ImplicitCompressionMessageParser>(result);
        }
        public void WithCompressionLevel_AnyValidCompressionLevel_SetsCompressionLevel()
        {
            var value   = CompressionLevel.High;
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithCompressionLevel(value).CompressionLevel;

            Assert.AreEqual(value, result);
        }
        public void WithAlwaysCompress_AnyValidBool_SetsAlwaysCompress()
        {
            var value   = true;
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithAlwaysCompress(value)
                          .AlwaysCompress;

            Assert.AreEqual(value, result);
        }
        public void WithCompressionSizeThreshold_AnyValidLong_SetsCompressionSizeThreshold()
        {
            var value   = 1000;
            var subject = new CompressingClientConfiguration();
            var result  = subject.WithCompressionSizeThreshold(value)
                          .CompressionSizeThreshold;

            Assert.AreEqual(value, result);
        }
        public void ToResponseBody_JsonValueWithCompressionMarkerZero_ReturnsValue()
        {
            var config  = new CompressingClientConfiguration();
            var value   = (new { Id = Guid.NewGuid(), Value = new Sentence() }).ToJson();
            var subject = new MessageService(config);

            var result = subject.ToResponseBody($"0|{value}");

            Assert.AreEqual(value, result);
        }
        public void ToResponseBody_MultilineValueWithCompressionMarkerZero_ReturnsValue()
        {
            var config  = new CompressingClientConfiguration();
            var value   = $"{new Sentence()}\r\n{new Sentence()}";
            var subject = new MessageService(config);

            var result = subject.ToResponseBody($"0|{value}");

            Assert.AreEqual(value, result);
        }
        public void ToResponseBody_WithAlwaysCompressAndInvalidValue_ThrowsFormatException()
        {
            var config  = new CompressingClientConfiguration().WithAlwaysCompress(true);
            var value   = (string)new Sentence();
            var subject = new MessageService(config);

            Assert.Throws <FormatException>(() =>
            {
                var result = subject.ToResponseBody(value);
            });
        }
        public void ToResponseBody_AnyCompressedValueAsBase64WithCompressionMarkerOne_ReturnsDecompressedValue()
        {
            var config          = new CompressingClientConfiguration();
            var value           = (string)new Sentence();
            var compressedValue = Convert.ToBase64String(new CompressionProvider().Compress(value));
            var subject         = new MessageService(config);

            var result = subject.ToResponseBody($"1|{compressedValue}");

            Assert.AreEqual(value, result);
        }
        public void ToResponseBody_AnyValueWithCompressionMarkerOne_ThrowsFormatException()
        {
            var config  = new CompressingClientConfiguration();
            var value   = (string)new Sentence();
            var subject = new MessageService(config);

            Assert.Throws <FormatException>(() =>
            {
                var result = subject.ToResponseBody($"1|{value}");
            });
        }
        public void ToResponseBody_NullValue_ThrowsFormatException()
        {
            var config  = new CompressingClientConfiguration();
            var value   = null as string;
            var subject = new MessageService(config);

            Assert.Throws <FormatException>(() =>
            {
                var result = subject.ToResponseBody(value);
            });
        }
        public void ToResponseBody_AnyValueAsBase4WithCompressionMarkerOne_ThrowsGZipException()
        {
            var config  = new CompressingClientConfiguration();
            var value   = Convert.ToBase64String(Encoding.UTF8.GetBytes(new Sentence()));
            var subject = new MessageService(config);

            Assert.Throws <GZipException>(() =>
            {
                var result = subject.ToResponseBody($"1|{value}");
            });
        }
        public void ToResponseBody_AnyCompressedValueAsBase64WithoutCompressionMarker_ThrowsFormatException()
        {
            var config          = new CompressingClientConfiguration();
            var value           = (string)new Sentence();
            var compressedValue = Convert.ToBase64String(new CompressionProvider().Compress(value));
            var subject         = new MessageService(config);

            Assert.Throws <FormatException>(() =>
            {
                var result = subject.ToResponseBody(compressedValue);
            });
        }