Пример #1
0
        // TODO: it should be only authors
        public async Task <ArticleDetailsDto> CreateArticle([FromBody] CreateOrEditArticleDto dto)
        {
            Article article = await _articlesService.Create(dto.Title, dto.Description, dto.Body,
                                                            await _usersService.GetCurrentUserAsync(), dto.Tags);

            return(ArticleDetailsDto.Build(article));
        }
Пример #2
0
        public async Task AddMultipleArticles_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);

            // Act
            await articlesService.Create(new Article { Title = "TestTitle2", Content = "TestContent2" });

            await articlesService.Create(new Article { Title = "TestTitle3", Content = "TestContent3" });

            await articlesService.Create(new Article { Title = "TestTitle4", Content = "TestContent4" });

            var articles = this.dbContext.Articles;

            // Assert
            Assert.AreEqual(3, articles.Count());
        }
Пример #3
0
        public async Task AddSingleArticle_Test()
        {
            // Arrange
            var articlesService = new ArticlesService(this.dbContext);

            // Act
            await articlesService.Create(new Article { Title = "TestTitle", Content = "TestContent" });

            var articles = this.dbContext.Articles;

            // Assert
            Assert.AreEqual(1, articles.Count());
        }
Пример #4
0
        public async Task DeleteArticleShouldBeSuccessfull()
        {
            var options = new DbContextOptionsBuilder <SportsNewsContext>()
                          .UseInMemoryDatabase(databaseName: "Find_User_Database3")
                          .Options;

            var dbContext       = new SportsNewsContext(options);
            var repository      = new DbRepository <Article>(dbContext);
            var articlesService = new ArticlesService(repository, null);

            await articlesService.Create(1, "sdsda", "dasasd");

            await articlesService.Create(1, "sdsda", "dasasd");

            await articlesService.Create(1, "sdsda", "dasasd");

            var id = repository.All().FirstOrDefault().Id;
            await articlesService.Delete(id);

            var count = repository.All().Count();

            Assert.Equal(2, count);
        }
        public void Create_IncreasesCount()
        {
            // Arrange
            var context         = this.ServiceProvider.GetRequiredService <WmipDbContext>();
            var articlesService = new ArticlesService(context);
            var creationInfo    = new CreatePostDto()
            {
                Title = "article1"
            };

            // Act
            var result = articlesService.Create(creationInfo);

            //Assert
            Assert.True(result);
            Assert.Single(context.Articles);
        }
Пример #6
0
 public ActionResult Create(ArticleViewModel articleViewModel)
 {
     articlesService.Create(articleViewModel);
     return(Json(new[] { articleViewModel }));
 }