I have the following xUnit test. How should I do in order to mock Func<ClientWebSocket>
with new ClientWebSocket()
using NSubstitute?
Btw, in addition ClientFactory
doesn't want to 100% unit test coverage.
public sealed class WebSocketOptions
{
public Func<ClientWebSocket> ClientFactory { get; set; } = () => new ClientWebSocket();
public int MaxMessageSize { get; set; } = 8192;
}
[Fact]
public void Build_ShouldReturnOptions_WhenAllParametersAreSet()
{
// Arrange
var factory = ClientFactory;
var sut = new WebSocketOptionsBuilder();
var expected = new
{
ClientFactory = factory,
MaxMessageSize = maxMessageSize
};
// Act
var actual = sut
.WithClientFactory(factory)
.WithMaxMessageSize(maxMessageSize)
.Build();
// Assert
actual.Should().BeEquivalentTo(expected);
ClientWebSocket ClientFactory()
{
return new ClientWebSocket();
}