Пример #1
0
            public void should_produce_arbitrary_count_of_message()
            {
                var processor = new Splitter(
                    m =>
                    {
                        var p = (string)m.Payload;
                        return p
                            .ToCharArray()
                            .Select(c => c.ToString(CultureInfo.InvariantCulture));
                    });

                var message = new Message(
                    "boo".ToMessageLabel(),
                    new Dictionary<string, object> { { "This", "That" } },
                    "Body");

                var result = processor.Apply(message).ToList();

                result.Should().HaveCount(4);
                result.Should().OnlyContain(m => m.Label.Name == "boo");
                result.Should().OnlyContain(m => m.Headers.ContainsKey("This"));
                result.Should().Contain(m => (string)m.Payload == "B");
                result.Should().Contain(m => (string)m.Payload == "o");
                result.Should().Contain(m => (string)m.Payload == "d");
                result.Should().Contain(m => (string)m.Payload == "y");
            }
Пример #2
0
            public void should_process_in_predefined_order()
            {
                var splitter = new Splitter(
                    m =>
                    {
                        var p = (string)m.Payload;
                        return p
                            .ToCharArray()
                            .Select(c => Tuple.Create(c));
                    });
                var filter = new Filter(m => char.IsLetter(((Tuple<char>)m.Payload).Item1));
                var translator = new Translator(m => char.IsLower(((Tuple<char>)m.Payload).Item1) ? "lower" : "upper");
                var router = new ContentBasedRouter(m => ((string)m.Payload + " route").ToMessageLabel());

                var processor = new Pipeline(
                    splitter, filter, translator, router);

                var message = new Message(
                    "boo".ToMessageLabel(),
                    new Dictionary<string, object> { { "This", "That" } },
                    "B1o-d,y");

                var result = processor.Apply(message).ToList();

                result.Should().HaveCount(4);
                result.Should().OnlyContain(m => m.Headers.ContainsKey("This"));

                result[0].Label.Name.Should().Be("upper route");
                result[1].Label.Name.Should().Be("lower route");
                result[2].Label.Name.Should().Be("lower route");
                result[3].Label.Name.Should().Be("lower route");

                result[0].Payload.Should().Be("upper");
                result[1].Payload.Should().Be("lower");
                result[2].Payload.Should().Be("lower");
                result[3].Payload.Should().Be("lower");
            }