public async void TestForGetLeagueArticleById() { var options = new DbContextOptionsBuilder <NewsContext>() .UseInMemoryDatabase(databaseName: "p3NewsService") .Options; using (var context = new NewsContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); var leagueArticle = new LeagueArticle { ArticleID = Guid.NewGuid(), Title = "goodnews!", Body = "wewon!", IsPinned = true, IsVisible = true }; r.LeagueArticles.Add(leagueArticle); await r.CommitSave(); var leagueArticle2 = await r.GetLeagueArticleById(leagueArticle.ArticleID); Assert.True(leagueArticle2.Equals(leagueArticle)); } }
public async void TestForGetPinnedLeagueArticles() { var options = new DbContextOptionsBuilder <NewsContext>() .UseInMemoryDatabase(databaseName: "p3NewsService") .Options; using (var context = new NewsContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); NewsController newsController = new NewsController(logic); var leagueArticle = new LeagueArticle() { ArticleID = Guid.NewGuid(), Title = "free hotdogs", Body = "come today to get your hotdogs!", Date = DateTime.Now, IsPinned = true, IsVisible = true }; r.LeagueArticles.Add(leagueArticle); await r.CommitSave(); var pinnedLeagueArticle = await newsController.GetPinnedLeagueArticles(); var convertedArticle = (List <LeagueArticleDto>)pinnedLeagueArticle; Assert.True(convertedArticle[0].Content.Equals(leagueArticle.Body)); } }
public async void TestForDeleteLeagueArticleById() { var options = new DbContextOptionsBuilder <NewsContext>() .UseInMemoryDatabase(databaseName: "p3NewsService") .Options; using (var context = new NewsContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); NewsController newsController = new NewsController(logic); var leagueArticle = new LeagueArticle() { ArticleID = Guid.NewGuid(), Title = "free hotdogs", Body = "come today to get your hotdogs!", Date = DateTime.Now, IsPinned = true, IsVisible = true }; r.LeagueArticles.Add(leagueArticle); await r.CommitSave(); Assert.NotEmpty(context.LeagueArticles); await newsController.DeleteLeagueArticleById(leagueArticle.ArticleID); Assert.Null(context.LeagueArticles.Find(leagueArticle.ArticleID)); } }
/// <summary> /// deletes a league article by the id /// </summary> /// <param name="id"></param> /// <returns></returns> public async Task DeleteLeagueArticleById(Guid id) { LeagueArticle articleToDelete = await _repo.GetLeagueArticleById(id); _repo.LeagueArticles.Remove(articleToDelete); await _repo.CommitSave(); }
/// <summary> /// edits a leagueArticle with the in coming leagueArticleDto /// </summary> /// <param name="leagueArticleDto"></param> /// <returns></returns> public async Task EditLeagueArticle(LeagueArticleDto leagueArticleDto) { LeagueArticle articleToEdit = await _repo.GetLeagueArticleById(leagueArticleDto.ArticleID); articleToEdit.Title = leagueArticleDto.Title; articleToEdit.Body = leagueArticleDto.Content; articleToEdit.Date = leagueArticleDto.Date; articleToEdit.IsVisible = leagueArticleDto.IsVisible; articleToEdit.IsPinned = leagueArticleDto.IsPinned; _repo.LeagueArticles.Update(articleToEdit); await _repo.CommitSave(); }
/// <summary> /// creates a leagueaArticle from the incoming leagueArticleDto /// </summary> /// <param name="leagueArticleDto"></param> /// <returns></returns> public async Task CreateLeagueArticle(LeagueArticleDto leagueArticleDto) { LeagueArticle newArticle = new LeagueArticle(); newArticle.Title = leagueArticleDto.Title; newArticle.Body = leagueArticleDto.Content; newArticle.Date = leagueArticleDto.Date; newArticle.IsVisible = leagueArticleDto.IsVisible; newArticle.IsPinned = leagueArticleDto.IsPinned; _repo.LeagueArticles.Add(newArticle); await _repo.CommitSave(); }
public void ValidateLeagueArticle() { var leagueArticle = new LeagueArticle { ArticleID = Guid.NewGuid(), Title = "goodnews!", Body = "wewon!", IsPinned = true, IsVisible = true }; var results = ValidateModel(leagueArticle); Assert.True(results.Count == 0); }
public async void TestForEditLeagueArticle() { var options = new DbContextOptionsBuilder <NewsContext>() .UseInMemoryDatabase(databaseName: "p3NewsService") .Options; using (var context = new NewsContext(options)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); Repo r = new Repo(context, new NullLogger <Repo>()); Logic logic = new Logic(r, new NullLogger <Repo>()); NewsController newsController = new NewsController(logic); var leagueArticle = new LeagueArticle() { ArticleID = Guid.NewGuid(), Title = "free hotdogs", Body = "come today to get your hotdogs!", Date = DateTime.Now, IsPinned = true, IsVisible = true }; r.LeagueArticles.Add(leagueArticle); await r.CommitSave(); var leagueArticleDto = new LeagueArticleDto() { ArticleID = leagueArticle.ArticleID, Title = "free hamburgers", Content = "come today to get your hamburgers!", Date = leagueArticle.Date, IsPinned = leagueArticle.IsPinned, IsVisible = leagueArticle.IsVisible, }; await newsController.EditLeagueArticle(leagueArticleDto); var editedLeagueArticle = await context.LeagueArticles.FindAsync(leagueArticle.ArticleID); Assert.True(editedLeagueArticle.Title == "free hamburgers"); } }