public async Task TestConsumer_ConsumerGroupCommitAsync() { var mocks = InitCluster(); mocks.Group.SetupGet(g => g.Configuration) .Returns(new ConsumerGroupConfiguration { AutoCommitEveryMs = -1, SessionTimeoutMs = 10 }); var consumer = new ConsumeRouter(mocks.Cluster.Object, new Configuration { TaskScheduler = new CurrentThreadTaskScheduler(), ConsumeBatchSize = 1 }, 1); consumer.StartConsumeSubscription(mocks.Group.Object, new[] { "the topic" }); await consumer.CommitAsync("the topic", 1, 42); mocks.Group.Verify(g => g.Commit(It.Is <IEnumerable <TopicData <OffsetCommitPartitionData> > >(l => l.Count() == 1 && l.First().TopicName == "the topic" && l.First().PartitionsData.Count() == 1 && l.First().PartitionsData.First().Partition == 1 && l.First().PartitionsData.First().Metadata == "" && l.First().PartitionsData.First().Offset == 42)), // Offset saved should be next expected offset Times.Once); mocks.Group.Setup(g => g.Commit(It.IsAny <IEnumerable <TopicData <OffsetCommitPartitionData> > >())) .ThrowsAsync(new InvalidOperationException()); // NUnit 3 (used for .Net Core build) requires to use ThrowsAsync which doesn't exist in 2.6 Assert.Throws <InvalidOperationException>(consumer.CommitAsync("the topic", 1, 42).GetAwaiter().GetResult); }