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); }
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); }
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()); } }
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); } } }
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()); } }
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)); }
public RawMessage OnProduce(RawMessage rawMessage) { return interceptors.AsEnumerable() .Aggregate(rawMessage, (x, y) => y.OnProduce(x)); }
public RawMessage OnConsume(RawMessage rawMessage) { return interceptors.AsEnumerable() .Reverse() .Aggregate(rawMessage, (x, y) => y.OnConsume(x)); }