Beispiel #1
0
        public async Task AddFavouritePostShouldWorkCorrectlyAsync()
        {
            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.AddFavouritePostAsync(1, "1");

            await service.AddFavouritePostAsync(2, "1");

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

            Assert.Equal(2, result);
        }
Beispiel #2
0
        public async Task MustReturnTrueWhenArticleIsAddedToFavouriteAsync()
        {
            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.AddFavouritePostAsync(1, "1");

            var result = service.AlreadyAddedAsync(1, "1");

            Assert.True(result.Result);
        }