Exemplo n.º 1
0
        public void Deserialize_ExperimentWithHeaders_Return()
        {
            var converter = new DtuFormatConverter();
            var xml       = XDocument.Load("Resources\\experiment6.xml");

            var result = converter.Deserialize(xml);

            Assert.That(result.Css, Is.EqualTo("url"));
            Assert.That(result.LockQuestion, Is.True);
            Assert.That(result.RedirectOnCloseUrl, Is.EqualTo("http://www.dtu.dk"));
            Assert.That(result.EnablePrevious, Is.True);
            Assert.That(result.FooterLabel, Is.EqualTo("No.: 7 - an {{b|TEST}} experiment by {{link|http://www.dtu.dk|DTU}}. Privacy etc can be located at bla bla"));
        }
Exemplo n.º 2
0
        public void Serialize_GivenQuestionWithComplexValue_SerializeComplexTypesToo()
        {
            var converter = new DtuFormatConverter();
            var xml       = XDocument.Load("Resources\\experiment5.xml");

            var result  = converter.Deserialize(xml);
            var result2 = converter.Serialize(result);

            Assert.That(result2.Descendants("DRQuestionCore").First().Element("Outputs").Element("Validation").Element("ComplexValue"), Is.Not.Null);
            Assert.That(result2.Descendants("DRQuestionCore").First().Element("Outputs").Element("Value").Element("Response"), Is.Not.Null);
            Assert.That(result2.Descendants("DRQuestionCore").First().Element("Outputs").Element("Value").Element("Response").Element("FreeText"), Is.Not.Null);
            Assert.That(result2.Descendants("DRQuestionCore").First().Element("Outputs").Element("Value").Element("Response").Element("Grading"), Is.Not.Null);
        }
Exemplo n.º 3
0
        public void Deserialize_GivenQuestionWithComplexValue_ValueAndValidationShouldBeParsed()
        {
            var converter = new DtuFormatConverter();
            var xml       = XDocument.Load("Resources\\experiment5.xml");

            var result = converter.Deserialize(xml);

            Assert.That(result.Slides[0].Questions[0].Validation.ComplexValueValidator.Count, Is.EqualTo(1));
            Assert.That(result.Slides[0].Questions[0].Output.ComplexValues.Count, Is.EqualTo(1));

            var q = QuestionnaireBuilder.MakeDto(result);

            Assert.That(q.Slides[0].Questions[0].Values.Any(item => item.Key == "Response"), Is.True);
        }
Exemplo n.º 4
0
        public void Serialize_GivenQuestion_SerializeHeaders()
        {
            var converter     = new DtuFormatConverter();
            var xml           = XDocument.Load("Resources\\experiment6.xml");
            var questionnaire = converter.Deserialize(xml);

            var result = converter.Serialize(questionnaire);

            Assert.That(result.Root.Element("CSS").Value, Is.EqualTo("url"));
            Assert.That(result.Root.Element("LockQuestion").Value, Is.EqualTo("1"));
            Assert.That(result.Root.Element("EnablePrevious").Value, Is.EqualTo("1"));
            Assert.That(result.Root.Element("FooterLabel").Value, Is.EqualTo("No.: 7 - an {{b|TEST}} experiment by {{link|http://www.dtu.dk|DTU}}. Privacy etc can be located at bla bla"));
            Assert.That(result.Root.Element("RedirectOnCloseUrl").Value, Is.EqualTo("http://www.dtu.dk"));
        }
Exemplo n.º 5
0
        public void Deserialize_GivenExperimentWithOneTask_ParseRequiredFields()
        {
            var converter = new DtuFormatConverter();
            var xml       = XDocument.Load("Resources\\experiment.xml");

            var result = converter.Deserialize(xml);

            Assert.That(result.Id, Is.EqualTo("ea3976c7-2d4a-4ef0-84a1-1d9e66f4a0e7"));
            Assert.That(result.Name, Is.EqualTo("DTU:Test:001"));
            Assert.That(result.Version, Is.EqualTo("1"));
            Assert.That(result.TargetId, Is.EqualTo("fba94e48-3c6d-4a2a-aef9-23108ee89ac0"));
            Assert.That(result.TargetName, Is.EqualTo("Jens Jensen"));
            Assert.That(result.Slides.Count, Is.EqualTo(8));
            Assert.That(result.Slides[0].TaskId, Is.EqualTo("0"));
            Assert.That(result.Slides[0].IsCompleted, Is.True);
            Assert.That(result.Slides[0].Questions.Count, Is.EqualTo(1));
            Assert.That(result.Slides[0].Questions[0].Id, Is.EqualTo("ea3976c7-2d4a-4ef0-84a1-1d9e66f4a0e7:0"));
            Assert.That(result.Slides[0].Questions[0].Version, Is.EqualTo("1"));
            Assert.That(result.Slides[0].Questions[0].Type, Is.EqualTo("Monitor"));
            Assert.That(result.Slides[0].Questions[0].Input, Is.Not.Empty);
            Assert.That(result.Slides[0].Questions[0].Output.MultiValues, Is.Not.Empty);
            var events = result.Slides[0].Questions[0].Validation.MultiValueValidator[0];

            Assert.That(events.Id, Is.EqualTo("Events"));
            Assert.That(events.Min, Is.EqualTo(0));
            Assert.That(events.Max, Is.EqualTo(uint.MaxValue));
            Assert.That(events.ComplexValueValidator.Id, Is.EqualTo("Event"));
            Assert.That(events.ComplexValueValidator.SimpleValueValidators[0].Id, Is.EqualTo("DateTime"));
            Assert.That(events.ComplexValueValidator.SimpleValueValidators[0].Validation,
                        Is.EqualTo(@"(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}.\d{3})Z"));
            Assert.That(result.Slides[1].IsCompleted, Is.False);
            Assert.That(result.Slides[1].Questions[0].Id, Is.EqualTo("ea3976c7-2d4a-4ef0-84a1-1d9e66f4a0e7:1"));
            Assert.That(result.Slides[1].Questions[0].Type, Is.EqualTo("Freetext"));
            Assert.That(result.Slides[1].Questions[0].Validation.SimpleValueValidator, Is.Not.Empty);
            Assert.That(result.Slides[1].Questions[1].Type, Is.EqualTo("RadioButtonGroup"));
            Assert.That(result.Slides[2].Questions[0].Type, Is.EqualTo("CheckBoxGroup"));
            Assert.That(result.Slides[2].Questions[0].Validation.MultiValueValidator[0].SimpleValueValidator.Id,
                        Is.EqualTo("Id"));
            Assert.That(result.Slides[2].Questions[0].Validation.MultiValueValidator[0].SimpleValueValidator.Validation,
                        Is.EqualTo(".*"));
            Assert.That(result.Slides[3].Questions[0].Type, Is.EqualTo("CheckBoxGroup"));
            Assert.That(result.Slides[4].Questions[0].Type, Is.EqualTo("CheckBoxGroup"));
            Assert.That(result.Slides[5].Questions[0].Type, Is.EqualTo("OneDScale"));
            Assert.That(result.Slides[6].Questions[0].Type, Is.EqualTo("TwoDKScaleDD"));
            Assert.That(result.Slides[7].Questions[0].Id, Is.EqualTo("ea3976c7-2d4a-4ef0-84a1-1d9e66f4a0e7:8"));
            Assert.That(result.Slides[7].Questions[0].Type, Is.EqualTo("Monitor"));
        }
