public async Task <ForecastSearchResponse> DoSearch(int month, int year) { ForecastSearchResponse response = null; // Search by users if (SelectedTabIndex == ForecastOverviewViewSetup.SearchByUserTabIndex) { var requestedUsers = GetUsersToSearchFor().ToList(); response = await _forecastService.GetBySearch(month, year, requestedUsers); if (response != null) { TryAddMissingUsers(month, year, response); } } // Search by registration if (SelectedTabIndex == ForecastOverviewViewSetup.SearchByRegistrationTabIndex) { response = await _forecastService.GetBySearch(month , year , SelectedProjectId , SelectedCompanyId , SelectedForecastTypeId); } return(response); }
protected override object Send(ForecastSearchByUsersRequest request) { var result = new ForecastSearchResponse { ForecastMonths = GetForecasts(request), Holidays = _holidaysByPeriodProvider.GetHolidays(request.ForecastMonth, request.ForecastYear), ProjectForecastTypeId = _domainSettings.ProjectForecastTypeId, }; return(result); }
public void TryAddMissingUsers_ServerReturnsNoResultsForAUser_MissingResponseUsersAreAdded() { // Arrange var forecastServiceMock = CreateMock <IForecastService>(); var userSearchOptionsMock = CreateMock <ForecastOverviewUserSearchOptions>(); var response = new ForecastSearchResponse { ForecastMonths = new List <ForecastMonthDto> { new ForecastMonthDto { UserId = 2 }, new ForecastMonthDto { UserId = 4 }, // Month with userid 3 is intentionally missing } }; var sut = new ForecastOverviewSearchOptions(forecastServiceMock.Object, userSearchOptionsMock.Object) { SelectedUsers = new ObservableCollection <ForecastUserDto> { new ForecastUserDto { UserId = 2 }, new ForecastUserDto { UserId = 3 }, new ForecastUserDto { UserId = 4 }, } }; // Act sut.TryAddMissingUsers(1, 2013, response); // Assert Assert.That(response.ForecastMonths.FirstOrDefault(x => x.UserId == 3), Is.Not.Null); }
/// <summary> /// If user does not have a forecastmonth registration /// the server will not return anytning. /// Generate "dummy" line, so missing registrations are visible /// </summary> /// <param name="month"></param> /// <param name="year"></param> /// <param name="response"></param> public virtual void TryAddMissingUsers(int month, int year, ForecastSearchResponse response) { var responsedUsersIds = response.ForecastMonths.Select(x => x.UserId).ToList(); var requestedUserIds = SelectedUsers.Where(x => !x.IsAllUsers).Select(x => x.UserId).ToList(); var userEmptyResult = requestedUserIds.Where(x => responsedUsersIds.All(y => y != x)); foreach ( var user in userEmptyResult.Select(userId => SelectedUsers.SingleOrDefault(x => x.UserId == userId)) // Select the local user-object .Where(user => user != null)) { response.ForecastMonths.Add(new ForecastMonthDto { UserId = user.UserId, UserName = user.Name, CreatedById = 0, Id = 0, IsLocked = false, Month = month, Year = year, ForecastDtos = new Collection <ForecastDto>() }); } }