Esempio n. 1
0
        public void PublishEventsToCertainQueueTestFourTimes()
        {
            var repoMock = new Mock <IRepository>(MockBehavior.Strict);
            var ev       = new SerializedEvent()
            {
                ID = 1337, TimeReceived = DateTime.Now, Body = "test body", EventType = typeof(TestEvent).FullName, RoutingKey = "#"
            };

            repoMock.Setup(repo => repo.FindBy(It.IsAny <Expression <Func <SerializedEvent, bool> > >())).Returns(() => new List <SerializedEvent>()
            {
                ev, ev, ev, ev
            });
            var queueName = "TestQueue2";

            using (var sender = new EventPublisher(_busOptions))
                using (var receiver = new TestDispatcher(_direct, queueName))
                    using (var publisher = new AuditPublisher(_direct))
                        using (var dispatcher = new AuditDispatcher(repoMock.Object, publisher, _busOptions))
                        {
                            var saec = new SendAllEventCommand();
                            saec.returnQueueName = queueName;
                            saec.StartTime       = DateTime.MinValue;
                            saec.EndTime         = DateTime.MaxValue;
                            sender.Publish(saec);

                            Thread.Sleep(1000);

                            Assert.AreEqual(4, receiver.ReceivedTestEventCount);
                        }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            string connectionString = @"server=db;userid=admin;password=1234;database=auditlog;";

            DbContextOptions  options    = new DbContextOptionsBuilder().UseMySQL(connectionString).Options;
            AuditLogDbContext context    = new AuditLogDbContext(options);
            BusOptions        busOptions = new BusOptions(hostname: "rabbitmq", port: 5672, username: "******", password: "******", exchangeName: "Lapiwe.GMS");

            using (IRepository repo = new AuditLogRepository(context))
                using (var all = new AllEventDispatcher(repo, busOptions))
                    using (var publisher = new AuditPublisher(busOptions))
                        using (var dispatcher = new AuditDispatcher(repo, publisher, busOptions))
                        {
                            Console.Read();
                        }
        }