예제 #1
0
파일: UnitTest1.cs 프로젝트: liamzhou77/LMS
        Team58LMSContext MakeMockDB()
        {
            var optionsBuilder = new DbContextOptionsBuilder <Team58LMSContext>();

            optionsBuilder.UseInMemoryDatabase("mock_db").UseApplicationServiceProvider(NewServiceProvider());
            Team58LMSContext db = new Team58LMSContext(optionsBuilder.Options);

            Departments d = new Departments();

            d.Name    = "School of Computing";
            d.Subject = "CS";
            Departments d2 = new Departments();

            d.Name    = "School of Music";
            d.Subject = "MUSC";
            Departments d3 = new Departments();

            d.Name    = "School of Mathematics";
            d.Subject = "MATH";

            db.Departments.Add(d);
            db.Departments.Add(d2);
            db.Departments.Add(d3);
            db.SaveChanges();

            return(db);
        }
예제 #2
0
        /*******Begin code to modify********/

        private string GenerateUId()
        {
            using (Team58LMSContext db = new Team58LMSContext())
            {
                var maxUId = (from s in db.Students select s.UId)
                             .Union(from p in db.Professors select p.UId)
                             .Union(from a in db.Administrators select a.UId)
                             .DefaultIfEmpty("u0000000")
                             .Max();
                int i = 0;
                if (int.TryParse(maxUId.Substring(1), out i))
                {
                    i++;
                    return("u" + i.ToString().PadLeft(7, '0'));
                }
                return(null);
            }
        }
예제 #3
0
        /*
         * WARNING: This is the quick and easy way to make the controller
         *          use a different LibraryContext - good enough for our purposes.
         *          The "right" way is through Dependency Injection via the constructor
         *          (look this up if interested).
         */

        // (Done)TODO: Uncomment and change 'X' after you have scaffoled

        public void UseLMSContext(Team58LMSContext ctx)
        {
            db = ctx;
        }
예제 #4
0
 public CommonController()
 {
     db = new Team58LMSContext();
 }