public async Task CreateAsync_Failed_Should_Throw_ClamAvException() { IConnectionFactory connectionFactory = new ConnectionFactory(new Uri("tcp://127.0.0.1:12897"), NullLoggerFactory.Instance); ClamAvException ex = await Assert.ThrowsAsync <ClamAvException>(async() => await connectionFactory.CreateAsync().ConfigureAwait(false)).ConfigureAwait(false); ex.InnerException.Should().NotBeNull(); }
public void Ctor_Validation() { ClamAvException clamAvException = new ClamAvException(); clamAvException.Message.Should().NotBeNullOrEmpty(); const string expectedMessage = "Some error"; clamAvException = new ClamAvException(expectedMessage); clamAvException.Message.Should().Be(expectedMessage); clamAvException = new ClamAvException(expectedMessage, new Exception("Error")); clamAvException.Message.Should().Be(expectedMessage); clamAvException.InnerException.Should().NotBeNull(); }
public void Serialization_Test() { const string expectedMessage = "Some error"; ClamAvException clamAvException = new ClamAvException(expectedMessage, new Exception("Error")); BinaryFormatter binaryFormatter = new BinaryFormatter(); using MemoryStream memoryStream = new MemoryStream(); binaryFormatter.Serialize(memoryStream, clamAvException); memoryStream.Seek(0, SeekOrigin.Begin); ClamAvException actual = binaryFormatter.Deserialize(memoryStream) as ClamAvException; actual.Should().NotBeNull(); actual.Should().BeEquivalentTo(clamAvException); }
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()); }