Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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());
        }