コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }