public void Setup() { // instantiate _revisionManager = new RevisionManager(); // Create User and Project Test Data using (var db = new MonokayuDbContext()) { // create user and project to test db.Add(new User2() { firstName = "PersonNameTest", lastName = "PersonLastNameTest", securityLevel = 0, password = "******" }); db.Add(new Project2() { projectName = "ProjectNameForTesting" }); db.SaveChanges(); } // Set global variables using (var db = new MonokayuDbContext()) { // locate data and obtain ids var userID = db.Users2.Where(u => u.firstName == "PersonNameTest").Where(c => c.lastName == "PersonLastNameTest").FirstOrDefault().UserID; var projectID = db.Projects2.Where(p => p.projectName == "ProjectNameForTesting").FirstOrDefault().ProjectID; // assign users to project using joining table db.Add(new UserProject() { userID = userID, projectID = projectID }); _userIdToTest = userID; _projectIdToTest = projectID; db.SaveChanges(); } //using (var db = new MonokayuDbContext()) //{ // db.Add(new Revision() { ProjectID = _projectIdToTest, deadline = DateTime.Now }); // db.SaveChanges(); //} }
public static void GenerateProjectTestData() { using (var db = new MonokayuDbContext()) { Console.WriteLine("Creating some projects"); db.Add(new Project2 { projectName = "Calculator" }); db.Add(new Project2 { projectName = "Radio" }); db.Add(new Project2 { projectName = "Revision Manager" }); db.SaveChanges(); } }
public (int userIdToTest, int projectIdToTest) GenerateTestDataForUnitTests() { Console.WriteLine("Generating test data"); using (var db = new MonokayuDbContext()) { // query first if exist //var user = db.Users2.Where(u => u.firstName == "PersonNameTest").Where(u => u.lastName == "PersonLastNameTest").FirstOrDefault(); //var project = db.Projects2.Where(p => p.projectName == "ProjectNameForTesting").FirstOrDefault(); //// if exist //if (user != null || project != null) //{ // return (user.UserID, project.ProjectID); //} //else //{ // create user and project to test db.Add(new User2() { firstName = "PersonNameTest", lastName = "PersonLastNameTest", securityLevel = 0, password = "******" }); db.Add(new Project2 { projectName = "ProjectNameForTesting" }); // locate data and obtain ids int userID = db.Users2.Where(u => u.firstName == "PersonNameTest").Where(u => u.lastName == "PersonLastNameTest").FirstOrDefault().UserID; int projectID = db.Projects2.Where(p => p.projectName == "ProjectNameForTesting").FirstOrDefault().ProjectID; // assign users to project db.Add(new UserProject { userID = userID, projectID = projectID }); //save and return db.SaveChanges(); return(userID, projectID); //return (user.UserID, project.ProjectID); //} } } // end of GenerateTestData()
// Inserts a revision given a project public void GenerateRevisionForProjectID(int projectId, DateTime deadline) { using (var db = new MonokayuDbContext()) { db.Add(new Revision() { deadline = deadline, ProjectID = projectId }); db.SaveChanges(); } }
public static void AssignUsersToProjects() { Console.WriteLine("Assiging projects"); using (var db = new MonokayuDbContext()) { // locating test data ids var LorenzoID = db.Users2.Where(u => u.firstName == "Lorenzo").Where(u => u.lastName == "Bulosan").FirstOrDefault().UserID; var CathyID = db.Users2.Where(u => u.firstName == "Cathy").Where(u => u.lastName == "French").FirstOrDefault().UserID; var MartinID = db.Users2.Where(u => u.firstName == "Martin").Where(u => u.lastName == "Beard").FirstOrDefault().UserID; var Project1ID = db.Projects2.Where(p => p.projectName == "Calculator").FirstOrDefault().ProjectID; var Project2ID = db.Projects2.Where(p => p.projectName == "Radio").FirstOrDefault().ProjectID; var Project3ID = db.Projects2.Where(p => p.projectName == "Revision Manager").FirstOrDefault().ProjectID; // assigning users to projects (many to many) // lorenzo -> project1/project3 // cathy -> project1/project2 // martin -> project3 db.Add(new UserProject { userID = LorenzoID, projectID = Project1ID }); db.Add(new UserProject { userID = LorenzoID, projectID = Project3ID }); db.Add(new UserProject { userID = CathyID, projectID = Project1ID }); db.Add(new UserProject { userID = CathyID, projectID = Project2ID }); db.Add(new UserProject { userID = MartinID, projectID = Project3ID }); db.SaveChanges(); } Console.WriteLine("You can close this console now and proceed to wpf app"); }
// methods for testing public static void GenerateRevisionForProjectID(int projectId) { using (var db = new MonokayuDbContext()) { Console.WriteLine($"Creating some Revision for projectID: {projectId}"); db.Add(new Revision() { deadline = new DateTime(), ProjectID = projectId }); db.SaveChanges(); } }
public static void GenerateUserTestData() { using (var db = new MonokayuDbContext()) { Console.WriteLine("Creating some Users"); db.Add(new User2() { firstName = "Lorenzo", lastName = "Bulosan", securityLevel = 0, password = "******" }); db.Add(new User2() { firstName = "Cathy", lastName = "French", securityLevel = 1, password = "******" }); db.Add(new User2() { firstName = "Martin", lastName = "Beard", securityLevel = 1, password = "******" }); db.SaveChanges(); } }
// Insert a task given a revisionID public void AddTaskToRevision(int revisionID, string title, string description, int urgency, int progress = 0, string url = "") { using (var db = new MonokayuDbContext()) { db.Add(new RevisionTask { RevisionID = revisionID, title = title, description = description, urgency = urgency, progress = progress, links = url }); db.SaveChanges(); } }
public void RetrivingRevisionFromProjectReturnsOneMoreThanBeforeWhenAddingOneRevision() { var revisions = _revisionManager.GetRevisionsFromProject(_projectIdToTest); using (var db = new MonokayuDbContext()) { db.Add(new Revision() { deadline = DateTime.Now, ProjectID = _projectIdToTest }); db.SaveChanges(); } var revisionsAfter = _revisionManager.GetRevisionsFromProject(_projectIdToTest); Assert.AreEqual(revisions.Count() + 1, revisionsAfter.Count()); }
// Inserts a comment to an existing task public void AddCommentToTaskID(int taskID, string comment, string senderName) { if (comment != "") { using (var db = new MonokayuDbContext()) { db.Add(new TaskComment { TaskID = taskID, comment = comment, senderName = senderName, time = DateTime.Now });; db.SaveChanges(); } } }