public async void CreateACommentForAnErrorReDirectsToSearchInHome() { 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 { DetailedName = "Invalid Conversion" }; ErrorResultController erc = new ErrorResultController(context); var result = await erc.Create(23, newComment, error, user); RedirectToActionResult routeResult = result as RedirectToActionResult; Assert.Equal("Home", routeResult.ControllerName); } }
public async void CreateACommentForAndErrorCommentIsCreatedOnIsSentWithRedirect() { 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 { DetailedName = "Invalid Conversion" }; ErrorResultController erc = new ErrorResultController(context); var result = await erc.Create(23, newComment, error, user); RedirectToActionResult routeResult = result as RedirectToActionResult; Assert.True(routeResult.RouteValues.Values.Contains(error.DetailedName)); } }
public async void CanUpVoteAComment() { 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 { DetailedName = "Invalid Conversion" }; ErrorResultController erc = new ErrorResultController(context); await erc.Create(23, newComment, error, user); await erc.UpVote(newComment, error, 1); Comment voted = context.Comments.Find(newComment.ID); Assert.Equal(1, voted.UpVote); } }
/// <summary> /// Action that will grab a specific error from the API and also the comments and users associated with that /// error /// </summary> /// <param name="id">Error ID</param> /// <param name="context">Syntacs DbContext</param> /// <param name="error">Error</param> /// <returns>ErrorResultViewModel</returns> public static async Task <ErrorResultViewModel> ViewDetailsError(int id, SyntacsDbContext context, Error error) { ErrorResultViewModel ervm = new ErrorResultViewModel { Error = error, Users = await context.Users.ToListAsync(), Comments = await context.Comments.Where(c => c.ErrExampleID == id) .Join(context.Users, c => c.UserID, u => u.ID, (comment, user) => new Comment { Alias = user.Alias, UserID = user.ID, ID = comment.ID, CommentBody = comment.CommentBody, ErrExampleID = comment.ErrExampleID, UpVote = comment.UpVote }) .ToListAsync() }; ervm.CodeFormat = CodeFormatter(ervm.Error); return(ervm); }
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); } }
public async void CanDeleteAComment() { 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 { DetailedName = "Invalid Conversion" }; ErrorResultController erc = new ErrorResultController(context); await erc.Create(23, newComment, error, user); var notEmpty = await context.Comments.ToListAsync(); Assert.NotEmpty(notEmpty); await erc.Delete(newComment, error); var empty = await context.Comments.ToListAsync(); Assert.Empty(empty); } }
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); } }
/// <summary> /// Constructor to set up our dependency injection /// </summary> /// <param name="context">Our DbContext</param> public ErrorResultController(SyntacsDbContext context) { _context = context; }