예제 #1
0
        public async Task GetAllShouldReturnArticles()
        {
            this.Setup();
            var repo = new Mock <IDeletableEntityRepository <BlogArticle> >();

            repo.Setup(x => x.AllAsNoTracking()).Returns(this.articleList.AsQueryable());
            repo.Setup(x => x.AddAsync(It.IsAny <BlogArticle>())).Callback(
                (BlogArticle article) => this.articleList.Add(article));
            var categoryRepo    = new Mock <IDeletableEntityRepository <BlogCategory> >();
            var articlesService = new ArticlesService(repo.Object, categoryRepo.Object);
            await articlesService.CreateAsync(this.testArticle, "testUser");

            var articles = articlesService.GetAll <ArticleViewModel>(1, 10);

            Assert.Single(articles);
        }
예제 #2
0
        public async Task GetAllArticles_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);

            this.dbContext.Articles.Add(new Article {
                Title = "TestTitle1", Content = "TestContent1"
            });
            this.dbContext.Articles.Add(new Article {
                Title = "TestTitle2", Content = "TestContent2"
            });
            this.dbContext.Articles.Add(new Article {
                Title = "TestTitle3", Content = "TestContent3"
            });
            await this.dbContext.SaveChangesAsync();

            // Act
            var articles = articlesService.GetAll();

            // Assert
            Assert.AreEqual(3, articles.Count);
        }
예제 #3
0
        public async Task TestGetAllMethod()
        {
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var articleRepository = new EfDeletableEntityRepository <Article>(context);

            var articlesService = new ArticlesService(articleRepository);

            var seeder = new ArticlesTestsSeeder();

            for (int i = 0; i < 10; i++)
            {
                var inputModel = new CreateArticleViewModel
                {
                    ImgUrl  = $"TT{i}{i * 2}asd",
                    Content = $"Ten{i}{i * 2}",
                    Title   = $"Article{i}",
                };
                await articlesService.CreateAsync(inputModel, i.ToString());
            }

            var result = articlesService.GetAll <IndexArticleViewModel>();

            Assert.Equal(10, result.Count());
        }
        public void GetAll_ReturnsCorrectAmountOfItems()
        {
            // Arrange
            var context  = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var article1 = new Article {
                Id = 1, Title = "ar1"
            };
            var article2 = new Article {
                Id = 2, Title = "art2"
            };
            var article3 = new Article {
                Id = 3, Title = "art3"
            };

            context.Articles.AddRange(article1, article2, article3);
            context.SaveChanges();
            var articlesService = new ArticlesService(context);

            // Act
            var result = articlesService.GetAll().ToList();

            //Assert
            Assert.Equal(3, result.Count);
        }