Example #1
0
        public void GetCourseRoleAsStudent()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string password = "******"; //We have only one password for all test accounts
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            Course[] courses = osbleService.GetCourses(authToken);

            CourseRole courseRole = osbleService.GetCourseRole(courses[0].ID, authToken);

            Assert.NotNull(courseRole);

            //No Nunit display
            Console.WriteLine("Returned Course Role ID: " + courseRole.ID);
            Console.WriteLine("Returned Course Role Name: " + courseRole.Name);
            Console.WriteLine("Returned Course Role Permissions : CanUploadFiles = " + courseRole.CanUploadFiles);
            Console.WriteLine("                                   CanGrade       = " + courseRole.CanGrade);
            Console.WriteLine("                                   CanModify      = " + courseRole.CanModify);
            Console.WriteLine("                                   CanSeeAll      = " + courseRole.CanSeeAll);
            Console.WriteLine("                                   CanSubmit      = " + courseRole.CanSubmit);

            StringAssert.AreEqualIgnoringCase("Student", courseRole.Name);
            Assert.IsFalse(courseRole.CanGrade);
            Assert.IsFalse(courseRole.CanUploadFiles);
            Assert.IsFalse(courseRole.CanModify);
            Assert.IsFalse(courseRole.CanSeeAll);
            Assert.IsTrue(courseRole.CanSubmit);

            Console.WriteLine("GetCoureRoleAsStudent() Assert(s) was successful.");
        }
Example #2
0
        public void SubmitAssignmentCorrectlyTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string password = "******"; //We have only one password for all test accounts
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            int assignmentID = 0;
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            //Get the file in a zip object
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\deliverable_zip.zip");
            file.AddEntry("hw1.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //We are looking for A3...
                if (assignment.AssignmentName == "A3 due Dec 25 by 11:55 PM")
                {
                    assignmentID = assignment.ID;
                }
            }

            bool result = osbleService.SubmitAssignment(assignmentID, zippedFile.ToArray(), authToken);
            Assert.AreEqual(true, result);
            Console.WriteLine("SubmitAssignmentCorrectlyTest() Assert(s) was successful.");
        }
Example #3
0
        private void RefreshProc()
        {
            // First login
            AuthenticationServiceClient authClient = new AuthenticationServiceClient();
            string authToken = null;

            try
            {
                authToken = authClient.ValidateUser(m_user, m_pass);
            }
            catch (System.ServiceModel.EndpointNotFoundException)
            {
                authClient.Close();
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "Could not connect to the OSBLE server. " +
                                                           "Please contact support if this problem persists."));
                return;
            }
            authClient.Close();
            authClient = null;

            if (string.IsNullOrEmpty(authToken))
            {
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "Could not log in to OSBLE. " +
                                                           "Please check your user name and password."));
                return;
            }

            // Now get a list of courses
            OsbleServiceClient osc = new OsbleServiceClient();

            m_courses = osc.GetCourses(authToken);

            // Make sure we got some courses
            if (null == m_courses || 0 == m_courses.Length)
            {
                m_onComplete(this, new OSBLEStateEventArgs(false,
                                                           "No courses were found for this user."));
                return;
            }

            // Go through the courses and find out this user's role
            List <Course> canBeGraded = new List <Course>();

            foreach (Course c in m_courses)
            {
                CourseRole cr = osc.GetCourseRole(c.ID, authToken);
                if (cr.CanGrade)
                {
                    canBeGraded.Add(c);
                }
            }
            m_courses = canBeGraded.ToArray();

            // Success if we made it this far
            m_onComplete(this, new OSBLEStateEventArgs(true, string.Empty));
        }
Example #4
0
        private void OSBLESubmitReviewCompleted(object sender, SubmitReviewCompletedEventArgs e)
        {
            object[]           args           = e.UserState as object[];
            OsbleServiceClient osc            = args[0] as OsbleServiceClient;
            EventHandler       onSaveComplete = args[1] as EventHandler;

            // We're done with the OSBLE client and can close it
            osc.CloseAsync();

            onSaveComplete(this, new SaveEventArgs(null == e.Error && e.Result));
        }
