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);
        }
Exemple #2
0
        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);
        }