public async Task GetCountShouldReturnTheCorrectCount() { this.Setup(); var repo = new Mock <IDeletableEntityRepository <BlogArticle> >(); repo.Setup(x => x.All()).Returns(this.articleList.AsQueryable()); repo.Setup(x => x.AddAsync(It.IsAny <BlogArticle>())).Callback( (BlogArticle article) => this.articleList.Add(article)); var categoryRepo = new Mock <IDeletableEntityRepository <BlogCategory> >(); var articlesService = new ArticlesService(repo.Object, categoryRepo.Object); await articlesService.CreateAsync(this.testArticle, "testUser"); var count = articlesService.GetCount(); Assert.Equal(1, count); await articlesService.CreateAsync(this.testArticle, "testUser"); count = articlesService.GetCount(); Assert.Equal(2, count); }
public void GetCountShouldReturnCorrectNumber() { var articlesRepository = new Mock <IRepository <Article> >(); articlesRepository.Setup(r => r.All()).Returns(new List <Article> { new Article(), new Article(), new Article(), }.AsQueryable()); var service = new ArticlesService(articlesRepository.Object, null); Assert.Equal(3, service.GetCount()); articlesRepository.Verify(x => x.All(), Times.Once); }
public async Task CreateArticleShouldBeSuccessfull() { var options = new DbContextOptionsBuilder <SportsNewsContext>() .UseInMemoryDatabase(databaseName: "Find_User_Database2") .Options; var dbContext = new SportsNewsContext(options); var repository = new DbRepository <Article>(dbContext); var articlesService = new ArticlesService(repository, null); await articlesService.Create(1, "sdsda", "dasasd"); var count = articlesService.GetCount(); Assert.Equal(1, count); }
public async Task GetCountShouldReturnCorrectNumberUsingDbContext() { var options = new DbContextOptionsBuilder <SportsNewsContext>() .UseInMemoryDatabase(databaseName: "Find_User_Database") .Options; var dbContext = new SportsNewsContext(options); dbContext.Articles.Add(new Article()); dbContext.Articles.Add(new Article()); dbContext.Articles.Add(new Article()); await dbContext.SaveChangesAsync(); var repository = new DbRepository <Article>(dbContext); var articlesService = new ArticlesService(repository, null); var count = articlesService.GetCount(); Assert.Equal(3, count); }