Beispiel #1
0
        public async Task UpdateShouldWorkCorrectlyAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryArticle              = new EfDeletableEntityRepository <Article>(dbContext);
            var repositoryArticlePicture       = new EfRepository <ArticlePicture>(dbContext);
            var repositoryUserFavouriteArticle = new EfDeletableEntityRepository <UserFavouriteArticle>(dbContext);

            var service = new ArticlePostsService(repositoryArticle, repositoryArticlePicture, repositoryUserFavouriteArticle);

            var articleId = await service.CreateAsync("test", "test", "1", 1);

            var article = new Article
            {
                Id         = articleId,
                Title      = "TestTwo",
                Content    = "TestTwo",
                UserId     = "1",
                CategoryId = 1,
            };

            var result = await service.UpdateAsync(article);

            Assert.Equal(article, result);
        }
Beispiel #2
0
        public async Task CreateArticleShouldWorkCorrectlyAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryArticle              = new EfDeletableEntityRepository <Article>(dbContext);
            var repositoryArticlePicture       = new EfRepository <ArticlePicture>(dbContext);
            var repositoryUserFavouriteArticle = new EfDeletableEntityRepository <UserFavouriteArticle>(dbContext);

            var service = new ArticlePostsService(repositoryArticle, repositoryArticlePicture, repositoryUserFavouriteArticle);

            await service.CreateAsync("test", "test", "1", 1);

            await service.CreateAsync("testTwo", "testTwo", "1", 2);

            var result = repositoryArticle.All().Count();

            Assert.Equal(2, result);
        }
Beispiel #3
0
        public async Task ReturnFalseIfUserIsOwnerOfArticleAsync()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var repositoryArticle              = new EfDeletableEntityRepository <Article>(dbContext);
            var repositoryArticlePicture       = new EfRepository <ArticlePicture>(dbContext);
            var repositoryUserFavouriteArticle = new EfDeletableEntityRepository <UserFavouriteArticle>(dbContext);

            var service = new ArticlePostsService(repositoryArticle, repositoryArticlePicture, repositoryUserFavouriteArticle);

            var articleId = await service.CreateAsync("test", "test", "1", 1);

            var isTrue = await service.ExistsAsync(articleId, "2");

            Assert.False(isTrue);
        }