Exemplo n.º 1
0
        public async Task AddPrivateRoomModeratorAsync_Throws_When_Wait_Throws(string roomName, string username)
        {
            var conn = new Mock <IMessageConnection>();

            conn.Setup(m => m.State)
            .Returns(ConnectionState.Connected);
            conn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

            var expectedEx = new TimeoutException();

            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromException(expectedEx));

            using (var s = new SoulseekClient(serverConnection: conn.Object, waiter: waiter.Object))
            {
                s.SetProperty("State", SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn);

                var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomModeratorAsync(roomName, username));

                Assert.NotNull(ex);
                Assert.Equal(expectedEx, ex);
            }
        }
Exemplo n.º 2
0
        public async Task AddPrivateRoomModeratorAsync_Throws_InvalidOperationException_When_Not_Connected()
        {
            using (var s = new SoulseekClient())
            {
                var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomModeratorAsync("room", "user"));

                Assert.NotNull(ex);
                Assert.IsType <InvalidOperationException>(ex);
            }
        }
Exemplo n.º 3
0
        public async Task AddPrivateRoomModeratorAsync_Throws_ArgumentException_Given_Bad_Username(string username)
        {
            using (var s = new SoulseekClient())
            {
                var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomModeratorAsync("room", username));

                Assert.NotNull(ex);
                Assert.IsType <ArgumentException>(ex);
                Assert.Equal("username", ((ArgumentException)ex).ParamName);
            }
        }
Exemplo n.º 4
0
        public async Task AddPrivateRoomModeratorAsync_Throws_OperationCanceledException_When_Write_Is_Canceled(string roomName, string username)
        {
            var conn = new Mock <IMessageConnection>();

            conn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken>()))
            .Throws(new OperationCanceledException());

            using (var s = new SoulseekClient(serverConnection: conn.Object))
            {
                s.SetProperty("State", SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn);

                var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomModeratorAsync(roomName, username, CancellationToken.None));

                Assert.NotNull(ex);
                Assert.IsType <OperationCanceledException>(ex);
            }
        }