public void ViewAllAvailableErrors() { List <Error> errors = new List <Error> { new Error { ID = 1, DetailedName = "Invalid Conversion", CodeExample = "woo\ncode\twoo" }, new Error { ID = 4, DetailedName = "NullReference", CodeExample = "woo\ncode\twoo" }, new Error { ID = 8, DetailedName = "Exception", CodeExample = "woo\ncode\twoo" } }; ErrorResultViewModel ervm = ErrorResultViewModel.AllDetails(errors); Assert.NotEmpty(ervm.Errors); }
bool ProcessValidationException(ActionExecutedContext context) { if (context.Exception != null && context.ModelState.TryAddModelError(context.Exception)) { _logger.LogError(context.Exception, "A validation exception occurred. It was returned to the client as a HTTP Status Code 400 fail."); } var validationErrors = GetValidationMessagesFromModelState(context); if (validationErrors.Any()) { var errors = validationErrors .GroupBy(e => e.PropertyName) .ToDictionary(g => g.Key, g => g.Select(e => e)); var result = new ErrorResultViewModel(errors); context.HttpContext.Response.StatusCode = 400; context.Result = new JsonResult(result); return(true); } return(false); }
public UsuarioManagement() { this.crudUsuario = new UsuarioCrudFactory(); this.itemManagement = new ItemManagement(); this.crudContrasena = new ContrasenaCrudFactory(); this.errorResult = new ErrorResultViewModel(); this.emailService = new EmailService(); }
/// <summary> /// Action that returns the result of the error search /// </summary> /// <param name="id">id of error</param> /// <returns>A ViewModel or a NotFound if no value</returns> public async Task <IActionResult> Index(Error error) { if (error != null) { return(View(await ErrorResultViewModel.ViewDetailsError(error.ID, _context, error))); } return(NotFound()); }
public void CodeGetsSplitIntoArrayToBeFormatted() { Error error = new Error { ID = 1, DetailedName = "Invalid Conversion", CodeExample = "int a = 1, b = 2;\nint c = a + b\nint d = c - b" }; string[] split = ErrorResultViewModel.CodeFormatter(error); Assert.Equal(3, split.Length); }
public void ViewTheTopError() { Error error = new Error { ID = 1, DetailedName = "Invalid Conversion", CodeExample = "woo\ncode\twoo", Votes = 10, }; ErrorResultViewModel ervm = ErrorResultViewModel.ViewTopError(error); Assert.Equal(10, ervm.Error.Votes); }
/// <summary> /// Action that makes a GET request to the API to get all available /// errors in reference /// </summary> /// <returns>ErrorViewModel</returns> public async Task <IActionResult> Index() { try { string errorResults = await APICallModel.APICallGetAll(); string tokens = JToken.Parse(errorResults).ToString(); var errorList = JsonConvert.DeserializeObject <List <Error> >(tokens); return(View(ErrorResultViewModel.AllDetails(errorList))); } catch (Exception) { return(NotFound()); } }
public ErrorResultViewModel ComprobarErrores(BaseEntity entity) { ErrorResultViewModel errorResult = new ErrorResultViewModel(); errorResult.details = new List <string>(); var citaError = crud.VerificarHorario <Cita>(entity); if (citaError != null) { if (citaError.id_sucursal < 0) { errorResult.details.Add("Cita fuera del horario de la sucursal"); } } if (crud.VerificarCita(entity)) { var cita = (Cita)entity; if (cita.id_item < 0) { if (crud.ObtenerEmpleadoDisponibleProd(entity) < 0) { errorResult.details.Add("No hay empleados disponibles en este horario"); } } else { if (crud.ObtenerEmpleadoDisponible(entity) < 0) { errorResult.details.Add("No hay empleados disponibles en este horario"); } } } if (errorResult.details.Count == 0) { return(null); } else { errorResult.message = "Han ocurrido errores generales al registrar la cita"; return(errorResult); } }
public async void GetAnErrorFromAPI() { DbContextOptions <SyntacsDbContext> options = new DbContextOptionsBuilder <SyntacsDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (SyntacsDbContext context = new SyntacsDbContext(options)) { string errorResult = await APICallModel.APICallErrorResults("Invalid Assignment"); string tokens = JToken.Parse(errorResult).ToString(); Error results = JsonConvert.DeserializeObject <Error>(tokens); var ervm = await ErrorResultViewModel.ViewDetailsError(results.ID, context, results); Assert.Equal("Invalid Assignment", ervm.Error.DetailedName); } }
/// <summary> /// Action that makes a request to grab the Top Rated Comment /// </summary> /// <returns>ErrorResultViewModel</returns> public async Task <IActionResult> Index() { try { var topErr = await APICallModel.APICallTopError(); if (!String.IsNullOrEmpty(topErr)) { string tokens = JToken.Parse(topErr).ToString(); Error topError = JsonConvert.DeserializeObject <Error>(tokens); return(View(ErrorResultViewModel.ViewTopError(topError))); } } catch (Exception) { return(NotFound()); } return(NotFound()); }
public async Task Invoke(HttpContext context) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error; if (ex == null) { return; } var vm = new ErrorResultViewModel(context.Response.StatusCode, ex); context.Response.ContentType = "application/json"; using (var writer = new StreamWriter(context.Response.Body)) { new JsonSerializer().Serialize(writer, vm); await writer.FlushAsync().ConfigureAwait(false); } }
public async void ViewSpecificDetailsOfAnError() { DbContextOptions <SyntacsDbContext> options = new DbContextOptionsBuilder <SyntacsDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (SyntacsDbContext context = new SyntacsDbContext(options)) { Comment newComment = new Comment { ID = 1, CommentBody = "Some comment text", UpVote = 0 }; User user = new User { ID = 23, Alias = "bob" }; Error error = new Error { ID = 1, DetailedName = "Invalid Conversion", CodeExample = "woo\ncode\twoo" }; await context.Comments.AddAsync(newComment); await context.Users.AddAsync(user); await context.SaveChangesAsync(); ErrorResultViewModel ervm = await ErrorResultViewModel.ViewDetailsError(1, context, error); Assert.Equal(error.DetailedName, ervm.Error.DetailedName); } }
public async void ViewListOfSimilarErrors() { DbContextOptions <SyntacsDbContext> options = new DbContextOptionsBuilder <SyntacsDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; using (SyntacsDbContext context = new SyntacsDbContext(options)) { List <Error> errors = new List <Error> { new Error { ID = 1, ErrorCategoryID = 1, DetailedName = "Invalid Conversion", CodeExample = "woo\ncode\twoo" }, new Error { ID = 20, ErrorCategoryID = 1, DetailedName = "Similar", CodeExample = "woo\ncode\twoo" }, new Error { ID = 15, ErrorCategoryID = 1, DetailedName = "Error 3", CodeExample = "woo\ncode\twoo" }, }; ErrorResultViewModel ervm = await ErrorResultViewModel.ViewDetails(1, context, errors); Assert.NotEmpty(ervm.Errors); } }