public async Task ChecksIfGetAllArticlesReturnsCorrectCount()
        {
            var options = new DbContextOptionsBuilder <ElectricTravelDbContext>()
                          .UseInMemoryDatabase(databaseName: "ArticlesTestDb").Options;

            using var dbContext = new ElectricTravelDbContext(options);

            var user = new ElectricTravelUser
            {
                Email    = "*****@*****.**",
                UserName = "******",
            };

            var article = new Article
            {
                ShortDescription = "asdffggasdasd",
                Content          = "asdasdjnjad",
                CreatedBy        = user,
                Title            = "asdgggghasjkljkj",
            };

            dbContext.Users.Add(user);
            dbContext.Articles.Add(article);

            dbContext.SaveChanges();

            using var repo = new EfDeletableEntityRepository <Article>(dbContext);
            var service = new ArticlesService(repo);

            var articasdasle = await dbContext.Articles
                               .FirstOrDefaultAsync(x => x.CreatedById == "goshkadsa");

            var articles = await service.GetAllArticles <ArticleViewModel>();

            var expectedResult = 2;
            var actualResult   = articles.Count();

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            var model = articlesService.GetAllArticles();

            return(View(model));
        }
Exemplo n.º 3
0
 public ActionResult <List <Article> > GetAllArticles() =>
 _articlesService.GetAllArticles();