public async Task CreateTaskAsyncShouldExecuteRepositoryCreateAsync() { // Arrange var val = Guid.NewGuid(); var textTaskEntity = new TextTaskEntity { Id = val }; var textTaskModel = new TextTaskModel() { Id = val }; _textTaskRepository.Setup(x => x.CreateAsync(It.IsAny <TextTaskEntity>())).ReturnsAsync(textTaskEntity); _mapper.Setup(m => m.Map <TextTaskModel>(It.IsAny <TextTaskEntity>())).Returns(new TextTaskModel { Id = val }); // Act var result = await _textTaskService.CreateTextTaskAsync(textTaskModel); // Assert Assert.NotNull(result); Assert.False(result.IsDeleted); Assert.Equal(textTaskModel.Id, result.Id); }
public async Task GetAllTasksAsyncShouldExecuteRepositoryGetAllTasksAsync() { // Arrange var listTaskEntities = new List <TextTaskEntity>(); var listTaskModels = new List <TextTaskModel>(); for (var i = 0; i < 5; i++) { var val = Guid.NewGuid(); var textTaskEntity = new TextTaskEntity { Id = val }; listTaskEntities.Add(textTaskEntity); var textTaskModel = new TextTaskModel() { Id = val }; listTaskModels.Add(textTaskModel); } _textTaskRepository.Setup(x => x.GetAllAsync()).ReturnsAsync(listTaskEntities); _mapper.Setup(m => m.Map <IEnumerable <TextTaskModel> >(It.IsAny <IEnumerable <TextTaskEntity> >())).Returns(listTaskModels); // Act var result = await _textTaskService.GetAllTextTasksAsync(); // Assert Assert.NotNull(result); Assert.Equal(result, listTaskModels); _textTaskRepository.Verify(x => x.GetAllAsync()); }
public async Task <ActionResult <TaskModel> > PostTextTask([FromForm] TextTaskModel textTaskModel) { var bearerToken = Request.Headers["Authorization"]; _logger.LogInformation($"PostTextTask {bearerToken} {DateTime.Now}"); var textFile = await _taskService.CreateTextTaskAsync(textTaskModel); return(new OkObjectResult(textFile)); }
public async Task <TextTaskModel> CreateTextTaskAsync(TextTaskModel textTaskModel) { var textTaskEntity = new TextTaskEntity { TaskId = textTaskModel.TaskId, TextId = textTaskModel.TextId, FindindWordsCount = textTaskModel.FindindWordsCount }; textTaskEntity = await _textTaskEfRepository.CreateAsync(textTaskEntity); return(_mapper.Map <TextTaskModel>(textTaskEntity)); }
private void DoWork(object state) { try { if (GetTaskModel is not null) { //Поиск новых файлов var allFiles = _iFindClient.GetAllTexts().Result; var allNewFiles = allFiles.Where(x => DateTime.Now.Subtract(x.CreatedDate).Minutes >= GetTaskModel.TaskInterval).ToList(); var qwe = allNewFiles.Count(); if (allNewFiles is not null && allNewFiles.Count() > 0) { //Слова для поиска string[] words = GetTaskModel.TaskSearchWords.Split(" "); foreach (var item in allNewFiles) { var textArray = item.Text.Replace('\r', ' ').Replace('\n', ' ').Replace(" ", " ").Split(" "); var findWords = textArray.SelectMany(e => words.Where(x => x == e)); var textTaskModel = new TextTaskModel { TaskId = GetTaskModel.Id, TextId = item.Id, FindindWordsCount = findWords.Count(), }; _iTextTaskService.CreateTextTaskAsync(textTaskModel).Wait(); } } } else { //Получени данных для задачи GetOrCreateTaskAsync().Wait(); } } catch (Exception ex) { throw; } }
private void Workflow(object state) { try { if (CurrentTaskModel is not null) { var allTexts = _iFindClient.GetAllTextsAsync().Result; var allNewTexts = allTexts.Where(x => DateTime.UtcNow.Subtract(x.CreatedDate) < ThreeMinutesInterval); if (allNewTexts is not null && allNewTexts.Count() > 0) { string[] words = CurrentTaskModel?.TaskFindWordsModels.Select(x => x.FindWord).ToArray(); foreach (var item in allNewTexts) { var infoAboutMatch = _iFindClient.GetWordsByMaskAsync(item.Id, words).Result; var resultDigits = Regex.Match(infoAboutMatch, @"\d+").Value; var textTaskModel = new TextTaskModel { TaskId = CurrentTaskModel.Id, TextId = item.Id, FindindWordsCount = Convert.ToInt32(resultDigits) }; _iTextTaskService.CreateTextTaskAsync(textTaskModel).Wait(); } } } else { CreateTaskAsync().Wait(); } } catch (Exception ex) { throw; } }
public async Task <ActionResult <TaskModel> > PostTextTask([FromForm] TextTaskModel textTaskModel) { var textFile = await _taskService.CreateTextTaskAsync(textTaskModel); return(new OkObjectResult(textFile)); }