Example #5
0
        public void DeleteSubmissionTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            UploaderWebServiceClient uploader = new UploaderWebServiceClient();
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password);
            Course[] courses = osbleService.GetCourses(authToken);

            //student doesn't have delete permissions Student role cannot modify
            bool result = uploader.DeleteFile("hw1.zip", courses[0].ID, authToken);
            Assert.IsFalse(result);
            Console.WriteLine("DeleteSubmissionTest() Assert(s) was successful.");
        }
Example #6
0
        private void AuthForSaveCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            object[] args = e.UserState as object[];
            AuthenticationServiceClient authClient = args[0] as AuthenticationServiceClient;
            EventHandler onSaveComplete            = args[1] as EventHandler;

            byte[] zippedData       = args[2] as byte[];
            int    originalAuthorID = (int)args[3];

            // If we failed then there's not much we can do
            if (null != e.Error || e.Cancelled)
            {
                // Invoke the completion delegate and return
                onSaveComplete(this, new SaveEventArgs(false));
                return;
            }

            string authToken = e.Result;

            m_lastAuthToken = authToken;

            // Build the OSBLE service client
            m_osbleClient = new OsbleServiceClient();
            m_osbleClient.OpenCompleted += delegate(object sender2, System.ComponentModel.AsyncCompletedEventArgs e2)
            {
                // How we save depends on the assignment type
                if (AssignmentTypes.CriticalReview == m_a.Type)
                {
                    // For critical reviews we use SubmitReviewAsync. According to the OSBLE team, when you call this
                    // you give it a zip file that contains a single file that is the review document. Recall that when
                    // we retrieve the files for a review assignment it's a zip of zips, and each file to review is
                    // within its own "child" zip under the main "parent" zip. This is NOT something we have to deal
                    // with here. We just submit the review file and we're done.
                    m_osbleClient.SubmitReviewCompleted += new EventHandler <SubmitReviewCompletedEventArgs>(OSBLESubmitReviewCompleted);
                    m_osbleClient.SubmitReviewAsync(originalAuthorID, m_a.ID, zippedData, authToken,
                                                    new object[] { m_osbleClient, onSaveComplete });
                }
                else
                {
                    // It's assumed that the assignment type is "Basic" if we come here
                    // For basic assignments we just use the SubmitAssignmentAsync method
                    m_osbleClient.SubmitAssignmentCompleted += this.OSBLESubmitAssignmentCompleted;
                    m_osbleClient.SubmitAssignmentAsync(m_a.ID, zippedData, authToken, new object[] { m_osbleClient, onSaveComplete });
                }
            };
            m_osbleClient.OpenAsync();

            // We're done with the authentication client
            authClient.CloseAsync();
        }
Example #7
0
        private void GetReviewItemsCompleted(object sender, GetReviewItemsCompletedEventArgs e)
        {
            object[]           args         = e.UserState as object[];
            OsbleServiceClient client       = args[0] as OsbleServiceClient;
            EventHandler       onCompletion = args[1] as EventHandler;

            if (null == e.Error && !e.Cancelled)
            {
                AddFromZip(e.Result);
            }

            client.CloseAsync();
            m_gettingFiles = false;
            onCompletion(this, new RelevantAssignmentEventArgs(m_files));
        }
Example #8
0
        private void OsbleClient_GetCoursesCompleted(object sender, GetCoursesCompletedEventArgs e)
        {
            OsbleServiceClient osbleClient = e.UserState as OsbleServiceClient;

            try
            {
                m_courses = e.Result;
            }
            catch (Exception)
            {
                OnError(this, new OSBLEStateEventArgs(false,
                                                      "Could not get list of courses for this user. You may need to contact your professor " +
                                                      "or systems administrator to remedy this."));
                osbleClient.CloseAsync();
                return;
            }

            // If we don't have any courses then let the user know
            if (0 == m_courses.Count)
            {
                OnError(this, new OSBLEStateEventArgs(false,
                                                      "No courses were found for this user. You may need to contact your professor " +
                                                      "or systems administrator to remedy this."));
                return;
            }

            // Loading the course list does not load their child lists of assignments.
            // We need to do that now.
            osbleClient.GetCourseAssignmentsCompleted += OsbleClient_GetCourseAssignmentsCompleted;
            m_coursesRemaining = 0;
            foreach (Course course in m_courses)
            {
                try
                {
                    osbleClient.GetCourseAssignmentsAsync(course.ID, m_authToken, course);
                    Interlocked.Increment(ref m_coursesRemaining);
                }
                catch (Exception) { }
            }
        }
