public async Task PingAsync_Should_Send_PingCommand() { (Mock <IConnectionFactory> connectionFactoryMock, Mock <IConnection> connectionMock, CancellationToken cancellationToken) = CreateMocks(); ClamAvClient clamAvClient = new ClamAvClient(connectionFactoryMock.Object, new NullLogger <ClamAvClient>()); await clamAvClient.PingAsync(cancellationToken).ConfigureAwait(false); connectionMock.Verify( mock => mock.SendCommandAsync(It.IsAny <PingCommand>(), It.Is <CancellationToken>(ct => ct == cancellationToken)), Times.Once()); clamAvClient.Dispose(); connectionMock.Verify( mock => mock.Dispose(), Times.Once()); }
public async Task PingAsync_Should_Throw_ClamAvException() { (Mock <IConnectionFactory> connectionFactoryMock, Mock <IConnection> connectionMock, CancellationToken cancellationToken) = CreateMocks(); ClamAvException thrownException = new ClamAvException("Some error"); ClamAvClient clamAvClient = new ClamAvClient(connectionFactoryMock.Object, new NullLogger <ClamAvClient>()); connectionMock.Setup( mock => mock.SendCommandAsync(It.IsAny <PingCommand>(), It.Is <CancellationToken>(ct => ct == cancellationToken))).Throws(thrownException); ClamAvException actualException = await Assert.ThrowsAsync <ClamAvException>(async() => await clamAvClient.PingAsync(cancellationToken).ConfigureAwait(false)).ConfigureAwait(false); actualException.Should().BeEquivalentTo(thrownException); clamAvClient.Dispose(); connectionMock.Verify( mock => mock.Dispose(), Times.Once()); }