public async Task AllHomeNewsAsyncShouldRerutnCorectedOrderedNewsArticles() { //Arrange var dbOptions = new DbContextOptionsBuilder <UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var accountService = new AccountService(db); var user = new User { Id = "1", UserName = "******" }; db.AddRange(user); await db.SaveChangesAsync(); //Act var result = await accountService.ProfileByUsername("UserUsername"); //Assert result.Username .Should() .Equals("UserUsername"); }
public async Task BySectionIdAsyncReturnsTheRightAnswerOrderedProperly() { //Arrange var dbOptions = new DbContextOptionsBuilder <UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var themesService = new ThemesService(db); var firstTheme = new ForumTheme { Id = 1, PublishedDate = DateTime.UtcNow, ForumSectionId = 1 }; var secondTheme = new ForumTheme { Id = 2, PublishedDate = DateTime.UtcNow.AddDays(-1), ForumSectionId = 1 }; var thirdTheme = new ForumTheme { Id = 3, IsDeleted = true, ForumSectionId = 1 }; var fourthTheme = new ForumTheme { Id = 4, ForumSectionId = 2 }; db.AddRange(firstTheme, secondTheme, thirdTheme, fourthTheme); await db.SaveChangesAsync(); //Act var result = await themesService .BySectionIdAsync(1); //Assert result .Should() .Match (r => r.ElementAt(0).Id == 2 && r.ElementAt(1).Id == 1) .And .HaveCount(2); }
public async Task AllHomeNewsAsyncShouldRerutnCorectedOrderedNewsArticles() { //Arrange var dbOptions = new DbContextOptionsBuilder <UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var newsService = new NewsService(db); var firstNewsArticle = new NewsArticle { Id = 1, Title = "First Article", PublishedDate = DateTime.UtcNow.AddDays(-1), ArticleType = ArticleType.Interviews }; var secondNewsArticle = new NewsArticle { Id = 2, Title = "Second Article", PublishedDate = DateTime.UtcNow.AddHours(1), ArticleType = ArticleType.Interviews }; var thirdNewsArticle = new NewsArticle { Id = 3, Title = " Third Article", PublishedDate = DateTime.UtcNow, ArticleType = ArticleType.History }; db.AddRange(firstNewsArticle, secondNewsArticle, thirdNewsArticle); await db.SaveChangesAsync(); //Act var result = await newsService.AllHomeNewsAsync(); //Assert result .Should() .Match (r => r.ElementAt(0).Id == 2 && r.ElementAt(1).Id == 3 && r.ElementAt(2).Id == 1) .And .HaveCount(3); }
public async Task ByThemeIdAsyncShouldReturnCorrectAnswerAndOrderCorrectly() { //Arrange var dbOptions = new DbContextOptionsBuilder <UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var articleService = new ArticleService(db); var firstArticle = new ForumArticle { Id = 2, PublishedDate = DateTime.UtcNow, ForumThemeId = 1 }; var secondArticle = new ForumArticle { Id = 3, PublishedDate = DateTime.UtcNow.AddDays(-1), ForumThemeId = 1 }; var thirdArticle = new ForumArticle { Id = 4, PublishedDate = DateTime.UtcNow, ForumThemeId = 2 }; db.AddRange(firstArticle, secondArticle, thirdArticle); await db.SaveChangesAsync(); //Act var result = await articleService.ByThemeIdAsync(1, 1); //Assert result .Should() .Match (r => r.ElementAt(0).Id == 3 && r.ElementAt(1).Id == 2) .And .HaveCount(2); }
public async Task <bool> Create(string title, string description) { if (title == null || description == null) { return(false); } var section = new ForumSection { Tittle = title, Description = description }; db.Add(section); await db.SaveChangesAsync(); return(true); }
public async Task AllAsyncShouldReturnCorrectAnswerAndOrderedProperly() { //Arrange var dbOptions = new DbContextOptionsBuilder<UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var sectionsService = new SectionsService(db); var firtSection = new ForumSection { Id = 1, Tittle = "b" }; var secondSection = new ForumSection { Id = 2, Tittle = "a" }; db.AddRange(firtSection, secondSection); await db.SaveChangesAsync(); //Act var result = await sectionsService .AllAsync(); //Assert result .Should() .Match (r => r.ElementAt(0).Id == 2 && r.ElementAt(1).Id == 1) .And .HaveCount(2); }
public async Task CreateCreatesSuccesssully() { //Arrange var dbOptions = new DbContextOptionsBuilder <UndergroundStationDbContext>() .UseInMemoryDatabase("UndergroundStationTestDb") .Options; var db = new UndergroundStationDbContext(dbOptions); var articleService = new ArticleService(db); await db.SaveChangesAsync(); //Act var success = await articleService .CreateAsync("Title", "Content", "1", 2, DateTime.UtcNow, 1); //Assert success .Should() .Equals(true); }