예제 #1
0
 public bool SaveChanges()
 {
     try
     {
         return(_db.SaveChanges() > 1);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
예제 #2
0
        void AddEmployee()
        {
            var provider       = services.BuildServiceProvider();
            var cs             = "Server=.;Database=EMPSYSDB;Integrated Security=True;";
            var optionsBuilder = new DbContextOptionsBuilder <AppContext>();

            optionsBuilder.UseSqlServer(cs);

            var _ctx = new AppContext(optionsBuilder.Options);
            // Arrange
            Employee employee = GenerateOneEmployee();

            _ctx.Employees.Add(employee);

            // Act
            _ctx.SaveChanges();
            var DbEmployees = _ctx.Employees.ToList();

            // Assert
            Assert.Contains(employee, DbEmployees);
        }