public async void ReturnAToolConsumerProfile_FromGetToolConsumerProfileAsync()
        {
            var clientResponse = await ToolConsumerProfileClient.GetToolConsumerProfileAsync(_client, "/ims/toolconsumerprofile");

            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            JsonAssertions.AssertSameObjectJson(clientResponse.Response, "ToolConsumerProfile");
        }
        public void AllFlagsStateReturnsStateWithReasons()
        {
            var flag1 = new FeatureFlagBuilder("key1").Version(100)
                        .OffVariation(0).Variations(LdValue.Of("value1"))
                        .Build();
            var flag2 = new FeatureFlagBuilder("key2").Version(200)
                        .OffVariation(1).Variations(LdValue.Of("x"), LdValue.Of("value2"))
                        .TrackEvents(true).DebugEventsUntilDate(UnixMillisecondTime.OfMillis(1000))
                        .Build();

            testData.UsePreconfiguredFlag(flag1);
            testData.UsePreconfiguredFlag(flag2);

            var state = client.AllFlagsState(user, FlagsStateOption.WithReasons);

            Assert.True(state.Valid);

            var expectedString = @"{""key1"":""value1"",""key2"":""value2"",
                ""$flagsState"":{
                  ""key1"":{
                    ""variation"":0,""version"":100,""reason"":{""kind"":""OFF""}
                  },""key2"":{
                    ""variation"":1,""version"":200,""reason"":{""kind"":""OFF""},""trackEvents"":true,""debugEventsUntilDate"":1000
                  }
                },
                ""$valid"":true
            }";
            var actualString   = LdJsonSerialization.SerializeObject(state);

            JsonAssertions.AssertJsonEqual(expectedString, actualString);
        }
        public void HighlightAnnotationEvent_MatchesReferenceJson()
        {
            var highlightAnnotation = new HighlightAnnotation("https://example.edu/highlights/12345")
            {
                Annotated = TestEntities.EpubSubChap431,
                Selection = new TextPositionSelector {
                    Start = "455", End = "489"
                },
                SelectionText = "Life, Liberty and the pursuit of Happiness",
                DateCreated   = TestEntities.DefaultDateCreated,
                DateModified  = TestEntities.DefaultDateModified
            };

            var highlightEvent = new AnnotationEvent(highlightAnnotation)
            {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.EpubSubChap431_Frame,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.EpubViewerApp,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(highlightEvent, "caliperHighlightAnnotationEvent");
        }
        public void ShareAnnotationEvent_MatchesReferenceJson()
        {
            var shareAnnotation = new ShareAnnotation("https://example.edu/shared/9999")
            {
                Annotated  = TestEntities.EpubSubChap433,
                WithAgents = new [] {
                    new Person("https://example.edu/user/657585")
                    {
                        DateCreated  = TestEntities.DefaultDateCreated,
                        DateModified = TestEntities.DefaultDateModified
                    },
                    new Person("https://example.edu/user/667788")
                    {
                        DateCreated  = TestEntities.DefaultDateCreated,
                        DateModified = TestEntities.DefaultDateModified
                    }
                },
                DateCreated  = TestEntities.DefaultDateCreated,
                DateModified = TestEntities.DefaultDateModified
            };

            var shareEvent = new AnnotationEvent(shareAnnotation)
            {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.EpubSubChap433_Frame,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.EpubViewerApp,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(shareEvent, "caliperSharedAnnotationEvent");
        }
        public void MinimalEvent_MatchesReferenceJson()
        {
            var @object = new BaseEntity("https://example.com/viewer/book/34843#epubcfi(/4/3)")
            {
                Type = new EntityType("http://www.idpf.org/epub/vocab/structure/#volume")
            };

            var actor = new Agent("https://example.edu/user/554433")
            {
                Type = new EntityType("http://purl.imsglobal.org/caliper/v1/lis/Person")
            };

            var @event = new BaseEvent
            {
                Actor     = actor,
                Action    = Action.Viewed,
                Object    = @object,
                EventTime = TestEntities.DefaultStartedAtTime
            };

            var caliperMessage = new CaliperMessage <BaseEvent>
            {
                SensorId = "https://example.edu/sensor/001",
                SendTime = TestEntities.DefaultSendTime,
                Data     = new[] { @event }
            };

            JsonAssertions.AssertSameObjectJson(caliperMessage, "caliperEnvelopeEventViewViewedMinimal");
        }
Beispiel #6
0
        public void SerializeToValidJson()
        {
            var referenceJson = TestUtils.LoadReferenceJsonFile("ResultContainer");
            var container     = JsonConvert.DeserializeObject <ResultContainer>(referenceJson);
            var containerJson = JsonConvert.SerializeObject(container);

            JsonAssertions.Equal(referenceJson, containerJson);
        }
        public async void ReturnAToolConsumerProfile_FromGetToolConsumerProfileAsync()
        {
            var uri            = new Uri(_client.BaseAddress, "ims/toolconsumerprofile");
            var clientResponse = await ToolConsumerProfileClient.GetToolConsumerProfileAsync(_client, uri.AbsoluteUri);

            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            JsonAssertions.AssertSameObjectJson(clientResponse.Response, "ToolConsumerProfile");
        }
Beispiel #8
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");
        }
        public void SerializeToValidJson()
        {
            var referenceJson = TestUtils.LoadReferenceJsonFile("Result");
            var result        = JsonConvert.DeserializeObject <Result>(referenceJson);
            var resultJson    = JsonConvert.SerializeObject(result);

            JsonAssertions.Equal(referenceJson, resultJson);
        }
Beispiel #10
0
        public async void GetOneMembershipPage_WhenGetMembershipPageAsyncIsCalled()
        {
            var clientResponse = await MembershipClient.GetMembershipPageAsync(_client, "/ims/membership", Key, Secret);

            Assert.Equal(HttpStatusCode.OK, clientResponse.StatusCode);
            Assert.NotNull(clientResponse.Response);
            JsonAssertions.AssertSameObjectJson(clientResponse.Response, "MembershipContainerPage");
        }
Beispiel #11
0
        public void SerializeToValidJson()
        {
            var referenceJson = TestUtils.LoadReferenceJsonFile("Score");
            var score         = JsonConvert.DeserializeObject <Score>(referenceJson);
            var scoreJson     = JsonConvert.SerializeObject(score);

            JsonAssertions.Equal(referenceJson, scoreJson);
        }
Beispiel #12
0
        public void SerializeToValidJson()
        {
            var referenceJson = TestUtils.LoadReferenceJsonFile("LineItem");
            var lineItem      = JsonConvert.DeserializeObject <LineItem>(referenceJson);
            var lineItemJson  = JsonConvert.SerializeObject(lineItem);

            JsonAssertions.Equal(referenceJson, lineItemJson);
        }
Beispiel #13
0
        public void ParseValidLtiResourceLinkRequest()
        {
            var referenceJson = TestUtils.LoadReferenceJsonFile("LtiResourceLinkRequest");

            var request     = JsonConvert.DeserializeObject <LtiResourceLinkRequest>(referenceJson);
            var requestJson = JsonConvert.SerializeObject(request);

            JsonAssertions.Equal(referenceJson, requestJson);
        }
Beispiel #14
0
        public void ExternalContextOnly_ToJsonLdStringMatchesReferenceJson()
        {
            var parent = new Parent
            {
                Id   = new Uri("http://localhost/test/1"),
                Name = "MyParent"
            };

            JsonAssertions.AssertSameJsonLdObject(parent, "ExternalContextOnly");
        }
        public void SessionTimedOutEvent_MatchesReferenceJson()
        {
            var timedOutEvent = new SessionEvent(Action.TimedOut)
            {
                Actor     = TestEntities.EpubViewerApp,
                Object    = TestEntities.SessionEnd,
                EventTime = TestEntities.DefaultStartedAtTime,
                EdApp     = TestEntities.EpubViewerApp,
                Group     = TestEntities.AmRev101_Group001
            };

            JsonAssertions.AssertSameObjectJson(timedOutEvent, "caliperSessionTimeoutEvent");
        }
Beispiel #16
0
        public void InternalContextOnly_MatchesReferenceJson()
        {
            var child = new Child
            {
                Name       = "MyChild",
                GrandChild = new Child
                {
                    Name = "MyGrandChild"
                }
            };

            JsonAssertions.AssertSameJsonLdObject(child, "InternalContextOnly");
        }
Beispiel #17
0
        public async void LaunchAContentItemSelectionTool_WithValidCredentials()
        {
            var ltiRequest = GetLtiContentItemSelectionRequest();

            // Substitute custom variables and calculate the signature
            var signature = ltiRequest.SubstituteCustomVariablesAndGenerateSignature("secret");

            using (var response = await _client.PostAsync(ltiRequest.Url.AbsoluteUri, GetContent(ltiRequest, signature)))
            {
                Assert.True(response.IsSuccessStatusCode, $"Response status code does not indicate success: {response.StatusCode}");
                JsonAssertions.AssertSameObjectJson(await GetContentAsJObject(response), LtiConstants.ContentItemSelectionRequestLtiMessageType);
            }
        }
Beispiel #18
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");
        }
