Beispiel #1
0
        public void DispatcherTest()
        {
            using (var eventSender = new EventPublisher(_config))
                using (FoutLoggingContext context = new FoutLoggingContext(_options))
                    using (CustomExceptionRepository repo = new CustomExceptionRepository(context))
                        using (FoutLoggingDispatcher dispatcher = new FoutLoggingDispatcher(_config, repo))
                        {
                            var myException = new ExceptionThrownEvent()
                            {
                                ExceptionType = typeof(ArgumentException),
                                GUID          = Guid.NewGuid().ToString(),
                                Message       = "Dit is een TestException",
                                TimeStamp     = DateTime.Now,
                                RoutingKey    = "jomaya.exception.Test"
                            };

                            eventSender.Publish(myException);

                            Thread.Sleep(3000);

                            Assert.IsTrue(context.Exceptions.Count(c => c.ExceptionType == typeof(ArgumentException).ToString()) > 0);

                            var result = context.Exceptions.First(c => c.ExceptionType == typeof(ArgumentException).ToString());

                            Assert.AreEqual("Dit is een TestException", result.Message);
                        }
        }
Beispiel #2
0
        public void TestCommonExceptionPublisher()
        {
            var errorMessage = "Dit is een TestException";

            var myException = new ArgumentException(errorMessage);

            using (FoutLoggingContext context = new FoutLoggingContext(_options))
                using (CustomExceptionRepository repo = new CustomExceptionRepository(context))
                    using (FoutLoggingDispatcher dispatcher = new FoutLoggingDispatcher(_config, repo))
                    {
                        ExceptionEventPublisher.PublishException(myException, false);

                        Thread.Sleep(10000);

                        Assert.IsTrue(context.Exceptions.Count(c => c.ExceptionType == typeof(ArgumentException).ToString()) > 0);

                        var result = context.Exceptions.First(c => c.ExceptionType == typeof(ArgumentException).ToString());

                        Assert.AreEqual("Dit is een TestException", result.Message);
                    }
        }
Beispiel #3
0
        private static void initializeEventDispatcher()
        {
            string sqlConnectionString = "server=db;userid=jomaya;password=jomaya;database=jomaya-foutlogging;";

            var optionsBuilder = new DbContextOptionsBuilder <FoutLoggingContext>();

            optionsBuilder.UseMySQL(sqlConnectionString);
            _context = new FoutLoggingContext(optionsBuilder.Options);
            _repo    = new CustomExceptionRepository(_context);

            var config = new EventBusConfig()
            {
                Host      = "rabbitmq",
                Port      = 5672,
                QueueName = "jomaya.foutlogging.queue"
            };

            var publisher = new EventPublisher(config);

            _dispatcher = new FoutLoggingDispatcher(config, _repo);
        }