private void interactionsTest(bool testArrayClear) { LETSIRTE_Service client = getClient(); string int1ID = "test_interaction_1"; cocdType cocd = client.Get(); interactionType int1 = cocd.GetInteraction(int1ID,true); int1.type = interactionTypeType.fill_in; int1.correctResponses = new correctResponsesType(); int1.correctResponses.ItemsElementName = new ItemsChoiceType[] {ItemsChoiceType.correctResponseFillIn}; correctResponsesTypeCorrectResponseFillIn rsp = new correctResponsesTypeCorrectResponseFillIn(); int1.correctResponses.Items = new object[] { rsp }; rsp.caseMatters = false; rsp.orderMatters = false; correctResponsesTypeCorrectResponseFillInMatchText match = new correctResponsesTypeCorrectResponseFillInMatchText(); correctResponsesTypeCorrectResponseFillInMatchText match2 = new correctResponsesTypeCorrectResponseFillInMatchText(); rsp.matchText = new correctResponsesTypeCorrectResponseFillInMatchText[] { match, match2 }; match.Value = "answer 42"; match2.Value = "answer 2"; int1.learnerResponse = new learnerResponseType(); int1.learnerResponse.ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.learnerResponseFillIn }; learnerResponseTypeLearnerResponseFillIn lrsp = new learnerResponseTypeLearnerResponseFillIn(); int1.learnerResponse.Items = new object[] { lrsp}; lrsp.Value = "ANSWER 1"; int1.result = interactionTypeResult.correct; int1.resultSpecified = true; int1.timeStamp = DateTime.UtcNow; int1.timeStampSpecified = true; int1.objectiveIds = new string[] { "id1", "id2" }; cocd.exitSpecified = true; cocd.exit = exit.suspend; client.Set(cocd); cocd = client.Get(); int1 = cocd.GetInteraction(int1ID, false); Assert.AreEqual(interactionTypeType.fill_in, int1.type); Assert.AreEqual(((correctResponsesTypeCorrectResponseFillIn) int1.correctResponses.Items[0]).matchText[0].Value, "answer 42"); learnerResponseTypeLearnerResponseFillIn lr = (learnerResponseTypeLearnerResponseFillIn) int1.learnerResponse.Items[0]; Thread.Sleep(1000); Assert.AreEqual(lr.Value.ToLower(), "answer 1"); Assert.AreEqual(interactionTypeResult.correct, int1.result); Assert.IsTrue(int1.resultSpecified); Assert.Greater(DateTime.UtcNow, int1.timeStamp); Assert.IsTrue(int1.timeStampSpecified); Assert.AreEqual("id2", int1.objectiveIds[1]); if (testArrayClear) { cocd.exitSpecified = true; cocd.exit = exit.suspend; int1.learnerResponse.Items = new object[] { }; int1.objectiveIds = new string[] { }; client.Set(cocd); cocd = client.Get(); int1 = cocd.GetInteraction(int1ID, false); // null or length==0 is acceptable if (int1.learnerResponse != null && int1.learnerResponse.Items != null) { Assert.AreEqual(0, int1.learnerResponse.Items.Length, "Failed to clear array"); } // null or length==0 is acceptable if (int1.objectiveIds != null) { Assert.AreEqual(0, int1.objectiveIds.Length, "Failed to clear array"); } } }
public void interactionsFillIn() { LETSIRTE_Service client = getClient(); string intFillInID = "FillIn"; cocdType cocd = client.Get(); interactionType inter = cocd.GetInteraction(intFillInID, true); inter.type = interactionTypeType.fill_in; inter.correctResponses = new correctResponsesType(); inter.correctResponses.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.correctResponseFillIn, ItemsChoiceType.correctResponseFillIn }; correctResponsesTypeCorrectResponseFillIn rsp = new correctResponsesTypeCorrectResponseFillIn(); correctResponsesTypeCorrectResponseFillIn rsp2 = new correctResponsesTypeCorrectResponseFillIn(); inter.correctResponses.Items = new object[] { rsp, rsp2 }; rsp.matchText = new correctResponsesTypeCorrectResponseFillInMatchText[2]; rsp2.matchText = new correctResponsesTypeCorrectResponseFillInMatchText[1]; rsp.matchText[0] = new correctResponsesTypeCorrectResponseFillInMatchText(); rsp.matchText[1] = new correctResponsesTypeCorrectResponseFillInMatchText(); rsp2.matchText[0] = new correctResponsesTypeCorrectResponseFillInMatchText(); rsp.matchText[0].Value = "answer 1"; rsp.matchText[1].Value = "answer 1.1"; rsp2.matchText[0].Value = "answer 2"; inter.description = new interactionTypeDescription(); inter.description.Value = "fillin interaction"; inter.learnerResponse = new learnerResponseType(); inter.learnerResponse.ItemsElementName = new ItemsChoiceType1[] { ItemsChoiceType1.learnerResponseFillIn, ItemsChoiceType1.learnerResponseFillIn }; learnerResponseTypeLearnerResponseFillIn lrsp = new learnerResponseTypeLearnerResponseFillIn(); learnerResponseTypeLearnerResponseFillIn lrsp2 = new learnerResponseTypeLearnerResponseFillIn(); inter.learnerResponse.Items = new object[] { lrsp,lrsp2 }; lrsp.Value = "answer 1"; lrsp2.Value = "answer 1.1"; inter.result = interactionTypeResult.correct; inter.resultSpecified = true; Assert.IsNotNull(inter, "inter"); Assert.IsNotNull(inter.correctResponses, "inter.correctResponses"); Assert.IsNotNull(inter.correctResponses.Items, "inter.correctResponses.Items"); Assert.AreEqual(2, inter.correctResponses.Items.Length, "correct response count"); Assert.AreEqual(2, inter.learnerResponse.Items.Length, "learner response count"); Assert.AreEqual(2, ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText.Length, "correct response 1 match count"); Assert.AreEqual("answer 1", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText[0].Value, "correct response 1"); Assert.AreEqual("answer 1.1", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText[1].Value, "correct response 1.1"); Assert.AreEqual("answer 2", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[1]).matchText[0].Value, "correct response 2"); Assert.AreEqual("answer 1", ((learnerResponseTypeLearnerResponseFillIn)inter.learnerResponse.Items[0]).Value, "learner response"); Assert.AreEqual("answer 1.1", ((learnerResponseTypeLearnerResponseFillIn)inter.learnerResponse.Items[1]).Value, "learner response"); cocd.exit = exit.suspend; cocd.exitSpecified = true; client.Set(cocd); cocd = client.Get(); inter = cocd.GetInteraction(intFillInID, false); Assert.IsNotNull(inter, "inter"); Assert.IsNotNull(inter.correctResponses, "inter.correctResponses"); Assert.IsNotNull(inter.correctResponses.Items, "inter.correctResponses.Items"); Assert.AreEqual(2, inter.correctResponses.Items.Length, "correct response count"); Assert.AreEqual(2, inter.learnerResponse.Items.Length, "learner response count"); Assert.AreEqual(2, ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText.Length, "correct response 1 match count"); Assert.AreEqual("answer 1", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText[0].Value, "correct response 1"); Assert.AreEqual("answer 1.1", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[0]).matchText[1].Value, "correct response 1.1"); Assert.AreEqual("answer 2", ((correctResponsesTypeCorrectResponseFillIn)inter.correctResponses.Items[1]).matchText[0].Value, "correct response 2"); Assert.AreEqual("answer 1", ((learnerResponseTypeLearnerResponseFillIn)inter.learnerResponse.Items[0]).Value, "learner response"); Assert.AreEqual("answer 1.1", ((learnerResponseTypeLearnerResponseFillIn)inter.learnerResponse.Items[1]).Value, "learner response"); }