public void FindUser_ShouldReturnUser() { const string fullName = "LastName von FirstName"; IList <ApplicationUser> users = new List <ApplicationUser> { new ApplicationUser { Id = "1", FirstName = "John", LastName = "Armstrong" }, new ApplicationUser { Id = "2", FirstName = "John", LastName = "Lennon" }, new ApplicationUser { Id = "3", FirstName = "FirstName", LastName = "von LastName" }, new ApplicationUser { Id = "4", FirstName = "FirstName von", LastName = "LastName" } }; var user = _vacationDomainService.FindUser(users, fullName); Assert.That(user, Is.Not.Null); Assert.That(user.Id, Is.EqualTo("3")); }
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); }