public async Task DeleteUser() { var user = fillTestDbHelper.Users.FirstOrDefault(); await deleteUsersService.DeleteUserAsync(user.Id); Assert.Null(await loadUsersService.GetUserAsync(user.Id)); }
public async Task <Response> CreateResponseAsync() { try { if (await verificationCodesService.IsVerificationCodeValidAsync(clientConnection.UserId.GetValueOrDefault().ToString(), clientConnection.UserId, request.VCode).ConfigureAwait(false)) { await deleteUsersService.DeleteUserAsync(clientConnection.UserId.GetValueOrDefault()).ConfigureAwait(false); nodeNoticeService.SendDeleteUsersNodeNoticeAsync(clientConnection.UserId.GetValueOrDefault()); BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateDeleteUserSegmentAsync( clientConnection.UserId.GetValueOrDefault(), new List <long> { NodeSettings.Configs.Node.Id }, NodeSettings.Configs.Node.Id).ConfigureAwait(false); BlockGenerationHelper.Instance.AddSegment(segment); Task disconnectTask = new Task(async() => { try { List <ClientConnection> clientConnections = connectionsService .GetClientConnections(new List <long> { clientConnection.UserId.Value }) .Where(connection => connection != clientConnection) .ToList(); foreach (var connection in clientConnections) { await connection.ClientSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "User deleted.", CancellationToken.None).ConfigureAwait(false); } await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false); await clientConnection.ClientSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "User deleted.", CancellationToken.None).ConfigureAwait(false); } catch { return; } }); disconnectTask.Start(); return(new ResultResponse(request.RequestId)); } return(new ResultResponse(request.RequestId, null, ObjectsLibrary.Enums.ErrorCode.WrongVerificationCode)); } catch (Exception ex) { Logger.WriteLog(ex, request); return(new ResultResponse(request.RequestId, "Can't delete user.", ObjectsLibrary.Enums.ErrorCode.DeleteUserProblem)); } }