Example #1
0
        public async Task Dispose_IsNotDisposed_StopOperationAsync()
        {
            // arrange
            var    managerMock = new Mock <ISession>(MockBehavior.Strict);
            string id          = "123";

            managerMock
            .Setup(x => x.StopOperationAsync(id, It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);
            ISession manager   = managerMock.Object;
            var      operation = new SocketOperation(manager, id);

            // act
            await operation.DisposeAsync();

            // assert
            managerMock.VerifyAll();
        }
Example #2
0
        public async Task ReadAsync_IsDisposed_Return()
        {
            // arrange
            ISession manager   = new Mock <ISession>().Object;
            string   id        = "123";
            var      operation = new SocketOperation(manager, id);
            await operation.DisposeAsync();

            List <OperationMessage> messages = new();

            // act
            await foreach (var elm in operation.ReadAsync(CancellationToken.None))
            {
                messages.Push(elm);
            }

            // assert
            Assert.Empty(messages);
        }
Example #3
0
        public async Task ReadAsync_IsDisposedDuringReceiving_Return()
        {
            // arrange
            ISession manager   = new Mock <ISession>().Object;
            string   id        = "123";
            var      operation = new SocketOperation(manager, id);
            List <OperationMessage> messages = new();

            // act
            await operation.ReceiveMessageAsync(
                ErrorOperationMessage.ConnectionInitializationError,
                CancellationToken.None);

            await foreach (var elm in operation.ReadAsync(CancellationToken.None))
            {
                messages.Push(elm);
                await operation.DisposeAsync();
            }

            // assert
            Assert.Single(messages);
        }