Beispiel #19
0
        public void ViewEvent_MatchesReferenceJson()
        {
            var viewEvent = new ViewEvent {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.EpubVolume43,
                Target     = TestEntities.EpubSubChap431_Frame,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.EpubViewerApp,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(viewEvent, "caliperViewEvent");
        }
Beispiel #20
0
        public void MediaEvent_MatchesReferenceJson()
        {
            var mediaEvent = new MediaEvent(Action.Paused)
            {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.VideoWithLearningObjective,
                Target     = TestEntities.VideoWithLearningObjective_Location710,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.SuperMediaTool,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(mediaEvent, "caliperMediaEvent");
        }
        public void SessionLoggedOutEvent_MatchesReferenceJson()
        {
            var loggedOutEvent = new SessionEvent(Action.LoggedOut)
            {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.EpubViewerApp,
                Target     = TestEntities.SessionEnd,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.EpubViewerApp,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(loggedOutEvent, "caliperSessionLogoutEvent");
        }
        public async void ReturnAToolConsumerProfile()
        {
            _client.DefaultRequestHeaders.Accept.Clear();
            _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(LtiConstants.LtiToolConsumerProfileMediaType));

            using (var response = await _client.GetAsync("ims/toolconsumerprofile"))
            {
                response.EnsureSuccessStatusCode();
                Assert.Equal(LtiConstants.LtiToolConsumerProfileMediaType, response.Content.Headers.ContentType.MediaType);
                var profile = await response.Content.ReadJsonAsObjectAsync <ToolConsumerProfile>();

                Assert.NotNull(profile);
                JsonAssertions.AssertSameObjectJson(profile, "ToolConsumerProfile");
            }
        }
Beispiel #23
0
        public void EmbeddedHtmlContentItem_MatchesReferenceJson()
        {
            // From http://www.imsglobal.org/lti/services/ltiCIv1p0pd/ltiCIv1p0pd.html
            var contentItem = new ContentItem
            {
                MediaType       = "text/html",
                PlacementAdvice = new ContentItemPlacement
                {
                    PresentationDocumentTarget = DocumentTarget.embed
                },
                Text = "<p>IMS has a <a href=\"http://imscatalog.org/\">catalog of certified products</a> available on their website</p>"
            };

            JsonAssertions.AssertSameObjectJson(contentItem, "EmbeddedHtmlContentItem");
        }
        public void AssessmentOutcomeEvent_MatchesReferenceJson()
        {
            var outcomeEvent = new OutcomeEvent(Action.Graded)
            {
                Actor      = TestEntities.User554433,
                Object     = TestEntities.Assessment1_Attempt1,
                Generated  = TestEntities.Assessment1_Attempt1_Result,
                EventTime  = TestEntities.DefaultStartedAtTime,
                EdApp      = TestEntities.SuperAssessmentTool,
                Group      = TestEntities.AmRev101_Group001,
                Membership = TestEntities.User554433_AmRev101_CourseSection001_Membership
            };

            JsonAssertions.AssertSameObjectJson(outcomeEvent, "caliperAssessmentOutcomeEvent");
        }
Beispiel #25
0
        public async void LaunchATool_WithValidCredentials(string lcid)
        {
            CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo(lcid);

            var ltiRequest = GetLtiLaunchRequest();

            // Substitute custom variables and calculate the signature
            var signature = ltiRequest.SubstituteCustomVariablesAndGenerateSignature("secret");

            using (var response = await _client.PostAsync(ltiRequest.Url.AbsoluteUri, GetContent(ltiRequest, signature)))
            {
                Assert.True(response.IsSuccessStatusCode, $"Response status code does not indicate success: {response.StatusCode}");
                var referenceJson = TestUtils.LoadReferenceJsonFile(LtiConstants.BasicLaunchLtiMessageType)
                                    .Replace("{lcid}", lcid);
                JsonAssertions.AssertSameObjectJson(await GetContentAsJObject(response), JObject.Parse(referenceJson));
            }
        }
Beispiel #26
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");
        }
Beispiel #27
0
        public void ExternalAndInternalContexts_MatchesReferenceJson()
        {
            var parent = new Parent
            {
                Id    = new Uri("http://localhost/test/1"),
                Name  = "MyParent",
                Child = new Child
                {
                    Name       = "MyChild",
                    GrandChild = new Child
                    {
                        Name = "MyGrandChild"
                    }
                }
            };

            JsonAssertions.AssertSameJsonLdObject(parent, "ExternalAndInternalContexts");
        }
Beispiel #28
0
        public void EmbeddedImageContentItem_MatchesReferenceJson()
        {
            // From http://www.imsglobal.org/lti/services/ltiCIv1p0pd/ltiCIv1p0pd.html
            var contentItem = new ContentItem
            {
                MediaType       = "image/png",
                PlacementAdvice = new ContentItemPlacement
                {
                    DisplayHeight = 184,
                    DisplayWidth  = 147,
                    PresentationDocumentTarget = DocumentTarget.embed,
                    WindowTarget = "_blank"
                },
                Title = "IMS logo for certified products",
                Url   = "http://developers.imsglobal.org/images/imscertifiedsm.png"
            };

            JsonAssertions.AssertSameObjectJson(contentItem, "EmbeddedImageContentItem");
        }
Beispiel #29
0
        public async void GetContentItemSelection()
        {
            var ltiRequest = GetLtiContentItemSelectionRequest("contentitemsprovider/librarythatreturnsselection");

            // Substitute custom variables and calculate the signature
            var signature = ltiRequest.SubstituteCustomVariablesAndGenerateSignature("secret");

            using (var response = await _client.PostAsync(ltiRequest.Url.AbsoluteUri, GetContent(ltiRequest, signature)))
            {
                Assert.True(response.IsSuccessStatusCode, $"Response status code does not indicate success: {response.StatusCode}\n{response.Content.ReadAsStringAsync().Result}");

                var selection = await GetContentAsJObject(response);

                Assert.Equal(LtiConstants.ContentItemSelectionLtiMessageType, selection[LtiConstants.LtiMessageTypeParameter]);
                Assert.Equal("VeryImportantData", selection[LtiConstants.ContentItemDataParameter]);

                var graph = JObject.Parse(selection[LtiConstants.ContentItemPlacementParameter].Value <string>());
                JsonAssertions.AssertSameObjectJson(graph, LtiConstants.ContentItemSelectionLtiMessageType);
            }
        }
Beispiel #30
0
        public void LtiLinkContentItem_MatchesReferenceJson()
        {
            // From http://www.imsglobal.org/lti/services/ltiCIv1p0pd/ltiCIv1p0pd.html
            var ltiLink = new LtiLink
            {
                Icon = new Image
                {
                    Id     = "https://www.server.com/path/animage.png",
                    Height = 50,
                    Width  = 50
                },
                Text   = "Read this section prior to your tutorial.",
                Title  = "Week 1 reading",
                Custom = new Dictionary <string, string> {
                    { "chapter", "12" }, { "section", "3" }
                }
            };

            JsonAssertions.AssertSameObjectJson(ltiLink, "LtiLinkContentItem");
        }