Exemplo n.º 1
0
        public void RepositoryCanFindBy()
        {
            // Arrange
            DbContextOptions          options         = new DbContextOptionsBuilder().UseInMemoryDatabase().Options;
            InMemoryAuditLogDbContext context         = new InMemoryAuditLogDbContext(options);
            SerializedEvent           serializedEvent = new SerializedEvent {
                RoutingKey = "BackendService.RoomCreated", EventType = "RoomCreatedEvent", Body = "{room: 'chess123'}"
            };
            SerializedEvent otherSerializedEvent = new SerializedEvent {
                RoutingKey = "BackendService.RoomCreated", EventType = "RoomCreatedEvent", Body = "{game: 'theultimategame'}"
            };

            using (IRepository repository = new AuditLogRepository(new InMemoryAuditLogDbContext(options)))
            {
                repository.Insert(serializedEvent);
                repository.Insert(otherSerializedEvent);
            }

            // Assert
            using (IRepository repository = new AuditLogRepository(context))
            {
                IEnumerable <SerializedEvent> foundItems = repository.FindBy(s => s.ID == otherSerializedEvent.ID);

                try
                {
                    Assert.AreEqual(1, foundItems.Count());
                    Assert.AreEqual(otherSerializedEvent.ID, foundItems.First().ID);
                }
                finally
                {
                    context.SerializedEvents.RemoveRange(context.SerializedEvents);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
        public void FindByWithNoDomainEventShouldBeCountOf4()
        {
            // Arrange
            using var context = new AuditLogContext(_options);
            var repository = new AuditLogRepository(context);
            var criteria   = new LogEntryCriteria
            {
                FromTimestamp = new DateTime(2019, 2, 2).Ticks,
                ToTimestamp   = new DateTime(2019, 9, 10).Ticks,
            };

            // Act
            var result = repository.FindBy(criteria);

            // Assert
            Assert.AreEqual(4, result.Count());
        }
Exemplo n.º 3
0
        public void FindByWithTimestampsOutOfReachShouldBeCountOf0()
        {
            // Arrange
            using var context = new AuditLogContext(_options);
            var repository = new AuditLogRepository(context);
            var criteria   = new LogEntryCriteria
            {
                EventType     = "DomainEvent",
                FromTimestamp = new DateTime(2019, 6, 7).Ticks,
                ToTimestamp   = new DateTime(2019, 6, 10).Ticks,
            };

            // Act
            var result = repository.FindBy(criteria);

            // Assert
            Assert.AreEqual(0, result.Count());
        }
Exemplo n.º 4
0
        public void FindByIsInstanceOfIEnumerableOfLogEntry()
        {
            // Arrange
            using var context = new AuditLogContext(_options);
            var repository = new AuditLogRepository(context);
            var criteria   = new LogEntryCriteria
            {
                EventType     = "DomainEvent",
                FromTimestamp = new DateTime(2019, 7, 1).Ticks,
                ToTimestamp   = new DateTime(2019, 7, 3).Ticks,
            };

            // Act
            var result = repository.FindBy(criteria);

            // Assert
            Assert.IsInstanceOfType(result, typeof(IEnumerable <LogEntry>));
        }