Ejemplo n.º 1
0
        public async void GetOneMembership_WhenRoleIsLearner()
        {
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/membership", Key, Secret, role : Role.Learner);

            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            Assert.Equal(1, clientResponse.Response.Count);
        }
Ejemplo n.º 2
0
        public async void GetAllMemberships_WhenGetMembershipAsyncIsCalled()
        {
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/membership", Key, Secret);

            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            Assert.NotNull(clientResponse.Response);
            JsonAssertions.AssertSameObjectJson(new { clientResponse.Response }, "Memberships");
        }
Ejemplo n.º 3
0
        public async void ReturnNotFound_WhenThereIsAnUnknownContextId()
        {
            // Given a working LTI Membership Service endpoint
            // When I specify an unknown contextId
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/membership/context/context-2", Key, Secret);

            // Then I get a NotFound response
            Assert.Equal(HttpStatusCode.NotFound, clientResponse.StatusCode);
        }
Ejemplo n.º 4
0
        public async void ReturnsLearners_WhenRoleFilterIsLearner()
        {
            // Given a working LTI Membership Service endpoint
            // When I call GetMembershipAsync with the Learner role filter
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/membership/context/context-1", Key, Secret, role : ContextRole.Learner);

            // Then I get an OK response
            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            // And the response is not null
            Assert.NotNull(clientResponse.Response);
            // And there is exactly one membership
            Assert.Equal(1, clientResponse.Response.Count);
        }
Ejemplo n.º 5
0
        public async void ReturnAllMemberships()
        {
            // Given a working LTI Membership Service endpoint
            // When I call GetMembershipAsync without any filters
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/membership/context/context-1", Key, Secret);

            // Then I get an OK response
            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            // And the response is not null
            Assert.NotNull(clientResponse.Response);
            // And the response matches the response in Memberships.json
            JsonAssertions.AssertSameObjectJson(new { clientResponse.Response }, "Memberships");
        }
Ejemplo n.º 6
0
        public async Task ReturnNoMemberships_WhenImageUrlsAreInvalid_AndErrorHandlerIsNull()
        {
            // Given a working LTI Membership Service endpoint
            // When I call GetMembershipAsync without any filters
            var clientResponse = await MembershipClient.GetMembershipAsync(_client, "/ims/rawmembership/RawMembershipsWithInvalidImageUrl", Key, Secret);

            // Then I get an OK response
            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            // And the response is not null
            Assert.NotNull(clientResponse.Response);
            // And the response is empty
            Assert.Equal(0, clientResponse.Response.Count);
        }
Ejemplo n.º 7
0
        public async Task <IEnumerable <Membership> > GetAllMembers(string membershipUrl, string key, string resourceLinkId)
        {
            using (HttpClient httpClient = _httpClientFactory.CreateClient(EdnaExternalHttpHandler.Name))
            {
                ClientResponse <List <Membership> > membershipResponse = await MembershipClient.GetMembershipAsync(httpClient, membershipUrl, key, ToolSecret, resourceLinkId);

                if (membershipResponse.Exception != null)
                {
                    _logger.LogError(membershipResponse.Exception, "Failed to fetch LTI1 users.");
                    return(Enumerable.Empty <Membership>());
                }

                return(membershipResponse.Response);
            }
        }
Ejemplo n.º 8
0
        public async Task ReturnAllMemberships_WhenImageUrlsAreInvalid_AndErrorHandlerIgnoresErrors()
        {
            // Given a working LTI Membership Service endpoint
            // When I call GetMembershipAsync without any filters
            var clientResponse = await MembershipClient.GetMembershipAsync
                                 (
                _client, "/ims/rawmembership/RawMembershipsWithInvalidImageUrl", Key, Secret,
                // Ignore deserialization errors
                deserializationErrorHandler : HandleDeserializationError
                                 );

            // Then I get an OK response
            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            // And the response is not null
            Assert.NotNull(clientResponse.Response);
            // And the response matches the response in Memberships.json
            JsonAssertions.AssertSameObjectJson(new { clientResponse.Response }, "MembershipsWithNoImages");
        }
Ejemplo n.º 9
0
        public async Task ReturnsInstructors_WhenRoleFilterIsInstructorWithNoBaseAddress()
        {
            // Given a working LTI Membership Service endpoint
            // When I call GetMembershipAsync with the Learner role filter
            var client = _server.CreateClient();

            client.BaseAddress = null;
            var clientResponse = await MembershipClient.GetMembershipAsync(client, "http://localhost/ims/membership/context/context-1", Key, Secret, role : ContextRole.Instructor);

            // Then I get an OK response
            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            // And the response is not null
            Assert.NotNull(clientResponse.Response);
            // And there is exactly one membership
            Assert.Equal(1, clientResponse.Response.Count);
            // And the role is Instructor
            Assert.Equal(clientResponse.Response[0].Role[0], ContextRole.Instructor);
        }