示例#1
0
文件: Tests.cs 项目: robertstoe/SPA
        public void SetProjectTest()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            ManagementController managementController = new ManagementController();

            managementController.AddUser("stoe", "password", "stoenica", "robert", 1960718162021, "*****@*****.**", "admin");
            managementController.AddProject("project", false);
            managementController.SetProject("stoe", "project");
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            dbContext.SaveChanges();
            List <Student.Models.User> user = dbContext.Users.Where(m => m.Username == "stoe").ToList();

            List <Student.Models.Project> project = dbContext.Projects.Where(m => m.Name == "project").ToList();

            var projectID = project[0].ID;
            var userID    = user[0].ID;
            List <Student.Models.Users_Projects> projects = dbContext.UsersProjects.Where(m => m.ProjectID == projectID && m.UserID == userID).ToList();
            var firstProjectID = projects[0].ProjectID;
            var firstUserID    = projects[0].UserID;

            Assert.Equal(firstProjectID, projectID);
            Assert.Equal(firstUserID, userID);
            dbContext.UsersProjects.Remove(projects[0]);
            dbContext.Projects.Remove(project[0]);
            var uid  = user[0].ID;
            var role = dbContext.Roles.Where(r => r.UserID == uid).ToList()[0];

            dbContext.Roles.Remove(role);
            dbContext.Users.Remove(user[0]);
            dbContext.SaveChanges();
            dbContext.Dispose();
        }
示例#2
0
文件: Tests.cs 项目: robertstoe/SPA
        public void DeleteProjectTest()
        {
            var appDataDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "C:\\Users\\Claudiu Sirbu\\source\\repos\\SE\\Student\\App_Data");

            AppDomain.CurrentDomain.SetData("DataDirectory", appDataDir);
            ManagementController managementController = new ManagementController();

            managementController.AddProject("project", false);
            Student.Models.ApplicationDbContext dbContext = Models.ApplicationDbContext.Create();
            List <Student.Models.Project>       projects  = dbContext.Projects.Where(m => m.Name == "project").ToList();
            var ID = projects[0].ID;

            dbContext.Projects.Remove(projects[0]);
            dbContext.SaveChanges();
            List <Student.Models.Project> list = dbContext.Projects.Where(m => m.ID == ID).ToList();
            var count = list.Count;

            Assert.Equal(count, 0);
            if (list.Count != 0)
            {
                dbContext.Projects.Remove(list[0]);
                dbContext.SaveChanges();
            }
            dbContext.Dispose();
        }