Exemplo n.º 6
0
        public void Serialize_GivenQuestionair_ReturnXml()
        {
            var converter = new DtuFormatConverter();
            var xml       = XDocument.Load("Resources\\experiment.xml");
            var expected  = converter.Deserialize(xml);

            var actual = converter.Serialize(expected);

            var root = actual.Root;

            Assert.That(root.Name.LocalName, Is.EqualTo("Experiment"));
            Assert.That(root.Element("Id").Value, Is.EqualTo("ea3976c7-2d4a-4ef0-84a1-1d9e66f4a0e7"));
            Assert.That(root.Element("Name").Value, Is.EqualTo("DTU:Test:001"));
            Assert.That(root.Element("Version").Value, Is.EqualTo("1"));
            Assert.That(root.Element("Target").Attribute("Id").Value, Is.EqualTo("fba94e48-3c6d-4a2a-aef9-23108ee89ac0"));
            Assert.That(root.Element("Target").Attribute("Name").Value, Is.EqualTo("Jens Jensen"));
            Assert.That(root.Element("Trials").HasElements, Is.True);
            Func <int, XElement> trial = (index) => root.Element("Trials").Descendants("Trial").ToList()[index];

            Assert.That(trial(0).Attribute("TaskId").Value, Is.EqualTo("0"));
            Assert.That(trial(0).Attribute("IsClosed").Value, Is.EqualTo("true"));
            Assert.That(trial(1).Attribute("IsClosed").Value, Is.EqualTo("false"));
            Func <int, int, XElement> question =
                (trialIndex, questionIndex) => trial(trialIndex).Elements().ToList()[questionIndex];

            Assert.That(question(0, 0).Attribute("Version").Value, Is.EqualTo("1"));
            Assert.That(question(0, 0).Element("Inputs").HasElements, Is.True);
            Func <int, int, string, XElement> validation =
                (trialIndex, questionIndex, id) =>
                question(trialIndex, questionIndex)
                .Element("Outputs")
                .Element("Validation")
                .Elements()
                .Single(ele => ele.Attribute("Id").Value == id);

            Assert.That(validation(0, 0, "Events").Attribute("Max").Value, Is.EqualTo("Inf"));
            Assert.That(validation(0, 0, "Events").Attribute("Min").Value, Is.EqualTo("0"));
            Assert.That(validation(0, 0, "Events").Element("ComplexValue").Attribute("Id").Value, Is.EqualTo("Event"));
            Assert.That(validation(0, 0, "Events").Element("ComplexValue").Elements().First().Attribute("Id").Value,
                        Is.EqualTo("DateTime"));
            Assert.That(validation(1, 0, "Text").Attribute("Validation").Value, Is.EqualTo(".*"));
            Func <int, int, string, XElement> value =
                (trialIndex, questionIndex, id) =>
                question(trialIndex, questionIndex).Element("Outputs").Element("Value").Element(id);

            Assert.That(value(0, 0, "Events").Elements("Event").First().Element("Id").Value, Is.EqualTo(".\\"));
        }
Exemplo n.º 7
0
        public void SerializeAfterDeserialize_XmlShouldStillBeValid()
        {
            var converter     = new DtuFormatConverter();
            var questionnaire = TestResources.Make_Questionnaire();

            questionnaire.GetQuestion("6a0fae3a-2ac0-477b-892a-b24433ff3bd2:4").Output = new Output
            {
                SimpleValues = new[] { new SimpleValue("Text", "Mars") }
            };

            var serialized   = converter.Serialize(questionnaire);
            var deserialized = converter.Deserialize(serialized);

            Assert.That(serialized.ToString().Contains("Mars"), Is.True);
            Assert.That(deserialized.GetQuestion("6a0fae3a-2ac0-477b-892a-b24433ff3bd2:4").Output.SimpleValues.First().Key,
                        Is.EqualTo("Text"));
        }