public async Task AddPrivateRoomMemberAsync_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.AddPrivateRoomMemberAsync(roomName, username)); Assert.NotNull(ex); Assert.Equal(expectedEx, ex); } }
public async Task AddPrivateRoomMemberAsync_Throws_InvalidOperationException_When_Not_Connected() { using (var s = new SoulseekClient()) { var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomMemberAsync("room", "user")); Assert.NotNull(ex); Assert.IsType <InvalidOperationException>(ex); } }
public async Task AddPrivateRoomMemberAsync_Throws_ArgumentException_Given_Bad_Username(string username) { using (var s = new SoulseekClient()) { var ex = await Record.ExceptionAsync(() => s.AddPrivateRoomMemberAsync("room", username)); Assert.NotNull(ex); Assert.IsType <ArgumentException>(ex); Assert.Equal("username", ((ArgumentException)ex).ParamName); } }
public async Task AddPrivateRoomMemberAsync_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.AddPrivateRoomMemberAsync(roomName, username, CancellationToken.None)); Assert.NotNull(ex); Assert.IsType <OperationCanceledException>(ex); } }