public async void TestForGetVisibleTeamArticles()
        {
            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  teamArticle = new TeamArticle
                {
                    ArticleID = Guid.NewGuid(),
                    TeamID    = Guid.NewGuid(),
                    Title     = "Start of season",
                    Body      = "Let's win them all!",
                    IsVisible = true,
                    IsPinned  = true
                };

                r.TeamArticles.Add(teamArticle);
                await r.CommitSave();

                var teamArticle2 = await r.GetVisibleTeamArticles();

                var convertedList = (List <TeamArticle>)teamArticle2;
                Assert.True(convertedList[0].Equals(teamArticle));
            }
        }
Esempio n. 2
0
        public async void TestForDeleteTeamArticle()
        {
            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            teamArticle    = new TeamArticle()
                {
                    ArticleID = Guid.NewGuid(),
                    Title     = "free hotdogs",
                    Body      = "come today to get your hotdogs!",
                    Date      = DateTime.Now,
                    IsPinned  = true,
                    IsVisible = true,
                    TeamID    = Guid.NewGuid()
                };
                r.TeamArticles.Add(teamArticle);
                await r.CommitSave();

                Assert.NotEmpty(context.TeamArticles);

                await newsController.DeleteTeamArticle(teamArticle.ArticleID);

                Assert.Null(context.TeamArticles.Find(teamArticle.ArticleID));
            }
        }
        public async void TestForGetPinnedTeamArticleDto()
        {
            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>());
                var   teamArticle = new TeamArticle()
                {
                    ArticleID = Guid.NewGuid(),
                    Title     = "free hotdogs",
                    Body      = "come today to get your hotdogs!",
                    Date      = DateTime.Now,
                    IsPinned  = true,
                    IsVisible = true,
                    TeamID    = Guid.NewGuid()
                };
                r.TeamArticles.Add(teamArticle);
                await r.CommitSave();

                var pinnedTeamArticle = await logic.GetPinnedTeamArticleDto();

                var convertedArticle = (List <TeamArticleDto>)pinnedTeamArticle;
                Assert.True(convertedArticle[0].Content.Equals(teamArticle.Body));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// deletes a team article by the id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteTeamArticleById(Guid id)
        {
            TeamArticle articleToDelete = await _repo.GetTeamArticleById(id);

            _repo.TeamArticles.Remove(articleToDelete);
            await _repo.CommitSave();
        }
Esempio n. 5
0
        /// <summary>
        /// Edits a teamArticle from the in coming teamArticleDto
        /// </summary>
        /// <param name="teamArticleDto"></param>
        /// <returns></returns>
        public async Task EditTeamArticle(TeamArticleDto teamArticleDto)
        {
            TeamArticle articleToEdit = await _repo.GetTeamArticleById(teamArticleDto.ArticleID);

            articleToEdit.Title     = teamArticleDto.Title;
            articleToEdit.Body      = teamArticleDto.Content;
            articleToEdit.Date      = teamArticleDto.Date;
            articleToEdit.TeamID    = teamArticleDto.TeamID;
            articleToEdit.IsVisible = teamArticleDto.IsVisible;
            _repo.TeamArticles.Update(articleToEdit);
            await _repo.CommitSave();
        }
Esempio n. 6
0
        /// <summary>
        /// creates a teamArticle from the in coming teamArticleDto
        /// </summary>
        /// <param name="teamArticleDto"></param>
        /// <returns></returns>
        public async Task CreateTeamArticle(TeamArticleDto teamArticleDto)
        {
            TeamArticle newArticle = new TeamArticle();

            newArticle.Title    = teamArticleDto.Title;
            newArticle.Body     = teamArticleDto.Content;
            newArticle.Date     = teamArticleDto.Date;
            newArticle.TeamID   = teamArticleDto.TeamID;
            newArticle.IsPinned = teamArticleDto.IsPinned;
            _repo.TeamArticles.Add(newArticle);
            await _repo.CommitSave();
        }
        public void ValidateTeamArticle()
        {
            var teamArticle = new TeamArticle
            {
                ArticleID = Guid.NewGuid(),
                TeamID    = Guid.NewGuid(),
                Title     = "Start of season",
                Body      = "Let's win them all!",
                IsVisible = true,
                IsPinned  = true
            };

            var results = ValidateModel(teamArticle);

            Assert.True(results.Count == 0);
        }
        public async void TestForEditTeamArticle()
        {
            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>());

                var teamArticle = new TeamArticle()
                {
                    ArticleID = Guid.NewGuid(),
                    Title     = "free hotdogs",
                    Body      = "come today to get your hotdogs!",
                    Date      = DateTime.Now,
                    IsPinned  = true,
                    IsVisible = true,
                    TeamID    = Guid.NewGuid()
                };
                r.TeamArticles.Add(teamArticle);
                await r.CommitSave();

                var teamArticleDto = new TeamArticleDto()
                {
                    ArticleID = teamArticle.ArticleID,
                    Title     = "free hamburgers",
                    Content   = "come today to get your hamburgers!",
                    Date      = teamArticle.Date,
                    IsPinned  = teamArticle.IsPinned,
                    IsVisible = teamArticle.IsVisible,
                    TeamID    = teamArticle.TeamID
                };
                await logic.EditTeamArticle(teamArticleDto);

                var editedTeamArticle = await context.TeamArticles.FindAsync(teamArticle.ArticleID);

                Assert.True(editedTeamArticle.Title == "free hamburgers");
            }
        }