public void WhenKeyProviderThenCreatesUntypedWrapper() { // arrange var message = new SomeMessage(); var messageKey = new byte[] { 1, 2 }; var keyProviderMock = new Mock <Func <SomeMessage, string, byte[]> >(); keyProviderMock.Setup(x => x(message, "topic1")).Returns(messageKey); // act _pb.KeyProvider(keyProviderMock.Object); // assert var keyProvider = _ps.GetKeyProvider(); keyProvider(message, "topic1").Should().BeSameAs(messageKey); keyProviderMock.Verify(x => x(message, "topic1"), Times.Once); }