예제 #1
0
 public void ShouldEncryptAndDecrypt()
 {
     var tripleDESInterceptor = new TripleDESInterceptor(Convert.FromBase64String("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), Convert.FromBase64String("aaaaaaaaaaa="));
     var body = Encoding.UTF8.GetBytes("haha");
     var rawMessage = new RawMessage(new MessageProperties(), body);
     Assert.AreEqual(body, tripleDESInterceptor.OnConsume(tripleDESInterceptor.OnProduce(rawMessage)).Body);
 }
예제 #2
0
 public void ShouldCompressAndDecompress()
 {
     var gZipInterceptor = new GZipInterceptor();
     var body = Encoding.UTF8.GetBytes("haha");
     var rawMessage = new RawMessage(new MessageProperties(), body);
     Assert.AreEqual(body, gZipInterceptor.OnConsume(gZipInterceptor.OnProduce(rawMessage)).Body);
 }
예제 #3
0
 public RawMessage OnProduce(RawMessage rawMessage)
 {
     var properties = rawMessage.Properties;
     var body = rawMessage.Body;
     using (var output = new MemoryStream())
     {
         using (var compressingStream = new GZipStream(output, CompressionMode.Compress))
             compressingStream.Write(body, 0, body.Length);
         return new RawMessage(properties, output.ToArray());
     }
 }
예제 #4
0
 public RawMessage OnConsume(RawMessage rawMessage)
 {
     var properties = rawMessage.Properties;
     var body = rawMessage.Body;
     using (var tripleDes = TripleDES.Create())
     {
         using (var tripleDesDecryptor = tripleDes.CreateDecryptor(key, iv))
         {
             var decryptedBody = tripleDesDecryptor.TransformFinalBlock(body, 0, body.Length);
             return new RawMessage(properties, decryptedBody);
         }
     }
 }
예제 #5
0
 public RawMessage OnConsume(RawMessage rawMessage)
 {
     var properties = rawMessage.Properties;
     var body = rawMessage.Body;
     using (var output = new MemoryStream())
     {
         using (var compressedStream = new MemoryStream(body))
         {
             using (var decompressingStream = new GZipStream(compressedStream, CompressionMode.Decompress))
                 decompressingStream.CopyTo(output);
         }
         return new RawMessage(properties, output.ToArray());
     }
 }
예제 #6
0
        public void ShouldCallAddedInterceptorsOnProduce()
        {
            var sourceMessage = new RawMessage(new MessageProperties(), new byte[0]);
            var firstMessage = new RawMessage(new MessageProperties(), new byte[0]);
            var secondMessage = new RawMessage(new MessageProperties(), new byte[0]);
            
            var first = NewMock<IProduceConsumeInterceptor>();
            var second = NewMock<IProduceConsumeInterceptor>();
            first.Expect(x => x.OnProduce(sourceMessage)).Return(firstMessage);
            second.Expect(x => x.OnProduce(firstMessage)).Return(secondMessage);

            var compositeInterceptor = new CompositeInterceptor();
            compositeInterceptor.Add(first);
            compositeInterceptor.Add(second);
            Assert.AreEqual(secondMessage, compositeInterceptor.OnProduce(sourceMessage));
        }
예제 #7
0
 public RawMessage OnProduce(RawMessage rawMessage)
 {
     return interceptors.AsEnumerable()
                        .Aggregate(rawMessage, (x, y) => y.OnProduce(x));
 }
예제 #8
0
 public RawMessage OnConsume(RawMessage rawMessage)
 {
     return interceptors.AsEnumerable()
                        .Reverse()
                        .Aggregate(rawMessage, (x, y) => y.OnConsume(x));
 }