Exemplo n.º 1
0
        public async void TestForCreateLeagueArticle()
        {
            //for coverage
            var dbContext = new NewsContext();

            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            leagueArticleDto = new LeagueArticleDto()
                {
                    ArticleID = Guid.NewGuid(),
                    Title     = "free hotdogs",
                    Content   = "come today to get your hotdogs!",
                    Date      = DateTime.Now,
                    IsPinned  = true,
                    IsVisible = true
                };

                await newsController.CreateLeagueArticle(leagueArticleDto);

                Assert.NotNull(context.LeagueArticles);
            }
        }
Exemplo n.º 2
0
        /// <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();
        }
Exemplo n.º 3
0
        /// <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 ValidateLeagueArticleDto()
        {
            var leagueArticleDto = new LeagueArticleDto
            {
                ArticleID = Guid.NewGuid(),
                Title     = "goodnews!",
                Content   = "wewon!",
                Date      = DateTime.Now,
                IsPinned  = true,
                IsVisible = true
            };

            var results = ValidateModel(leagueArticleDto);

            Assert.True(results.Count == 0);
        }
Exemplo n.º 5
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");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// returns a list of league articles that are pinned
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <LeagueArticleDto> > GetPinnedLeagueArticleDto()
        {
            List <LeagueArticle> pinnedLeagueArticles = (List <LeagueArticle>) await _repo.GetPinnedLeagueArticles();

            List <LeagueArticleDto> dtos = new List <LeagueArticleDto>();

            foreach (var item in pinnedLeagueArticles)
            {
                LeagueArticleDto newDto = new LeagueArticleDto();
                newDto.ArticleID = item.ArticleID;
                newDto.Title     = item.Title;
                newDto.Content   = item.Body;
                newDto.Date      = item.Date;
                newDto.IsVisible = item.IsVisible;
                newDto.IsPinned  = item.IsPinned;
                dtos.Add(newDto);
            }
            return(dtos);
        }
Exemplo n.º 7
0
 public async Task EditLeagueArticle(LeagueArticleDto leagueArticleDto)
 {
     await _logic.EditLeagueArticle(leagueArticleDto);
 }
Exemplo n.º 8
0
 public async Task CreateLeagueArticle(LeagueArticleDto leagueArticleDto)
 {
     await _logic.CreateLeagueArticle(leagueArticleDto);
 }