示例#1
0
        public void RemoveTeam_Test()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <TeamContext>().UseInMemoryDatabase($"TeamContext_{ Guid.NewGuid() }").Options;

            using (var context = new TeamContext(options))
            {
                context.Add(new Team()
                {
                    Id               = 1,
                    City             = "Chicago",
                    Name             = "Chicago Fire",
                    DateOfFoundation = DateTime.Now
                });

                context.Add(new Team()
                {
                    Id               = 2,
                    City             = "Los Angeles",
                    Name             = "Los Angeles Galaxy",
                    DateOfFoundation = DateTime.Now
                });

                context.SaveChanges();

                var repository = new TeamsRepository(context);

                //Act
                repository.RemoveTeam(1);
                var teams = repository.GetTeams().ToList();

                //Assert
                Assert.Equal(1, teams.Count);
            }
        }