public async Task FetchUnprocessedAsync_should_return_unprocessed_messages_only() { var batchSize = 6; var publisher = Substitute.For <IMessagePublisher>(); var messages = Enumerable.Repeat(1, batchSize) .Select(CreateFakeMessage) .ToArray(); int index = 0; foreach (var message in messages) { if (0 == (index++ % 2)) { await message.Process(publisher, CancellationToken.None); } } await using var dbContext = _fixture.BuildDbContext(); dbContext.Messages.AddRange(messages); await dbContext.SaveChangesAsync(); var sut = new MessagesRepository(dbContext); var results = await sut.FetchUnprocessedAsync(batchSize, CancellationToken.None); results.Should().NotBeNullOrEmpty() .And.HaveCount(3); }