Example #9
0
        public void GetCoursesTest()
        {
            // Variable declarations
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string[] expectedClasses = { "422 SE Principles II", "Fake 322" };
            int[] expectedCourseCount = { 0, 1, 1, 2, 2 };
            List<Course[]> receivedClasses = new List<Course[]>();
            List<string> uNames = new List<string>();
            string receivedAuthToken;
            string password = "******";

            //Create a table of user names
            for (int i = 1; i < 6; i++)
            {
                uNames.Add("osble.test.group" + i + "@gmail.com");
            }

            //Receive an AuthToken, then immediately call GetCourses with that AuthToken
            //Store the Class[] in a List
            for (int i = 0; i < 5; i++)
            {
                receivedAuthToken = CommonTestLibrary.OsbleLogin(uNames[i], password);
                receivedClasses.Add(osbleService.GetCourses(receivedAuthToken));
            }

            //Loop through the classes
            for (int i = 0; i < 5; i++)
            {
                //Assert that the number of classes are equal
                Assert.AreEqual(expectedCourseCount[i], receivedClasses[i].Length);
                for (int j = 0; j < expectedCourseCount[i]; j++)
                {
                    //Assert the strings are equal
                    StringAssert.AreEqualIgnoringCase(expectedClasses[j], receivedClasses[i][j].Name);
                }
            }

            Console.WriteLine("GetCoursesTest() Assert(s) was successful.");
        }
Example #10
0
        public void SubmitAssignmentLateTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string password = "******"; //We have only one password for all test accounts
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            int assignmentID = 0;
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            //Get the file in a zip object
            Console.WriteLine("Zipping file...\n");
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\deliverable_txt.txt");
            file.AddEntry("hw1.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);
            Console.WriteLine("File zipped.\n");

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //Find a passed due assignment
                if (assignment.AssignmentName == "A1 due Nov 4 by 6 PM")
                {
                    assignmentID = assignment.ID;
                }
            }

            Console.WriteLine("Attempting to submit assignment now...\n");

            bool result = osbleService.SubmitAssignment(assignmentID, zippedFile.ToArray(), authToken);
            // SubmitAssignment should return false
            Assert.AreEqual(false, result, "OSBLE accepted assignment late when it should not.");
            Console.WriteLine("SubmitAssignmentLateTest() Assert(s) successful. Assignment was not submitted.");
        }
Example #11
0
        public void SubmitGradebookAsStudent()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            int assignmentID = 0;
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            //Get the file in a zip object
            Console.WriteLine("Zipping file...\n");
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\review.xlsx");
            file.AddEntry("review.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);
            Console.WriteLine("File zipped.\n");

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //We are looking for A3...
                if (assignment.AssignmentName == "A3 due Dec 25 by 11:55 PM")
                {
                    assignmentID = assignment.ID;
                    Console.WriteLine("Successfully found assignment.\n");
                }
            }

            int result = osbleService.UploadCourseGradebook(courses[0].ID, zippedFile.ToArray(), authToken);
            Assert.AreEqual(-1, result);
            Console.WriteLine("SubmitGradebookAsStudent() Assert(s) was successful.");
        }
Example #12
0
        public void VerifyAssignmentContentsTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string password = "******"; //We have only one password for all test accounts
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            int assignmentID = 0;
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            //Get the file in a zip object
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\deliverable_zip.zip");
            file.AddEntry("hw1.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //We are looking for A3...
                if (assignment.AssignmentName == "A3 due Dec 25 by 11:55 PM")
                {
                    assignmentID = assignment.ID;
                }
            }

            // Retrieve the assignment

            byte[] expected = zippedFile.ToArray();
            byte[] results = osbleService.GetAssignmentSubmission(assignmentID, authToken);

            Console.WriteLine("Expected Length: " + expected.Length + "\nActual Length: " + results.Length);

            Assert.AreEqual(expected.Length, results.Length);
            for (int i = 70; i < expected.Length - 100; i++)
            {
                Assert.AreEqual(expected[i], results[i]);
            }
            Console.WriteLine("VerifyAssignmentContentsTest() Assert(s) was successful.");
        }
