public void FilterUsersByNamesQuery_ShouldBuildPredicate() { const string fullName = "x y z"; IList <ApplicationUser> users = new List <ApplicationUser> { new ApplicationUser { Id = "1", FirstName = "x", LastName = "x" }, new ApplicationUser { Id = "2", FirstName = "y", LastName = "y" }, new ApplicationUser { Id = "3", FirstName = "z", LastName = "z" }, new ApplicationUser { Id = "4", FirstName = "x", LastName = "y" }, new ApplicationUser { Id = "5", FirstName = "x", LastName = "z" }, new ApplicationUser { Id = "6", FirstName = "y", LastName = "x" }, new ApplicationUser { Id = "7", FirstName = "y", LastName = "z" }, new ApplicationUser { Id = "8", FirstName = "z", LastName = "x" }, new ApplicationUser { Id = "9", FirstName = "z", LastName = "y" }, new ApplicationUser { Id = "10", FirstName = "Real", LastName = "Name" } }; var filter = _vacationDomainService.UsersByNamesFilter(fullName); var result = users.Where(filter.Compile()).ToList(); Assert.That(result.Count(), Is.EqualTo(9)); }
public async Task <VacationImportStatusDto> UploadVacationReportFileAsync(Stream fileStream) { var excelReader = ExcelReaderFactory.CreateBinaryReader(fileStream); var sheets = GetWorksheetNames(excelReader); var workSheet = GetWorksheetData(excelReader, sheets.First()); var importStatus = new VacationImportStatusDto { Imported = new List <VacationImportEntryDto>(), Skipped = new List <VacationImportEntryDto>() }; foreach (var row in workSheet) { var acceptableData = row[CodeColIndex] is string && row[FullnameColIndex] is string && row[OperationColIndex] is string && row[OfficeColIndex] is string && row[JobTitleColIndex] is string && (row[VacationTotalTimeColIndex] is double || row[VacationTotalTimeColIndex] is int) && (row[VacationUsedTimeColIndex] is double || row[VacationUsedTimeColIndex] is int) && (row[VacationUnusedTimeColIndex] is double || row[VacationUnusedTimeColIndex] is int); if (!acceptableData) { continue; } var fullName = row[FullnameColIndex].ToString(); var code = row[CodeColIndex].ToString(); var users = _applicationUserDbSet.Where(_vacationDomainService.UsersByNamesFilter(fullName).Compile()).ToList(); var userToUpdate = _vacationDomainService.FindUser(users, fullName); if (userToUpdate != null) { var fullTime = (double)row[VacationTotalTimeColIndex]; var usedTime = (double)row[VacationUsedTimeColIndex]; var unusedTime = (double)row[VacationUnusedTimeColIndex]; userToUpdate.VacationTotalTime = fullTime; userToUpdate.VacationUsedTime = usedTime; userToUpdate.VacationUnusedTime = unusedTime; userToUpdate.VacationLastTimeUpdated = DateTime.UtcNow; importStatus.Imported.Add(new VacationImportEntryDto { Code = code, FullName = fullName }); } else { var exception = new VacationImportException($"User wasn't found during import - entry code: {code}, fullname: {fullName}"); var exceptionTelemetry = new ExceptionTelemetry { Message = exception.Message, Exception = exception }; exceptionTelemetry.Properties.Add("Entry code", code); exceptionTelemetry.Properties.Add("Entry last name, first name", fullName); _telemetryClient.TrackException(exceptionTelemetry); importStatus.Skipped.Add(new VacationImportEntryDto { Code = code, FullName = fullName }); } } await _uow.SaveChangesAsync(); excelReader.Close(); return(importStatus); }