public void GetById_ReturnCorrectArticle()
        {
            // Arrange
            var context  = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var article1 = new Article {
                Id = 1, Title = "ar1", Ratings = new List <Rating>()
            };
            var article2 = new Article {
                Id = 2, Title = "art2", Ratings = new List <Rating>()
            };
            var article3 = new Article {
                Id = 3, Title = "art3", Ratings = new List <Rating>()
            };

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

            // Act
            var result    = articlesService.GetById(1);
            var resultDto = articlesService.GetById(1, "");

            //Assert
            Assert.Equal("ar1", result.Title);
            Assert.Equal("ar1", resultDto.Title);
            Assert.Equal(RatingType.Neutral, resultDto.CurrentUserRating);
        }
示例#2
0
        public ActionResult ViewEdit(int id)
        {
            ArticleItemModel model = new ArticleItemModel();
            var categoryItem       = _artilesService.GetById(id);

            model = categoryItem.ToModelArticle();
            return(View("Create", model));
        }
示例#3
0
        public async Task TestGetByIdMethod()
        {
            MapperInitializer.InitializeMapper();
            var context           = ApplicationDbContextInMemoryFactory.InitializeContext();
            var articleRepository = new EfDeletableEntityRepository <Article>(context);

            var articlesService = new ArticlesService(articleRepository);

            var articlesId = new List <int>();

            var inputModel = new CreateArticleViewModel
            {
                ImgUrl  = $"TT{2}{2 * 2}asd",
                Content = $"Ten{2}{2 * 2}",
                Title   = $"Article{2}",
            };
            var id = await articlesService.CreateAsync(inputModel, "2");

            var articleId = articleRepository.All().First(x => x.Id == id);

            var article = articlesService.GetById <IndexArticleViewModel>(id);

            Assert.True(article != null);

            Assert.True(article.Id == id);
        }
示例#4
0
        public async Task GetByIdShouldReturnTheCorrectArticle()
        {
            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");

            await articlesService.CreateAsync(this.testArticle, "testUser");

            var returnedArticle = articlesService.GetById <ArticleViewModel>(1);

            Assert.Equal("test", returnedArticle.Title);
        }