public async Task GetArticleById() { 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 article = new Article { Id = 1, Title = "Test", Content = "Test", CategoryId = 1, UserId = "1", }; await repositoryArticle.AddAsync(article); await repositoryArticle.SaveChangesAsync(); AutoMapperConfig.RegisterMappings(typeof(ArticleByIdTestViewModel).GetTypeInfo().Assembly); var service = new ArticlePostsService(repositoryArticle, repositoryArticlePicture, repositoryUserFavouriteArticle); var articleResult = await service.GetByIdAsync <ArticleByIdTestViewModel>(article.Id); Assert.Equal(article.Id, articleResult.Id); }
public async Task GetAllFavouritePostAsyncShouldReturnCorrectCount() { 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 userFavouriteArticle = new UserFavouriteArticle { ArticleId = 1, UserId = "1", }; await repositoryUserFavouriteArticle.AddAsync(userFavouriteArticle); await repositoryUserFavouriteArticle.SaveChangesAsync(); AutoMapperConfig.RegisterMappings(typeof(GetAllFavouritePostTestViewModel).GetTypeInfo().Assembly); var service = new ArticlePostsService(repositoryArticle, repositoryArticlePicture, repositoryUserFavouriteArticle); var posts = await service.GetAllFavouritePostAsync <GetAllFavouritePostTestViewModel>(userFavouriteArticle.UserId); Assert.Equal(1, posts.Count()); }
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); }
public async Task MustReturnFalseWhenArticleIsAddedToFavouriteAsync() { 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 result = await service.AlreadyAddedAsync(1, "1"); Assert.False(result); }
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); }
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); }