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); }
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); }
public void ContextRolesAreConvertedToJsonLdValues() { const ContextRole contextRole = ContextRole.Instructor; Assert.Equal("\"lism:Instructor\"", contextRole.ToJsonLdString()); }