示例#1
0
        public async void TestForGetLeagueArticles()
        {
            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 getLeagueArticles = await newsController.GetLeagueArticles();

                var convertedArticles = (List <LeagueArticleDto>)getLeagueArticles;
                Assert.True(convertedArticles[0].Content.Equals(leagueArticle.Body));
            }
        }