示例#1
0
        public async Task ChangePasswordAsync_Throws_InvalidOperationException_If_Not_Logged_In(SoulseekClientStates state)
        {
            using (var s = new SoulseekClient())
            {
                s.SetProperty("State", state);

                var ex = await Record.ExceptionAsync(() => s.ChangePasswordAsync("a"));

                Assert.NotNull(ex);
                Assert.IsType <InvalidOperationException>(ex);
            }
        }
示例#2
0
        public async Task ChangePasswordAsync_Throws_ArgumentException_On_Null_Username(string password)
        {
            using (var s = new SoulseekClient())
            {
                s.SetProperty("State", SoulseekClientStates.Connected | SoulseekClientStates.LoggedIn);

                var ex = await Record.ExceptionAsync(() => s.ChangePasswordAsync(password));

                Assert.NotNull(ex);
                Assert.IsType <ArgumentException>(ex);
            }
        }
示例#3
0
        public async Task ChangePasswordAsync_Uses_Given_CancellationToken(string password, CancellationToken cancellationToken)
        {
            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait <string>(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(password));

            var serverConn = new Mock <IMessageConnection>();

            serverConn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

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

                await s.ChangePasswordAsync(password, cancellationToken);
            }

            serverConn.Verify(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), cancellationToken), Times.Once);
        }
示例#4
0
        public async Task ChangePasswordAsync_Succeeds_On_Matching_Confirmation(string password)
        {
            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait <string>(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(password));

            var serverConn = new Mock <IMessageConnection>();

            serverConn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

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

                var ex = await Record.ExceptionAsync(() => s.ChangePasswordAsync(password));

                Assert.Null(ex);
            }
        }
示例#5
0
        public async Task ChangePasswordAsync_Throws_OperationCanceledException_On_Cancel(string password)
        {
            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait <string>(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(password));

            var serverConn = new Mock <IMessageConnection>();

            serverConn.Setup(m => m.WriteAsync(It.IsAny <byte[]>(), It.IsAny <CancellationToken>()))
            .Throws(new OperationCanceledException());

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

                var ex = await Record.ExceptionAsync(() => s.ChangePasswordAsync(password));

                Assert.NotNull(ex);
                Assert.IsType <OperationCanceledException>(ex);
            }
        }
示例#6
0
        public async Task ChangePasswordAsync_Throws_On_Mismatching_Confirmation(string password)
        {
            var waiter = new Mock <IWaiter>();

            waiter.Setup(m => m.Wait <string>(It.IsAny <WaitKey>(), null, It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(password + "!"));

            var serverConn = new Mock <IMessageConnection>();

            serverConn.Setup(m => m.WriteAsync(It.IsAny <IOutgoingMessage>(), It.IsAny <CancellationToken>()))
            .Returns(Task.CompletedTask);

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

                var ex = await Record.ExceptionAsync(() => s.ChangePasswordAsync(password));

                Assert.NotNull(ex);
                Assert.IsType <SoulseekClientException>(ex);
                Assert.True(ex.Message.ContainsInsensitive("doesn't match the specified password"));
            }
        }