Example #13
0
        public void SubmitAssignmentWrongClassTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string password = "******"; //We have only one password for all test accounts
            // Student that is in class 422
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password);

            // Student that is not in class 422
            string authToken2 = CommonTestLibrary.OsbleLogin("*****@*****.**", password);

            int assignmentID = 0;

            // get the assignments for course 422
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            Console.WriteLine("Zipping file...\n");
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\deliverable_txt.txt");
            file.AddEntry("hw1.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);
            Console.WriteLine("File zipped.\n");

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //Find a passed due assignment
                if (assignment.AssignmentName == "A2 due Nov 6 by 2 PM")
                {
                    assignmentID = assignment.ID;
                }
            }

            Console.WriteLine("Attempting to submit assignment now...\n");

            // the student that was not in 422 is submitting to the assignment ID for an assignment in class 422
            bool result = osbleService.SubmitAssignment(assignmentID, zippedFile.ToArray(), authToken2);
            // SubmitAssignment should return false
            Assert.AreEqual(false, result, "OSBLE accepted assignment to wrong class when it should not.");
            Console.WriteLine("SubmitAssignmentWrongClassTest() Assert(s) was successful. Assignment was not submitted.");
        }
Example #14
0
        public void SubmitAssignmentOverSizeLimitTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password); //Use our OsbleLogin() function from our common test library to retrieve auth tokens
            int assignmentID = 0;
            Course[] courses = osbleService.GetCourses(authToken);
            Assignment[] assignments = osbleService.GetCourseAssignments(courses[0].ID, authToken);

            //Get the file in a zip object
            Console.WriteLine("Zipping file...\n");
            ZipFile file = new ZipFile();
            FileStream stream = File.OpenRead(startDirectory + "\\Test Assignments\\deliverable_zip_large.zip");
            file.AddEntry("hw1.zip", stream);
            MemoryStream zippedFile = new MemoryStream();
            file.Save(zippedFile);
            Console.WriteLine("File zipped.\n");

            //For each assignment in assignments...
            foreach (Assignment assignment in assignments)
            {
                //We are looking for A3...
                if (assignment.AssignmentName == "A3 due Dec 25 by 11:55 PM")
                {
                    assignmentID = assignment.ID;
                    Console.WriteLine("Successfully found assignment.\n");
                }
            }

            Console.WriteLine("Attempting to submit assignment now...\n");

            bool result = osbleService.SubmitAssignment(assignmentID, zippedFile.ToArray(), authToken);
            Assert.AreEqual(false, result, "OSBLE accepted oversize assignment when it should not.");
            Console.WriteLine("SubmitAssignmentOverSizeLimitTest() Assert(s) successful. Assignment was not submitted.");
        }
