Ejemplo n.º 1
0
        public static StimulusDigest ToStimulusDigest(
            ItemMetadata itemMetadata,
            ItemContents itemContents)
        {
            if (itemMetadata == null)
            {
                throw new ArgumentNullException(nameof(itemMetadata));
            }
            if (itemMetadata.Metadata == null)
            {
                throw new ArgumentNullException(nameof(itemMetadata.Metadata));
            }
            if (itemContents == null)
            {
                throw new ArgumentNullException(nameof(itemContents));
            }
            if (itemContents.Passage == null)
            {
                throw new ArgumentNullException(nameof(itemContents.Passage));
            }

            StimulusDigest digest = new StimulusDigest()
            {
                ItemKey  = itemContents.Passage.ItemKey,
                BankKey  = itemContents.Passage.ItemBank,
                Contents = itemContents.Passage.Contents,
            };

            return(digest);
        }
        public void TestDeserializeXmltoItemContents()
        {
            int expectedItemKey = 856;
            int expectedBankKey = 187;

            string       testFile          = @"/Items/Item-187-856/item-187-856.xml";
            string       baseTestDirectory = Directory.GetDirectories(Directory.GetCurrentDirectory(), "TestContentItems", SearchOption.AllDirectories)[0];
            FileInfo     metadataFile      = new FileInfo(baseTestDirectory + testFile);
            ItemContents contents          = XmlSerialization.DeserializeXml <ItemContents>(metadataFile);

            Assert.Equal(expectedItemKey, contents.Item.ItemKey);
            Assert.Equal(expectedBankKey, contents.Item.ItemBank);
        }
        public async Task <IHttpActionResult> SaveContentChanges(string fileUrl, [FromBody] ItemContents contents)
        {
            if (string.IsNullOrEmpty(fileUrl))
            {
                return(BadRequest());
            }
            if (null == contents)
            {
                return(BadRequest());
            }

            // Generate the resourceId for the MS Graph URL so we know where to request an access token
            Uri    target     = new Uri(fileUrl);
            string resourceId = target.GetLeftPart(UriPartial.Authority);

            // Retrieve an access token so we can make API calls
            string accessToken = null;

            try
            {
                accessToken = await AuthHelper.GetUserAccessTokenSilentAsync(resourceId);
            }
            catch (Exception ex)
            {
                return(Ok(new SaveResults {
                    Success = false, Error = ex.Message
                }));
            }

            // Upload the new file content
            try
            {
                var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(contents.MarkdownText));
                var result = await HttpHelper.Default.UploadFileContentsFromStreamAsync(stream, fileUrl, accessToken);

                return(Ok(new SaveResults {
                    Success = true
                }));
            }
            catch (Exception ex)
            {
                return(Ok(new SaveResults {
                    Success = false, Error = ex.Message
                }));
            }
        }
        public void TestItemToItemDigestInvalid()
        {
            ItemMetadata metadata = new ItemMetadata();
            ItemContents contents = new ItemContents();

            metadata.Metadata                           = new SmarterAppMetadataXmlRepresentation();
            contents.Item                               = new ItemXmlFieldRepresentation();
            metadata.Metadata.ItemKey                   = 1;
            metadata.Metadata.GradeCode                 = "7";
            metadata.Metadata.TargetAssessmentType      = "Test target string";
            metadata.Metadata.SufficientEvidenceOfClaim = "Test claim string";
            metadata.Metadata.InteractionType           = "EQ";
            metadata.Metadata.SubjectCode               = "MATH";
            metadata.Metadata.StandardPublications      = new List <StandardPublication>();
            metadata.Metadata.StandardPublications.Add(
                new StandardPublication
            {
                PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2"
            });

            var settings = new AppSettings
            {
                SettingsConfig = new SettingsConfig
                {
                    SupportedPublications = new string[] { "" }
                }
            };

            contents.Item.ItemKey  = 2;
            contents.Item.ItemBank = 3;
            contents.Item.Contents = new List <Content>();
            var exception = Record.Exception(() => ItemDigestTranslation.ToItemDigest(metadata, contents, new AppSettings()));

            Assert.NotNull(exception);
            Assert.IsType <SampleItemsContextException>(exception);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Translates metadata, itemcontents and lookups to item digest
        /// </summary>
        public static ItemDigest ToItemDigest(
            ItemMetadata itemMetadata,
            ItemContents itemContents,
            AppSettings settings,
            StimulusDigest stimulusDigest = null)
        {
            if (itemMetadata == null)
            {
                throw new ArgumentNullException(nameof(itemMetadata));
            }
            if (itemMetadata.Metadata == null)
            {
                throw new ArgumentNullException(nameof(itemMetadata.Metadata));
            }
            if (itemContents == null)
            {
                throw new ArgumentNullException(nameof(itemContents));
            }
            if (itemContents.Item == null)
            {
                throw new ArgumentNullException(nameof(itemContents.Item));
            }

            if (itemContents.Item.ItemKey != itemMetadata.Metadata.ItemKey)
            {
                throw new SampleItemsContextException("Cannot digest items with different ItemKey values.\n"
                                                      + $"Content Item Key: {itemContents.Item.ItemKey} Metadata Item Key:{itemMetadata.Metadata.ItemKey}");
            }

            string itemType            = itemContents.Item.ItemType ?? string.Empty;
            string interactionCode     = itemMetadata.Metadata.InteractionType ?? string.Empty;
            var    oldToNewInteraction = settings?.SettingsConfig?.OldToNewInteractionType;

            if (oldToNewInteraction != null && oldToNewInteraction.ContainsKey(itemType))
            {
                settings.SettingsConfig.OldToNewInteractionType.TryGetValue(itemType, out itemType);
            }

            if (oldToNewInteraction != null && oldToNewInteraction.ContainsKey(interactionCode))
            {
                settings.SettingsConfig.OldToNewInteractionType.TryGetValue(interactionCode, out interactionCode);
            }

            ItemDigest digest = new ItemDigest()
            {
                ItemType                 = itemType,
                ItemKey                  = itemContents.Item.ItemKey,
                BankKey                  = itemContents.Item.ItemBank,
                TargetAssessmentType     = itemMetadata.Metadata.TargetAssessmentType,
                SufficentEvidenceOfClaim = itemMetadata.Metadata.SufficientEvidenceOfClaim,
                AssociatedStimulus       = itemMetadata.Metadata.AssociatedStimulus,
                AslSupported             = itemMetadata.Metadata.AccessibilityTagsASLLanguage.AslSupportedStringToBool(),
                AllowCalculator          = itemMetadata.Metadata.AllowCalculator == "Y",
                DepthOfKnowledge         = itemMetadata.Metadata.DepthOfKnowledge,
                Contents                 = itemContents.Item.Contents,
                InteractionTypeCode      = interactionCode,
                AssociatedPassage        = itemContents.Item.AssociatedPassage,
                GradeCode                = itemMetadata.Metadata.GradeCode,
                MaximumNumberOfPoints    = itemMetadata.Metadata.MaximumNumberOfPoints,
                StandardPublications     = itemMetadata.Metadata.StandardPublications,
                SubjectCode              = itemMetadata.Metadata.SubjectCode,
                ItemMetadataAttributes   = itemContents.Item.ItemMetadataAttributes,
                StimulusDigest           = stimulusDigest,
                SmarterAppItemDescriptor = itemMetadata.Metadata.SmarterAppItemDescriptor
            };

            return(digest);
        }
        public void TestItemToItemDigest()
        {
            int    testItemKey  = 1;
            int    testItemBank = 2;
            string testGrade    = "5";

            ItemMetadata metadata = new ItemMetadata();
            ItemContents contents = new ItemContents();

            metadata.Metadata                           = new SmarterAppMetadataXmlRepresentation();
            contents.Item                               = new ItemXmlFieldRepresentation();
            metadata.Metadata.ItemKey                   = testItemKey;
            metadata.Metadata.GradeCode                 = testGrade;
            metadata.Metadata.TargetAssessmentType      = "Test target string";
            metadata.Metadata.SufficientEvidenceOfClaim = "Test claim string";
            metadata.Metadata.InteractionType           = "EQ";
            metadata.Metadata.SubjectCode               = "MATH";
            metadata.Metadata.StandardPublications      = new List <StandardPublication>();
            metadata.Metadata.StandardPublications.Add(
                new StandardPublication
            {
                PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2"
            });

            contents.Item.ItemKey  = testItemKey;
            contents.Item.ItemBank = testItemBank;
            contents.Item.Contents = new List <Content>();

            var interactionTypes = new List <InteractionType>
            {
                new InteractionType(code: "EQ", label: "", description: "", order: 0)
            };

            var subjects = new List <Subject>
            {
                new Subject(
                    code: "MATH",
                    label: string.Empty,
                    shortLabel: string.Empty,
                    claims: ImmutableArray.Create <Claim>(),
                    interactionTypeCodes: ImmutableArray.Create <string>())
            };

            var placeholderText = new RubricPlaceHolderText
            {
                RubricPlaceHolderContains = new string[0],
                RubricPlaceHolderEquals   = new string[0]
            };

            var settings = new SettingsConfig
            {
                SupportedPublications = new string[] { "" }
            };

            AppSettings appSettings = new AppSettings
            {
                SettingsConfig        = settings,
                RubricPlaceHolderText = placeholderText
            };


            ItemDigest digest = ItemDigestTranslation.ToItemDigest(metadata, contents, appSettings);

            Assert.Equal(testItemKey, digest.ItemKey);
            Assert.Equal(testItemBank, digest.BankKey);
            Assert.Equal(GradeLevels.Grade5, GradeLevelsUtils.FromString(digest.GradeCode));
            Assert.Equal("Test target string", digest.TargetAssessmentType);
            Assert.Equal("Test claim string", digest.SufficentEvidenceOfClaim);
            Assert.Equal("MATH", digest.SubjectCode);
            Assert.Equal("EQ", digest.InteractionTypeCode);
        }
        public void TestItemstoItemDigests()
        {
            int testItemCount = 3;
            List <ItemContents>      contentsList = new List <ItemContents>();
            List <ItemMetadata>      metadataList = new List <ItemMetadata>();
            IEnumerable <ItemDigest> digests;

            // Get a range of numbers from 50 to the number of items being tested.
            // Use the same numer for an item's key and bank to make it easy to validate that
            // ItemMetadata and ItemContents objects are being paired correctly.
            int[]  itemKeys            = Enumerable.Range(50, testItemCount).ToArray();
            int[]  banksKeys           = itemKeys;
            string testTarget          = "Test target string";
            string testClaimEvidence   = "Test claim string";
            string testInteractionType = "EQ";
            string testSubject         = "MATH";

            int i;

            for (i = 0; i < testItemCount; i++)
            {
                ItemMetadata metadata = new ItemMetadata();
                ItemContents contents = new ItemContents();

                metadata.Metadata = new SmarterAppMetadataXmlRepresentation();
                contents.Item     = new ItemXmlFieldRepresentation();

                //Test metadata attributes
                metadata.Metadata.ItemKey                   = itemKeys[i];
                metadata.Metadata.GradeCode                 = (itemKeys[i] % 9 + 3).ToString();
                metadata.Metadata.TargetAssessmentType      = testTarget + itemKeys[i];
                metadata.Metadata.SufficientEvidenceOfClaim = testClaimEvidence + itemKeys[i];
                metadata.Metadata.InteractionType           = testInteractionType;
                metadata.Metadata.SubjectCode               = testSubject;
                metadata.Metadata.StandardPublications      = new List <StandardPublication>();
                metadata.Metadata.StandardPublications.Add(
                    new StandardPublication
                {
                    PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2"
                });

                //Test contents attributes
                contents.Item.ItemKey  = itemKeys[i];
                contents.Item.ItemBank = banksKeys[i];
                contents.Item.Contents = new List <Content>();

                metadataList.Add(metadata);
                contentsList.Add(contents);
            }

            var interactionTypes = new List <InteractionType>
            {
                new InteractionType(code: testInteractionType, label: "", description: "", order: 0)
            };

            var subjects = new List <Subject>
            {
                new Subject(
                    code: testSubject,
                    label: string.Empty,
                    shortLabel: string.Empty,
                    claims: ImmutableArray.Create <Claim>(),
                    interactionTypeCodes: ImmutableArray.Create <string>())
            };

            var settings = new AppSettings
            {
                SettingsConfig = new SettingsConfig
                {
                    AccessibilityTypes    = new List <AccessibilityType>(),
                    SupportedPublications = new string[] { "" }
                }
            };

            digests = ItemDigestTranslation.ToItemDigests(metadataList, contentsList, settings);

            Assert.Equal(itemKeys.Length, digests.Count());

            foreach (var digest in digests)
            {
                int id = digest.ItemKey;
                Assert.Equal(digest.ItemKey, digest.BankKey);
                Assert.Equal(GradeLevelsUtils.FromString((digest.ItemKey % 9 + 3).ToString()), GradeLevelsUtils.FromString(digest.GradeCode));
                Assert.Equal(testTarget + id, digest.TargetAssessmentType);
                Assert.Equal(testClaimEvidence + id, digest.SufficentEvidenceOfClaim);
                Assert.Equal(testInteractionType, digest.InteractionTypeCode);
                Assert.Equal(testSubject, digest.SubjectCode);
            }
        }
        public StandardIdentifierTranslationTests()
        {
            elaStandardString           = "SBAC-ELA-v1:3-L|4-6|6.SL.2";
            mathv1StandardString        = "SBAC-MA-v1:1|NBT|E-3|a/s|3.NBT.2";
            mathV4StandardString        = "SBAC-MA-v4:1|NS|D-6|m|6.NS.6c";
            mathV5StandardString        = "SBAC-MA-v5:2|NS|D-6|m|6.NS.6c";
            mathV6StandardString        = "SBAC-MA-v6:3|P|TS04|D-6";
            invalidElaStandardString    = "SBAC-ELA-v1:3-L";
            invalidMathV1StandardString = "SBAC-MA-v1:1|NBT||a/s|";
            invalidMathV4StandardString = "SBAC-MA-v4:|NS|D-6||";
            invalidMathV5StandardString = "SBAC-MA-v5:2||||6.NS.6c";
            invalidMathV6StandardString = "SBAC-MA-v6:3|||";
            noClaimString  = "SBAC-ELA-v1|4-6|6.SL.2";
            noTargetString = "SBAC-ELA-v1:3-L||6.SL.2";
            int    testItemKey  = 1;
            int    testItemBank = 2;
            string testGrade    = "5";

            metadata                                    = new ItemMetadata();
            contents                                    = new ItemContents();
            metadata.Metadata                           = new SmarterAppMetadataXmlRepresentation();
            contents.Item                               = new ItemXmlFieldRepresentation();
            metadata.Metadata.ItemKey                   = testItemKey;
            metadata.Metadata.GradeCode                 = testGrade;
            metadata.Metadata.TargetAssessmentType      = "Test target string";
            metadata.Metadata.SufficientEvidenceOfClaim = "Test claim string";
            metadata.Metadata.InteractionType           = "EQ";
            metadata.Metadata.SubjectCode               = "MATH";
            metadata.Metadata.StandardPublications      = new List <StandardPublication>();
            metadata.Metadata.StandardPublications.Add(
                new StandardPublication
            {
                PrimaryStandard = "SBAC-MA-v1:1|NBT|E-3|a/s|3.NBT.2",
                Publication     = "SBAC-MA-v1"
            });

            contents.Item.ItemKey  = testItemKey;
            contents.Item.ItemBank = testItemBank;
            contents.Item.Contents = new List <Content>();

            var interactionTypes = new List <InteractionType>
            {
                new InteractionType(code: "EQ", label: "", description: "", order: 0)
            };

            var subjects = new List <Subject>
            {
                new Subject(
                    code: "MATH",
                    label: string.Empty,
                    shortLabel: string.Empty,
                    claims: ImmutableArray.Create <Claim>(),
                    interactionTypeCodes: ImmutableArray.Create <string>())
            };

            var placeholderText = new RubricPlaceHolderText
            {
                RubricPlaceHolderContains = new string[0],
                RubricPlaceHolderEquals   = new string[0]
            };

            var settings = new SettingsConfig
            {
                SupportedPublications = new string[] { "" }
            };

            appSettings = new AppSettings
            {
                SettingsConfig        = settings,
                RubricPlaceHolderText = placeholderText
            };
        }
        public SampleItemTranslationTests()
        {
            rubricEntries = new List <RubricEntry>()
            {
                new RubricEntry
                {
                    Scorepoint = "0",
                    Name       = "TestName",
                    Value      = "TestValue"
                },
                new RubricEntry
                {
                    Scorepoint = "1",
                    Name       = "TestName1",
                    Value      = "TestValue1"
                }
            };

            var sampleResponces = new List <SampleResponse>()
            {
                new SampleResponse()
                {
                    Purpose       = "TestPurpose",
                    ScorePoint    = "0",
                    Name          = "TestName",
                    SampleContent = "TestSampleContent"
                },
                new SampleResponse()
                {
                    Purpose       = "TestPurpose1",
                    ScorePoint    = "1",
                    Name          = "TestName1",
                    SampleContent = "TestSampleContent1"
                }
            };

            rubricSamples = new List <RubricSample>()
            {
                new RubricSample
                {
                    MaxValue        = "MaxVal",
                    MinValue        = "MinVal",
                    SampleResponses = sampleResponces
                },
                new RubricSample
                {
                    MaxValue        = "MaxVal1",
                    MinValue        = "MinVal1",
                    SampleResponses = new List <SampleResponse>()
                }
            };

            rubricList = new RubricList()
            {
                Rubrics       = rubricEntries,
                RubricSamples = rubricSamples
            };

            Resources = new List <AccessibilityResource>
            {
                AccessibilityResource.Create(
                    resourceCode: "ACC1",
                    order: 1,
                    disabled: false,
                    defaultSelection: "ACC1_SEL1",
                    currentSelectionCode:  "ACC1_SEL1",
                    label: "Accessibility 1",
                    description: "Accessibility Selection One",
                    resourceType: "Acc1Type",
                    selections: ImmutableArray.Create(
                        new AccessibilitySelection(
                            code: "ACC1_SEL1",
                            order: 1,
                            disabled: false,
                            label: "Selection 1",
                            hidden: false))),
                AccessibilityResource.Create(
                    resourceCode: "ACC2",
                    order: 2,
                    disabled: false,
                    defaultSelection: "ACC2_SEL2",
                    currentSelectionCode:  "ACC2_SEL2",
                    label: "Accessibility 2",
                    description: "Accessibility Selection Two",
                    resourceType: "Acc2Type",
                    selections: ImmutableArray.Create(
                        new AccessibilitySelection(
                            code: "ACC2_SEL1",
                            order: 1,
                            disabled: false,
                            label: "Selection 1",
                            hidden: false),
                        new AccessibilitySelection(
                            code: "ACC2_SEL2",
                            order: 2,
                            disabled: false,
                            label: "Selection 2",
                            hidden: false)))
            };

            accessibilityType       = new AccessibilityType();
            accessibilityType.Id    = "Acc1Type";
            accessibilityType.Label = "Accessibility 1";
            accessibilityType.Order = 1;

            int    testItemKey  = 1;
            int    testItemBank = 2;
            string testGrade    = "5";

            metadata                                    = new ItemMetadata();
            contents                                    = new ItemContents();
            metadata.Metadata                           = new SmarterAppMetadataXmlRepresentation();
            contents.Item                               = new ItemXmlFieldRepresentation();
            metadata.Metadata.ItemKey                   = testItemKey;
            metadata.Metadata.GradeCode                 = testGrade;
            metadata.Metadata.TargetAssessmentType      = "Test target string";
            metadata.Metadata.SufficientEvidenceOfClaim = "Test claim string";
            metadata.Metadata.InteractionType           = "2";
            metadata.Metadata.SubjectCode               = "MATH";
            metadata.Metadata.MaximumNumberOfPoints     = 2;
            metadata.Metadata.StandardPublications      = new List <StandardPublication>();
            metadata.Metadata.StandardPublications.Add(
                new StandardPublication
            {
                PrimaryStandard = "SBAC-ELA-v1:3-L|4-6|6.SL.2",
                Publication     = "SupportedPubs"
            });

            contents.Item.ItemKey  = testItemKey;
            contents.Item.ItemBank = testItemBank;
            contents.Item.Contents = new List <Content>();
            var placeholderText = new RubricPlaceHolderText
            {
                RubricPlaceHolderContains = new string[] { "RubricSampleText", "RubricSampleText1" },
                RubricPlaceHolderEquals   = new string[0]
            };

            settings = new SettingsConfig
            {
                SupportedPublications = new string[] { "SupportedPubs" },
                AccessibilityTypes    = new List <AccessibilityType>()
                {
                    accessibilityType
                },
                InteractionTypesToItem       = new Dictionary <string, string>(),
                DictionarySupportedItemTypes = new List <string>(),
                LanguageToLabel = new Dictionary <string, string>()
            };

            appSettings = new AppSettings
            {
                SettingsConfig        = settings,
                RubricPlaceHolderText = placeholderText
            };

            digest = ItemDigestTranslation.ToItemDigest(metadata, contents, appSettings);
        }