/// <summary> /// Action used to upvote favourite error examples /// </summary> /// <param name="id">id of the error</param> /// <param name="error">Error object that binds votes and the detailed name</param> /// <param name="vote">value of the vote</param> /// <returns>Redirects regardless of success or not</returns> public async Task <IActionResult> ErrorVote(int id, [Bind("Votes, DetailedName")] Error error, int vote) { error.ID = id; error.Votes += vote; var errorVote = await APICallModel.APICallUpVoteError(id, error); return(RedirectToAction("Search", "Home", new { search = error.DetailedName })); }
public async void MakeAPICallToGetSpecificError() { var response = await APICallModel.APICallErrorResults("dividebyzero exception"); var tokens = JToken.Parse(response).ToString(); Error result = JsonConvert.DeserializeObject <Error>(tokens); Assert.Equal("DivideByZero Exception", result.DetailedName); }
public async void MakeAPICallToGetAllErrorsr() { var response = await APICallModel.APICallGetAll(); var tokens = JToken.Parse(response).ToString(); List <Error> errors = JsonConvert.DeserializeObject <List <Error> >(tokens); Assert.NotEmpty(errors); }
/// <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 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 takes in a search string and sends that as part of the /// get request to the API /// </summary> /// <param name="search">Search string</param> /// <returns>Redirects to a result or to the full list</returns> public async Task <IActionResult> Search(string search) { if (!String.IsNullOrEmpty(search)) { try { string errorResults = await APICallModel.APICallErrorResults(search); string tokens = JToken.Parse(errorResults).ToString(); Error results = JsonConvert.DeserializeObject <Error>(tokens); return(RedirectToAction("Index", "ErrorResult", results)); } catch (Exception) { return(NotFound()); } } return(RedirectToAction("Index", "ErrorList")); }
/// <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 void MakeAPICallToGetTopError() { var response = APICallModel.APICallTopError(); Assert.NotNull(response); }