Example #15
0
        private void ValidateForSaveCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            // Error check
            if (e.Cancelled)
            {
                return;
            }
            if (null != e.Error)
            {
                OnError(this, new OSBLEStateEventArgs(false, e.Error.Message));
                return;
            }

            // The authentication token is stored in the result
            m_authToken = e.Result;

            // Build the OSBLE client
            //m_osbleClient = new OsbleServiceClient(m_bind,
            //    new System.ServiceModel.EndpointAddress(OSBLEServiceLink));
            m_osbleClient = new OsbleServiceClient();
            m_osbleClient.SubmitAssignmentCompleted += this.OsbleClient_SubmitAssignmentCompleted;

            // We built an object array for the user state to keep track of the authentication client
            // (which we have to close at the end) and the save data
            object[] objs = e.UserState as object[];

            // The authentication client is the first object in the array
            AuthenticationServiceClient auth = objs[0] as AuthenticationServiceClient;

            // The assignment data is the second object in the array. Note that this is the uncompressed data
            // and we need to put it in a zip before submitting.
            byte[] assignmentData = objs[1] as byte[];

            // Create a memory stream to save the zip file to
            MemoryStream ms = new MemoryStream();

            // Create the zip output stream with the maximum level of compression
            ZipOutputStream zos = new ZipOutputStream(ms);

            zos.SetLevel(9);

            // Create the entry for this file
            ZipEntry newEntry = new ZipEntry(ZipEntry.CleanName(GetDeliverableFileName(m_currentAssignment)));

            newEntry.DateTime = DateTime.Now;
            zos.PutNextEntry(newEntry);
            zos.Write(assignmentData, 0, assignmentData.Length);
            zos.CloseEntry();

            // Flush the zip file
            zos.Flush();

            // Get a reference to the compressed data
            byte[] compressed = ms.ToArray();

            // Close the zip file
            zos.Close();

            // We will reuse the array for our next async call, this time with the OSBLE client as the
            // first object
            objs[0] = m_osbleClient;

            // Submit
            m_osbleClient.SubmitAssignmentAsync(m_currentAssignment.ID, ms.ToArray(), m_authToken);

            // Free memory
            zos.Dispose();
            ms.Dispose();

            // "Always close the client" says the documentation
            auth.CloseAsync();
        }
Example #16
0
        public void PostMessageTest()
        {
            OsbleServiceClient osbleService = new OsbleServiceClient();
            UploaderWebServiceClient uploader = new UploaderWebServiceClient();
            string authToken = CommonTestLibrary.OsbleLogin("*****@*****.**", password);
            Course[] courses = osbleService.GetCourses(authToken);
            bool result = uploader.PostActivityMessage("This", courses[0].ID, authToken);

            Assert.IsTrue(result);
            Console.WriteLine("PostMessageTest() Assert(s) was successful.");
        }
Example #17
0
        private void AuthForLoadCompleted(object sender, ValidateUserCompletedEventArgs e)
        {
            object[] args = e.UserState as object[];
            AuthenticationServiceClient authClient = args[0] as AuthenticationServiceClient;

            // If we failed then there's not much we can do
            if (null != e.Error || e.Cancelled)
            {
                m_gettingFiles = false;

                // Invoke the completion delegate
                (args[1] as EventHandler)(this, new RelevantAssignmentEventArgs(m_files));

                return;
            }

            string authToken = e.Result;

            m_lastAuthToken = authToken;

            // The last thing we do with the authentication client is get the active user
            authClient.GetActiveUserCompleted += new EventHandler <GetActiveUserCompletedEventArgs>(AuthClient_GetActiveUserCompleted);
            authClient.GetActiveUserAsync(authToken, authClient);

            OsbleServiceClient osc = new OsbleServiceClient();

            // What we query for depends on the assignment type
            args[0] = osc;
            if (AssignmentTypes.CriticalReview == m_a.Type)
            {
                // We need to use "GetReviewItems"
                osc.GetReviewItemsCompleted += new EventHandler <GetReviewItemsCompletedEventArgs>(GetReviewItemsCompleted);
                try
                {
                    osc.GetReviewItemsAsync(m_a.ID, authToken, args);
                }
                catch (Exception)
                { }
            }
            else if (AssignmentTypes.CriticalReviewDiscussion == m_a.Type)
            {
                // We need to use "GetMergedReviewDocument"
                osc.GetMergedReviewDocumentCompleted += new EventHandler <GetMergedReviewDocumentCompletedEventArgs>(GetMergedReviewDocumentCompleted);
                try
                {
                    osc.GetMergedReviewDocumentAsync(m_a.ID, authToken, args);
                }
                catch (Exception)
                { }
            }
            else
            {
                // We need to use "GetAssignmentSubmission"
                osc.GetAssignmentSubmissionCompleted += new EventHandler <GetAssignmentSubmissionCompletedEventArgs>(GetAssignmentSubmissionCompleted);
                try
                {
                    osc.GetAssignmentSubmissionAsync(m_a.ID, authToken, args);
                }
                catch (Exception) { }
            }
        }