Exemplo n.º 1
0
        public void CommandLoggingInterceptorTestForNoLogging()
        {
            var commandLoggingInterceptor = new CustomCommandLoggingInterceptor(
                _logFactory,
                new Dictionary <Type, CommandLoggingDelegate>
            {
                { typeof(int), null }
            });
            var commandsHandler = new CommandsHandler();

            using (var messagingEngine = new MessagingEngine(
                       _logFactory,
                       new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "InMemory", new TransportInfo("none", "none", "none", null) }
            })))
            {
                using (var engine = new CqrsEngine(
                           _logFactory,
                           messagingEngine,
                           Register.DefaultEndpointResolver(new InMemoryEndpointResolver()),
                           Register.CommandInterceptors(commandLoggingInterceptor),
                           Register.BoundedContext("test1")
                           .ListeningCommands(typeof(int)).On("lykke-wallet-events")
                           .WithCommandsHandler(commandsHandler)))
                {
                    engine.StartSubscribers();
                    using (var writer = new StringWriter())
                    {
                        var prevOut = Console.Out;
                        Console.SetOut(writer);
                        messagingEngine.Send(1, new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json));
                        Thread.Sleep(1000);
                        Console.SetOut(prevOut);

                        var output = writer.ToString();
                        Assert.True(output.IsNullOrEmpty(), "Command was logged");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void CommandLoggingInterceptorTest()
        {
            int commandLoggedCount        = 0;
            var commandLoggingInterceptor = new CustomCommandLoggingInterceptor(
                _logFactory,
                new Dictionary <Type, CommandLoggingDelegate>
            {
                { typeof(int), (l, h, c) => ++ commandLoggedCount }
            });
            var commandsHandler = new CommandsHandler();

            using (var messagingEngine = new MessagingEngine(
                       _logFactory,
                       new TransportResolver(new Dictionary <string, TransportInfo>
            {
                { "InMemory", new TransportInfo("none", "none", "none", null) }
            })))
            {
                using (var engine = new CqrsEngine(
                           _logFactory,
                           messagingEngine,
                           Register.DefaultEndpointResolver(new InMemoryEndpointResolver()),
                           Register.CommandInterceptors(commandLoggingInterceptor),
                           Register.BoundedContext("test1")
                           .ListeningCommands(typeof(int)).On("lykke-wallet-events")
                           .WithCommandsHandler(commandsHandler)))
                {
                    engine.StartSubscribers();
                    messagingEngine.Send(1, new Endpoint("InMemory", "lykke-wallet-events", serializationFormat: SerializationFormat.Json));
                    Thread.Sleep(1000);

                    Assert.True(commandLoggedCount > 0, "Command was not logged");
                    Assert.True(commandLoggedCount == 1, "Command was logged more than once");
                }
            }
        }