public void GetArticles_ShouldReturnAll() { // Arrange var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); dbContext.Articles.Add(new Article() { Id = 1, Title = "Football", }); dbContext.Articles.Add(new Article() { Id = 2, Title = "Basketball", }); dbContext.Articles.Add(new Article() { Id = 3, Title = "Tennis", }); dbContext.SaveChanges(); var service = new ArticleService(dbContext); // Act var articles = service.GetArticles(); // Assert Assert.AreEqual(3, articles.Count); }
public void UserUnfavouritesATeam_UnfavouritesCorrectly() { var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); dbContext.Teams.Add(new Team { Id = 1, Name = "Liverpool" }); dbContext.SaveChanges(); var team = dbContext.Teams.Find(1); dbContext.Users.Add(new User { Id = "1", UserName = "******", FavouriteTeam = team }); dbContext.SaveChanges(); var service = new TeamService(dbContext); service.UnfavouriteATeam("1", 1); Assert.AreEqual(0, dbContext.Teams.Find(1).Fans.Count); }
public void CreateCategory_AddsCorrectlyName() { var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); var service = new CategoryService(dbContext); service.Create("Football"); Assert.AreEqual(true, dbContext.Categories.Any(c => c.Name == "Football")); }
public void CreateCategory_ShouldCreateCorrectly() { var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); var service = new CategoryService(dbContext); service.Create("Football"); Assert.AreEqual(1, dbContext.Categories.Count()); }
public void GetArticles_ShouldReturnNone() { var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); var service = new ArticleService(dbContext); var articles = service.GetArticles(); Assert.AreEqual(0, articles.Count); }
public void DeleteCategory_RemovesCorrectly() { var options = new DbContextOptionsBuilder <SportsSystemContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var dbContext = new SportsSystemContext(options); dbContext.Categories.Add(new Category { Id = 1, Name = "Football" }); var service = new CategoryService(dbContext); service.Delete(1); Assert.AreEqual(0, dbContext.Categories.Count()); }
public CreateModel(SportsSystemContext context, ICategoryService categories) { this.categories = categories; }
public ArticleService(SportsSystemContext context) : base(context) { }
public UserService(SportsSystemContext context) : base(context) { }
public CategoryService(SportsSystemContext context) : base(context) { }
public TeamService(SportsSystemContext context) : base(context) { }
public VideoService(SportsSystemContext context) : base(context) { }
public Service(SportsSystemContext context) { this.Context = context; }