예제 #1
0
        private bool TryExtractRole(string source, out ContextRole role)
        {
            var roleFound = true;

            role = default(ContextRole);

            do
            {
                // Parse cases like lism:<role>
                int start = source.IndexOf(':') + 1;
                if (Enum.TryParse(source.Substring(start), out role))
                {
                    break;
                }

                // Parse cases like urn: urn:lti:role:ims/lis/<role>/<sub-role>
                start = source.IndexOf(UrnPrefix) + UrnPrefix.Length;
                var end = source.IndexOf('/', start);
                if (Enum.TryParse(source.Substring(start, end - start), out role))
                {
                    break;
                }

                // Parse cases like uri: http://purl.imsglobal.org/vocab/lis/v2/mm#<role>
                start = source.LastIndexOf('#') + 1;
                if (Enum.TryParse(source.Substring(start), out role))
                {
                    break;
                }

                roleFound = false;
            } while (!roleFound);

            return(roleFound);
        }
예제 #2
0
        private void ContextRolesAreConvertedFromJsonLdObjects()
        {
            var expectedContextRoles = new ContextRole[]
            {
                ContextRole.Instructor,
                ContextRole.Administrator,
                ContextRole.Learner,
                ContextRole.ContentDeveloper
            };

            var inputContextRoles = "{ roles: [ " +
                                    "\"lism:Instructor\", " +
                                    "\"http://purl.imsglobal.org/vocab/lis/v2/person#Administrator\", " +
                                    "\"Learner\", " +
                                    "\"urn:lti:role:ims/lis/ContentDeveloper/ContentExpert\"" +
                                    "]}";
            var actualContextRoles = JsonConvert.DeserializeObject <RoleTestObject>(inputContextRoles);

            Assert.Equal(actualContextRoles.Roles, expectedContextRoles);
        }
예제 #3
0
        public void ContextRolesAreConvertedToJsonLdValues()
        {
            const ContextRole contextRole = ContextRole.Instructor;

            Assert.Equal("\"lism:Instructor\"", contextRole.ToJsonLdString());
        }