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

            using var dbContext = new ElectricTravelDbContext(options);

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

            var article = new ArticleInputViewModel();

            article = null;

            var isCreated = await service.CreateAsync(article);

            Assert.True(!isCreated);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(ArticleInputViewModel article)
        {
            var userId = this.userManager.GetUserId(this.User);

            article.UserId = userId;

            if (!this.ModelState.IsValid)
            {
                return(this.View(article));
            }

            var isCreated = await this.articlesService.CreateAsync(article);

            if (!isCreated)
            {
                this.ViewData["Message"] = "Something is wrong. Article can not be created.";
            }

            return(this.RedirectToAction(nameof(this.Index)));
        }
Exemplo n.º 3
0
        public async Task <bool> CreateAsync(ArticleInputViewModel input)
        {
            if (input == null)
            {
                return(false);
            }

            var article = new Article()
            {
                ShortDescription = input.ShortDescription,
                Content          = input.Content,
                CreatedById      = input.UserId,
                Title            = input.Title,
                Path             = input.Path,
            };

            await this.articleRepository.AddAsync(article);

            await this.articleRepository.SaveChangesAsync();

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

            using var dbContext = new ElectricTravelDbContext(options);

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

            var article = new ArticleInputViewModel()
            {
                ShortDescription = "DDDDDSASDSASD",
                Content          = "DDDDDSASDSASD",
                UserId           = "goshoasd",
                Title            = "DDDDDASDASDS",
            };

            var isCreated = await service.CreateAsync(article);

            Assert.True(isCreated);
        }
Exemplo n.º 5
0
        public IActionResult Create()
        {
            var input = new ArticleInputViewModel();

            return(this.View(input));
        }