Esempio n. 1
0
        private async Task BuildRaceTraceAsync(int year, int round)
        {
            try
            {
                _dataIsLoadingObserver.UpdateIsLoading(true);

                var driverTask             = _driverService.GetDriversForRaceAsync(year, round);
                var lapTimesForDriversTask = GetLapTimesForDriversAsync(year, round);

                await Task.WhenAll(driverTask, lapTimesForDriversTask);

                _driverCollection = driverTask.Result;
                var lapTimesForDrivers = lapTimesForDriversTask.Result;

                _driveTeamLookup = _driverCollection.ToDictionary(key => key.DriverCode, value => value.Team);
                _raceData        = CreateRaceDataCollection(lapTimesForDrivers);

                var referenceTime = CalculateReferenceTime(_driverCollection, _raceData);
                _dataIsLoadingObserver.UpdateIsLoading(false);

                CalculateRaceTrace(referenceTime);
            }
            catch (Exception ex)
            {
                var errorOccurrence = new ErrorOccurrence("Calculating race trace.", ex);
                _dataIsLoadingObserver.ErrorOccured(errorOccurrence);
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> PutErrorOccurrence(int id, ErrorOccurrence errorOccurrence)
        {
            if (id != errorOccurrence.Id)
            {
                return(BadRequest());
            }

            _context.Entry(errorOccurrence).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ErrorOccurrenceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <ActionResult <ErrorOccurrence> > PostErrorOccurrence(ErrorOccurrence errorOccurrence)
        {
            _context.ErrorOccurrences.Add(errorOccurrence);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetErrorOccurrence", new { id = errorOccurrence.Id }, errorOccurrence));
        }
Esempio n. 4
0
        /// <summary>
        /// Get the GetHistoryErrorOccurrenceGroups for a testsystem
        /// </summary>
        /// <param name="errorResults">the list of error results</param>
        /// <returns>A List of ErrorOccurrenceGroups</returns>
        public static List <ErrorOccurrenceGroup> GetHistoryErrorOccurrenceGroups(IList <HistoryResult> errorResults)
        {
            List <ErrorOccurrenceGroup> occurrenceGroups = new List <ErrorOccurrenceGroup>();

            foreach (HistoryResult result in errorResults)
            {
                ErrorOccurrenceGroup errorOccurrenceGroup = occurrenceGroups.Find(objErrorOccurrenceGroupOther => objErrorOccurrenceGroupOther.Testcase.ID == result.Testcase.ID);
                if (errorOccurrenceGroup == null)
                {
                    errorOccurrenceGroup = new ErrorOccurrenceGroup {
                        Testcase = result.Testcase
                    };
                    occurrenceGroups.Add(errorOccurrenceGroup);
                }
                ErrorOccurrence errorOccurrence = errorOccurrenceGroup.LstErrorOccurence.Find(errorOccurrenceOther => result.Error != null && errorOccurrenceOther.Error.ID == result.Error.ID);
                if (errorOccurrence == null)
                {
                    Debug.Assert(result.Error != null, "result.Error != null");
                    errorOccurrence = new ErrorOccurrence {
                        Error = result.Error
                    };
                    errorOccurrenceGroup.LstErrorOccurence.Add(errorOccurrence);
                }
                OccurrenceElement occurrenceElement = new OccurrenceElement
                {
                    Browser        = result.Browser,
                    DateTime       = result.Testtime,
                    Language       = result.Language,
                    ScreenshotFile = result.ScreenshotFile,
                    DetailLog      = result.DetailLog
                };
                errorOccurrence.LstOccurence.Add(occurrenceElement);
            }
            return(occurrenceGroups);
        }
        public void Should_Add_New_Error_When_Save()
        {
            var fakeContext = new FakeContext("SaveNewError");

            var fakeError = new ErrorOccurrence();

            fakeError.Id               = 3;
            fakeError.Title            = "title";
            fakeError.RegistrationDate = DateTime.Today;
            fakeError.Origin           = "ip";
            fakeError.Filed            = false;
            fakeError.Details          = "details";
            fakeError.IdEvent          = 2;
            fakeError.EnvironmentId    = 2;
            fakeError.LevelId          = 2;
            fakeError.Username         = "******";

            using (var context = new CentralErroContexto(fakeContext.FakeOptions))
            {
                var service = new ErrorOcurrenceService(context);
                var actual  = service.SaveOrUpdate(fakeError);

                Assert.NotEqual(0, actual.Id);
            }
        }
Esempio n. 6
0
        public ActionResult <ErrorOccurrenceDTO> Post([FromBody] ErrorOccurrenceDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Montando as fk's
            var level = _levelService.FindByIdLevel(value.LevelId);
            var env   = _environmentService.FindById(value.EnvironmentId);

            if (level != null && env != null)
            {
                var errorOcurrence = new ErrorOccurrence()
                {
                    Title            = value.Title,
                    RegistrationDate = DateTime.Now,
                    Origin           = value.Origin,
                    Filed            = false,
                    Details          = value.Details,
                    IdEvent          = value.EventId,
                    EnvironmentId    = env.Id,
                    LevelId          = level.IdLevel,
                    Username         = value.Username,
                };

                var registryError = _erroService.SaveOrUpdate(errorOcurrence);
                if (registryError != null)
                {
                    return(Ok("Ocorrencia cadastrada com sucesso!"));
                }
                else
                {
                    object res = null;
                    NotFoundObjectResult notfound = new NotFoundObjectResult(res);
                    notfound.StatusCode = 400;
                    notfound.Value      = "Erro ao registrar Ocorrencia!";
                    return(NotFound(notfound));
                }
            }
            else
            {
                object res = null;
                NotFoundObjectResult notfound = new NotFoundObjectResult(res);
                notfound.StatusCode = 404;

                if (level == null)
                {
                }
                if (env == null)
                {
                    notfound.Value = "O Environment informado não foi encontrado!";
                    return(NotFound(notfound));
                }
                return(NotFound());
            }
        }
Esempio n. 7
0
 public ErrorOccurrence SaveOrUpdate(ErrorOccurrence error)
 {
     if (_context.Environments.Any(e => e.Id == error.EnvironmentId) &&
         _context.Levels.Any(l => l.IdLevel == error.LevelId))
     {
         var state = error.Id == 0 ? EntityState.Added : EntityState.Modified;
         _context.Entry(error).State = state;
         _context.SaveChanges();
     }
     return(error);
 }
Esempio n. 8
0
 public void Update(ErrorOccurrence errorOccurrence)
 {
     try
     {
         _repository.Update(errorOccurrence);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void Update(ErrorOccurrence errorOccurrence)
        {
            var errorOccurrenceRecovered = _context.ErrorOccurrences
                                           .FirstOrDefault(x => x.Id == errorOccurrence.Id);

            if (errorOccurrenceRecovered == null)
            {
                throw new Exception($"Ocorrência de erro com id {errorOccurrence.Id} não encontrada.");
            }

            _context.ErrorOccurrences.Update(errorOccurrence);
            _context.SaveChanges();
        }
Esempio n. 10
0
        public ErrorOccurrence RegisterOrUpdateErrorOccurrence(ErrorOccurrence errorOccurrence)
        {
            if (_context.Users.Any(u => u.UserId == errorOccurrence.UserId) &&
                _context.Errors.Any(e => e.ErrorId == errorOccurrence.ErrorId) &&
                _context.Situations.Any(s => s.SituationId == errorOccurrence.SituationId))
            {
                var state = errorOccurrence.ErrorOccurrenceId == 0 ? EntityState.Added : EntityState.Modified;
                _context.ErrorOccurrences.Add(errorOccurrence);
                _context.SaveChanges();
            }

            return(errorOccurrence);
        }
Esempio n. 11
0
 public void Save(ErrorOccurrence errorOccurrence)
 {
     try
     {
         if (errorOccurrence.CreatedAt == DateTime.MinValue || errorOccurrence.CreatedAt == null)
         {
             errorOccurrence.CreatedAt = DateTime.Now;
         }
         _repository.Save(errorOccurrence);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
        public void Should_Return_Ok_When_Filed_Errors()
        {
            var fakeContext = new FakeContext("FileError");

            var fakeError = new ErrorOccurrence();

            fakeError.Id    = 1;
            fakeError.Filed = true;

            using (var context = new CentralErroContexto(fakeContext.FakeOptions))
            {
                var service = new ErrorOcurrenceService(context);
                var actual  = service.SaveOrUpdate(fakeError);

                Assert.NotEqual(0, actual.Id);
            }
        }
Esempio n. 13
0
        public ActionResult <ErrorOccurrenceDTO> Delete(int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ErrorOccurrence errorOccurrence = _erroService.FindById(id);

            if (errorOccurrence == null)
            {
                return(BadRequest("Erro não existe"));
            }
            else
            {
                _contexto.Errors.Remove(errorOccurrence);
                var retornError = _erroService.SaveOrUpdate(errorOccurrence);
                var retorno     = _mapper.Map <ErrorOccurrenceDTO>(retornError);
                return(Ok(retorno));
            }
        }
Esempio n. 14
0
        private bool testarItemCorrespondeFiltro(ErrorOccurrence erro, string tipoFiltro, string valorFiltro)
        {
            if (tipoFiltro == "T")
            {
                return(true);
            }

            if (valorFiltro == "none")
            {
                return(true);
            }


            if (string.IsNullOrEmpty(valorFiltro))
            {
                return(true);
            }


            if (tipoFiltro == "L")
            {
                return(erro.Error.Level.Id.ToString().Contains(valorFiltro.ToUpper()) ||
                       erro.Error.Level.Name.ToUpper().Contains(valorFiltro.ToUpper()));
            }


            if (tipoFiltro == "D")
            {
                return(erro.Details.ToUpper().Contains(valorFiltro.ToUpper()) ||
                       erro.Error.Title.ToUpper().Contains(valorFiltro.ToUpper()));
            }

            if (tipoFiltro == "O")
            {
                return(erro.Origin.Contains(valorFiltro));
            }

            return(true);
        }
Esempio n. 15
0
        public void Update(ErrorOccurrence errorOccurrence)
        {
            var errorOccurrenceRecovered = _context.ErrorOccurrences.AsNoTracking()
                                           .FirstOrDefault(x => x.Id == errorOccurrence.Id);

            if (errorOccurrenceRecovered == null)
            {
                throw new Exception($"Ocorrência de erro com id {errorOccurrence.Id} não encontrada.");
            }

            errorOccurrence.Title = string.IsNullOrEmpty(errorOccurrence.Title)
                ? string.IsNullOrEmpty(errorOccurrenceRecovered.Title) ? "Não informado." : errorOccurrenceRecovered.Title
                : errorOccurrence.Title;
            errorOccurrence.Description = string.IsNullOrEmpty(errorOccurrence.Description)
                ? string.IsNullOrEmpty(errorOccurrenceRecovered.Description) ? "Não informado." : errorOccurrenceRecovered.Description
                : errorOccurrence.Description;
            errorOccurrence.Origin = string.IsNullOrEmpty(errorOccurrence.Origin)
                ? string.IsNullOrEmpty(errorOccurrenceRecovered.Origin) ? "Não informado." : errorOccurrenceRecovered.Origin
                : errorOccurrence.Origin;

            _context.ErrorOccurrences.Update(errorOccurrence);
            _context.SaveChanges();
        }
Esempio n. 16
0
        public ErrorOccurrence FileErrorOccurrence(ErrorOccurrence errorOccurrence)
        {
            if (_context.Users.Any(u => u.UserId == errorOccurrence.UserId) &&
                _context.Errors.Any(e => e.ErrorId == errorOccurrence.ErrorId) &&
                _context.Situations.Any(s => s.SituationId == errorOccurrence.SituationId))
            {
                var state = errorOccurrence.ErrorOccurrenceId == 0 ? EntityState.Added : EntityState.Modified;
                var FileErrorOccurrence = errorOccurrence.Situation;

                if (_situationService.ConsultSituationByName("Arquivado") == null)
                {
                    return(null);
                }

                errorOccurrence.Situation   = _situationService.ConsultSituationByName("Arquivado");
                errorOccurrence.SituationId = _situationService.ConsultSituationByName("Arquivado").SituationId;

                _context.Entry(errorOccurrence).State = state;
                _context.SaveChanges();
            }

            return(errorOccurrence);
        }
Esempio n. 17
0
        public ActionResult <ErrorOccurrenceDTO> PutErrorOccurrence(int id, ErrorOccurrence errorOccurrence)
        {
            if (id != errorOccurrence.ErrorOccurrenceId)
            {
                return(BadRequest());
            }

            try
            {
                return(Ok(_mapper.Map <ErrorOccurrenceDTO>(_service.RegisterOrUpdateErrorOccurrence(errorOccurrence))));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!_service.ErrorOccurrenceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
 public void Save(ErrorOccurrence errorOccurrence)
 {
     _context.ErrorOccurrences.Add(errorOccurrence);
     _context.SaveChanges();
 }
        public Mock <IErrorOcurrenceService> FakeErrorOccurrenceService()
        {
            var service = new Mock <IErrorOcurrenceService>();

            service.Setup(x => x.FindById(It.IsAny <int>()))
            .Returns((int id) => GetFakeData <ErrorOccurrence>()
                     .FirstOrDefault(x => x.Id == id));

            service.Setup(x => x.GetAllErrors())
            .Returns(() => GetFakeData <ErrorOccurrence>().ToList());

            service.Setup(x => x.FiledErrors(It.IsAny <int>()));

            service.Setup(x => x.FindFiledErrors())
            .Returns(() => GetFakeData <ErrorOccurrence>()
                     .Where(x => x.Filed == true)
                     .ToList());

            service.Setup(x => x.SaveOrUpdate(It.IsAny <ErrorOccurrence>()))
            .Returns((ErrorOccurrence error) =>
            {
                if (error.Id == 0)
                {
                    error.Id = 999;
                }
                return(error);
            });


            service.Setup(x => x.FindByFilters(It.IsAny <int>(), It.IsAny <int>(),
                                               It.IsAny <int>(), It.IsAny <string>()))
            .Returns((int ambiente, int?campoOrdenacao, int?campoBuscado,
                      string textoBuscado) =>
            {
                var fakeError = new ErrorOccurrence();

                if (textoBuscado == "error")
                {
                    fakeError.LevelId = 1;
                }
                else if (textoBuscado == "warn")
                {
                    fakeError.LevelId = 2;
                }
                else
                {
                    fakeError.LevelId = 3;
                }

                List <ErrorOccurrence> errorsSearchList = new List <ErrorOccurrence>();
                List <ErrorOccurrence> errorsList       = new List <ErrorOccurrence>();

                if (textoBuscado != "" && campoBuscado != 0 && campoBuscado != null)
                {
                    if (campoBuscado == 1)
                    {
                        errorsList = GetFakeData <ErrorOccurrence>().Where(x => x.LevelId == fakeError.LevelId && x.EnvironmentId == ambiente).ToList();
                    }
                    else if (campoBuscado == 2)
                    {
                        errorsList = GetFakeData <ErrorOccurrence>().Where(x => x.Details.Contains(textoBuscado) && x.EnvironmentId == ambiente).ToList();
                    }
                    else if (campoBuscado == 3)
                    {
                        errorsList = GetFakeData <ErrorOccurrence>().Where(x => x.Origin.Contains(textoBuscado) && x.EnvironmentId == ambiente).ToList();
                    }
                }
                else if (ambiente > 0)
                {
                    errorsList = GetFakeData <ErrorOccurrence>().Where(x => x.EnvironmentId == ambiente).ToList();
                }
                else
                {
                    errorsList = GetFakeData <ErrorOccurrence>().ToList();
                }

                if (errorsList.Count() > 0)
                {
                    if (campoOrdenacao == 1 && campoBuscado != 1)
                    {
                        errorsSearchList = errorsList.OrderBy(x => x.LevelId).ToList();
                    }
                    else if (campoOrdenacao == 2)
                    {
                        if (campoBuscado != 1)
                        {
                            var ordenacao = errorsList.GroupBy(x => x.LevelId)
                                            .Select(group => new
                            {
                                Level      = group.Key,
                                Quantidade = group.Count()
                            })
                                            .OrderByDescending(x => x.Quantidade)
                                            .ToList();

                            errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Level).IndexOf(x.LevelId)).ToList();
                        }
                        else
                        {
                            var ordenacao = errorsList.GroupBy(x => x.Details)
                                            .Select(group => new
                            {
                                Details    = group.Key,
                                Quantidade = group.Count()
                            })
                                            .OrderByDescending(x => x.Quantidade)
                                            .ToList();

                            errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Details).IndexOf(x.Details)).ToList();
                        }
                    }
                    else
                    {
                        var ordenacao = errorsList.GroupBy(x => x.Origin)
                                        .Select(group => new
                        {
                            Origin     = group.Key,
                            Quantidade = group.Count()
                        })
                                        .OrderByDescending(x => x.Quantidade)
                                        .ToList();

                        errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Origin).IndexOf(x.Origin)).ToList();
                    }
                }
                //caso não for informado nenhuma ordenação, eu ordeno pelo Environment
                else
                {
                    errorsSearchList = errorsList.OrderBy(x => x.Origin).ToList();
                }

                errorsSearchList = errorsSearchList.Where(x => x.Filed == false).ToList();

                return(errorsSearchList);
            });
            return(service);
        }
        public void Should_Be_Ok_When_Get_By_Filter(int ambiente, int?campoOrdenacao, int?campoBuscado,
                                                    string textoBuscado)
        {
            var fakeError = new ErrorOccurrence();

            if (textoBuscado == "error")
            {
                fakeError.LevelId = 1;
            }
            else if (textoBuscado == "warn")
            {
                fakeError.LevelId = 2;
            }
            else
            {
                fakeError.LevelId = 3;
            }

            List <ErrorOccurrence> errorsSearchList = new List <ErrorOccurrence>();
            List <ErrorOccurrence> errorsList       = new List <ErrorOccurrence>();

            if (textoBuscado != "" && campoBuscado != 0 && campoBuscado != null)
            {
                if (campoBuscado == 1)
                {
                    errorsList = _fakeContext.GetFakeData <ErrorOccurrence>().Where(x => x.LevelId == fakeError.LevelId && x.EnvironmentId == ambiente).ToList();
                }
                else if (campoBuscado == 2)
                {
                    errorsList = _fakeContext.GetFakeData <ErrorOccurrence>().Where(x => x.Details.Contains(textoBuscado) && x.EnvironmentId == ambiente).ToList();
                }
                else if (campoBuscado == 3)
                {
                    errorsList = _fakeContext.GetFakeData <ErrorOccurrence>().Where(x => x.Origin.Contains(textoBuscado) && x.EnvironmentId == ambiente).ToList();
                }
            }
            else if (ambiente > 0)
            {
                errorsList = _fakeContext.GetFakeData <ErrorOccurrence>().Where(x => x.EnvironmentId == ambiente).ToList();
            }
            else
            {
                errorsList = _fakeContext.GetFakeData <ErrorOccurrence>().ToList();
            }

            if (errorsList.Count() > 0)
            {
                if (campoOrdenacao == 1 && campoBuscado != 1)
                {
                    errorsSearchList = errorsList.OrderBy(x => x.LevelId).ToList();
                }
                else if (campoOrdenacao == 2)
                {
                    if (campoBuscado != 1)
                    {
                        var ordenacao = errorsList.GroupBy(x => x.LevelId)
                                        .Select(group => new
                        {
                            Level      = group.Key,
                            Quantidade = group.Count()
                        })
                                        .OrderByDescending(x => x.Quantidade)
                                        .ToList();

                        errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Level).IndexOf(x.LevelId)).ToList();
                    }
                    else
                    {
                        var ordenacao = errorsList.GroupBy(x => x.Details)
                                        .Select(group => new
                        {
                            Details    = group.Key,
                            Quantidade = group.Count()
                        })
                                        .OrderByDescending(x => x.Quantidade)
                                        .ToList();

                        errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Details).IndexOf(x.Details)).ToList();
                    }
                }
                else
                {
                    var ordenacao = errorsList.GroupBy(x => x.Origin)
                                    .Select(group => new
                    {
                        Origin     = group.Key,
                        Quantidade = group.Count()
                    })
                                    .OrderByDescending(x => x.Quantidade)
                                    .ToList();

                    errorsSearchList = errorsList.OrderBy(x => ordenacao.Select(y => y.Origin).IndexOf(x.Origin)).ToList();
                }
            }
            else
            {
                errorsSearchList = errorsSearchList.OrderBy(x => x.Origin).ToList();
            }

            errorsSearchList = errorsSearchList.Where(x => x.Filed == false).ToList();

            List <int>    errors_int    = new List <int>();
            List <string> errors_string = new List <string>();

            if (errorsSearchList.Count() > 0)
            {
                if (campoOrdenacao == 1 && campoBuscado != 1)
                {
                    errors_int = errorsSearchList.Select(x => x.LevelId).ToList();
                }
                else if (campoOrdenacao == 2)
                {
                    if (campoBuscado != 1)
                    {
                        errors_int = errorsSearchList.Select(x => x.LevelId).ToList();
                    }
                    else
                    {
                        errors_string = errorsSearchList.Select(x => x.Details).ToList();
                    }
                }
                else
                {
                    errors_string = errorsSearchList.Select(x => x.Origin).ToList();
                }
            }
            else
            {
                errors_string = errorsSearchList.Select(x => x.Origin).ToList();
            }

            var service = new ErrorOcurrenceService(_contexto);
            var actual  = service.FindByFilters(ambiente, campoOrdenacao, campoBuscado, textoBuscado);

            Assert.Equal(errorsSearchList, actual, new ErrorOccurrenceIdComparer());
        }