public void Save_QuestionThatExist_UpdateDatabaseAndReturn()
        {
            var questionireGateway = new Mock <IQuestionnaireGateway>();

            Context.QuestionnaireGateway = questionireGateway.Object;
            var gateway       = new McmQuestionGateway(Mcm.Object);
            var questionnaire = TestResources.Make_Questionnaire();
            var question      = new Question("Test")
            {
                Id     = "6a0fae3a-2ac0-477b-892a-b24433ff3bd2:4",
                Output =
                    new Output
                {
                    SimpleValues = new []
                    {
                        new SimpleValue("Text", "Mars")
                    }
                }
            };

            questionireGateway.Setup(m => m.Get(It.IsAny <Guid>())).Returns(questionnaire);

            var result = gateway.Save(question);

            Assert.That(result.Output.SimpleValues.First().Key, Is.EqualTo("Text"));
            Assert.That(result.Output.SimpleValues.First().Value, Is.EqualTo("Mars"));
            questionireGateway.Verify(m => m.Set(It.IsAny <Questionnaire>()));
        }
Example #2
0
        public void ComplexMultiValue_ValidateCorrectly()
        {
            var questionnaire = TestResources.Make_Questionnaire();

            var question = questionnaire.GetQuestion("6a0fae3a-2ac0-477b-892a-b24433ff3bd2:0");

            question.Output = new Output
            {
                MultiValues = new[]
                {
                    new MultiValue
                    {
                        Key           = "Events",
                        ComplexValues = new[]
                        {
                            new ComplexValue
                            {
                                SimpleValues = new[]
                                {
                                    new SimpleValue("Id", " "),
                                    new SimpleValue("Type", "Trial Start"),
                                    new SimpleValue("Method", " "),
                                    new SimpleValue("Data", " "),
                                    new SimpleValue("DateTime", "2015-04-03T08:37:27.805Z"),
                                }
                            }
                        }
                    }
                }
            };
        }
        public void Set_ObjectFoundButNoMetadta_Throw()
        {
            var obj = new Chaos.Mcm.Data.Dto.Object
            {
                Guid         = new Guid("6a0fae3a-2ac0-477b-892a-b24433ff3bd2"),
                ObjectTypeID = Context.Config.ExperimentObjectTypeId
            };
            var questionnaire = TestResources.Make_Questionnaire();

            mcm.Setup(m => m.ObjectGet(obj.Guid, true, false, false, false, false)).Returns(obj);

            Make_QuestionnaireGateway().Set(questionnaire);
        }
        public void Set_IdMatchesWrongObjectType_Throw()
        {
            var obj = new Chaos.Mcm.Data.Dto.Object
            {
                Guid         = new Guid("6a0fae3a-2ac0-477b-892a-b24433ff3bd2"),
                ObjectTypeID = 999 // wrong id
            };
            var questionnaire = TestResources.Make_Questionnaire();

            mcm.Setup(m => m.ObjectGet(obj.Guid, true, false, false, false, false)).Returns(obj);

            Make_QuestionnaireGateway().Set(questionnaire);
        }
Example #5
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"));
        }
        public void Set_QuestionnaireFound_SetMetadata()
        {
            var obj           = TestResources.Make_QuestionnaireObject();
            var questionnaire = TestResources.Make_Questionnaire();
            var question      = new Question("Test")
            {
                Id     = "6a0fae3a-2ac0-477b-892a-b24433ff3bd2:4",
                Output =
                    new Output
                {
                    SimpleValues = new[] { new SimpleValue("Text", "Mars"), }
                }
            };

            questionnaire.GetQuestion(question.Id).Output = question.Output;
            mcm.Setup(m => m.ObjectGet(obj.Guid, true, false, false, false, false)).Returns(obj);

            var result = Make_QuestionnaireGateway().Set(questionnaire);

            Assert.That(result.Id, Is.EqualTo(questionnaire.Id));
            mcm.Verify(m => m.MetadataSet(obj.Guid, It.IsAny <Guid>(), Context.Config.ExperimentMetadataSchemaId, null, 0, It.IsAny <XDocument>(), It.IsAny <Guid>()));
        }
Example #7
0
        public void Serialize_MultiValueComplexValueDoesntHaveAKey_UseItemAsKey()
        {
            var questionnaire = TestResources.Make_Questionnaire();

            var question = questionnaire.GetQuestion("6a0fae3a-2ac0-477b-892a-b24433ff3bd2:0");

            question.Output = new Output
            {
                MultiValues = new[]
                {
                    new MultiValue
                    {
                        Key           = "Events",
                        ComplexValues = new[]
                        {
                            new ComplexValue
                            {
                                SimpleValues = new[]
                                {
                                    new SimpleValue("Id", " "),
                                    new SimpleValue("Type", "Trial Start"),
                                    new SimpleValue("Method", " "),
                                    new SimpleValue("Data", " "),
                                    new SimpleValue("DateTime", "2015-04-03T08:37:27.805Z"),
                                }
                            }
                        }
                    }
                }
            };

            var result = new DtuFormatConverter().Serialize(questionnaire);

            Assert.That(
                result.Descendants("Outputs").First().Descendants("Events").First().Elements().All(item => item.Name == "Item"),
                Is.True);
        }
        public void Set_IdNotFound_Throw()
        {
            var questionnaire = TestResources.Make_Questionnaire();

            Make_QuestionnaireGateway().Set(questionnaire);
        }