public async Task CheckStatisticsReturnsTradedAssetAndAssetTwoNames() { Dictionary <string, string> queryParams = new Dictionary <string, string>() { { "algoId", postInstanceData.AlgoId }, { "instanceId", postInstanceData.InstanceId } }; var instanceDataResponse = await Consumer.ExecuteRequest(algoInstanceDataPath, queryParams, null, Method.GET); Assert.That(instanceDataResponse.Status, Is.EqualTo(HttpStatusCode.OK)); // Wait up to 3 minutes for the algo to be started await AlgoStoreCommonSteps.WaitAlgoToStart(ClientInstanceRepository, postInstanceData); StatisticsDTO statistics = await AlgoStoreCommonSteps.GetStatisticsResponseAsync(Consumer, postInstanceData); // TODO: Update the test to use dynamic TradedAsset and AssetTwo // Assert statistics endpoint returns "TradedAssetName" and "AssetTwoName" Assert.That(statistics.TradedAssetName, Is.EqualTo("EUR")); Assert.That(statistics.AssetTwoName, Is.EqualTo("BTC")); // Stop the algo instance await AlgoStoreCommonSteps.StopAlgoInstance(Consumer, postInstanceData); }
/// <summary> /// Edits user with the specified ID. /// </summary> /// <param name="id">ID of the user which will be edited.</param> /// <param name="user">User data which will be applied.</param> /// <param name="statistics">DTO containing statistics which will be updated during work of this method.</param> /// <returns>True if user with the specified ID has been found and edited, otherwise false.</returns> public bool EditUser(int id, UserDTO user, StatisticsDTO statistics) { var userToEdit = _userRepository.GetById(id); statistics.SelectsTime += _userRepository.LastOperationTime; statistics.SelectsCount++; if (userToEdit == null) { return(false); } userToEdit.UserName = user.Login; userToEdit.Name = user.Name; userToEdit.Surname = user.Surname; userToEdit.EMail = user.EMail; if (user.Password != null) { userToEdit.Password = _authService.HashPassword(user.Password); } userToEdit.Money = user.Value; _userRepository.Edit(userToEdit); statistics.UpdatesTime += _userRepository.LastOperationTime; statistics.UpdatesCount++; return(true); }
/// <summary> /// Method that returns Collection of Transaction DTOs /// </summary> /// <param name="statistics">Statistics DTO</param> /// <returns>Collection of Transaction DTOs</returns> public ICollection <TransactionDTO> GetAll(StatisticsDTO statistics) { var transaction = _transactionRepository.GetAll().Select(t => Mapper.Map <TransactionDTO>(t)).ToList(); statistics.SelectsTime += _transactionRepository.LastOperationTime; statistics.SelectsCount++; return(transaction); }
/// <summary> /// Retrieves all users from the database. /// </summary> /// <param name="statistics">DTO containing statistics which will be updated during work of this method.</param> /// <returns>Collection of retrieved users from the database.</returns> public ICollection <UserDTO> GetAllUsers(StatisticsDTO statistics) { var users = _userRepository.GetAll().Select(p => Mapper.Map <UserDTO>(p)).ToList(); statistics.SelectsTime += _userRepository.LastOperationTime; statistics.SelectsCount++; return(users); }
/// <summary> /// Adds user passed in the parameter to the database. /// </summary> /// <param name="user">User DTO which will be added to the database.</param> /// <param name="statistics">DTO containing statistics which will be updated during work of this method.</param> public void AddUser(UserDTO user, StatisticsDTO statistics) { var mappedUser = Mapper.Map <User>(user); mappedUser.Password = _authService.HashPassword(user.Password); _userRepository.Add(Mapper.Map <User>(mappedUser)); statistics.InsertsTime += _userRepository.LastOperationTime; statistics.InsertsCount++; }
public StatisticsDTO UsersStatistics() { var allUsers = this.unitOfWork.UsersRepository.All().Select(user => new { Id = user.Id, UserName = user.UserName, IsDeleted = user.IsDeleted }).ToList(); var allUsersTweeters = this.unitOfWork.UsersTweeterRepository.All().Select(userTweeter => new { UserName = userTweeter.User.UserName, IsDeleted = userTweeter.IsDeleted }).ToList(); var allUserTweets = this.unitOfWork.UsersTweetRepository.All().Select(userTweet => new { UserName = userTweet.User.UserName, IsDeleted = userTweet.IsDeleted }).ToList(); Dictionary <string, UserStatisticsDTO> userStatisticsDTOs = new Dictionary <string, UserStatisticsDTO>(); OverallStatisticsDTO overallStatisticsDTO = new OverallStatisticsDTO(); foreach (var user in allUsers) { userStatisticsDTOs[user.UserName] = new UserStatisticsDTO { UserName = user.UserName, Id = user.Id, Status = (user.IsDeleted == true) ? "Deleted" : "Active" }; } foreach (var dto in userStatisticsDTOs) { dto.Value.StoredTweetsCount = allUserTweets.Count(ut => ut.UserName == dto.Key && !ut.IsDeleted); dto.Value.DeletedTweetsCount = allUserTweets.Count(ut => ut.UserName == dto.Key && ut.IsDeleted); dto.Value.FavouriteTweetersCount = allUsersTweeters.Count(ut => ut.UserName == dto.Key && !ut.IsDeleted); dto.Value.DeletedFavouriteTweetersCount = allUsersTweeters.Count(ut => ut.UserName == dto.Key && ut.IsDeleted); overallStatisticsDTO.TotalFavouriteTweetersCount += dto.Value.FavouriteTweetersCount; overallStatisticsDTO.TotalFavouriteTweetersCount += dto.Value.DeletedFavouriteTweetersCount; overallStatisticsDTO.TotalStoredTweetsCount += dto.Value.StoredTweetsCount; overallStatisticsDTO.TotalStoredTweetsCount += dto.Value.DeletedTweetsCount; } StatisticsDTO statisticsDTO = new StatisticsDTO() { UserStatisticsDTOs = userStatisticsDTOs.Values, OverallStatisticsDTO = overallStatisticsDTO }; return(statisticsDTO); }