Ejemplo n.º 1
0
        public void Update_WhenChecklistIsMapped_UpdatesAnswers()
        {
            // Arrange.
            var request = new TestRequest();
            request.SourceItems.Add(new TestData { Text = "aaa", Number = 111 });
            request.SourceItems.Add(new TestData { Text = "bbb", Number = 222 });

            var dataContext = new SourceData(request);

            var childMapping1 = new SimpleFieldMapping(
                ReflectionHelper.GetProperty<TestAnswer>(x => x.Text),
                dc => dc.GetPropertyValue("SourceItems.Text"),
                true,
                new SafeTypeConverter());
            var childMapping2 = new SimpleFieldMapping(
                ReflectionHelper.GetProperty<TestAnswer>(x => x.Number),
                dc => dc.GetPropertyValue("SourceItems.Number"),
                false,
                new SafeTypeConverter());

            var dtm = Mock.Create<IDynamicTypeManager>(Behavior.Loose);
            Mock.Arrange(() => dtm.NewEditableChild<IEditableRoot>(AnswerProcessName)).Returns(() => new TestAnswer());

            var mapping = new ChecklistFieldMapping(
                ReflectionHelper.GetProperty<TestEdit>(x => x.Checklist),
                dc => dc.EnumerateItems("SourceItems"),
                new[] { childMapping1, childMapping2 },
                dtm);

            var editItem = new TestEdit();

            // Act.
            mapping.Update(dataContext, editItem);

            // Assert.
            Assert.AreEqual(2, editItem.Checklist.AnswerProcessList.Count);

            var answer1 = (TestAnswer)editItem.Checklist.AnswerProcessList[0];
            Assert.AreEqual("aaa", answer1.Text);
            Assert.AreEqual(111, answer1.Number);

            var answer2 = (TestAnswer)editItem.Checklist.AnswerProcessList[1];
            Assert.AreEqual("bbb", answer2.Text);
            Assert.AreEqual(222, answer2.Number);
        }
Ejemplo n.º 2
0
        public void Update_WhenChecklistIsNotMapped_UpdatesAnswers()
        {
            // Arrange.
            var request = new TestRequest { RootText = "abc", RootNumber = 123 };
            var dataContext = new SourceData(request);

            var childMapping1 = new SimpleFieldMapping(
                ReflectionHelper.GetProperty<TestAnswer>(x => x.Text),
                dc => dc.GetPropertyValue("RootText"),
                false,
                new SafeTypeConverter());
            var childMapping2 = new SimpleFieldMapping(
                ReflectionHelper.GetProperty<TestAnswer>(x => x.Number),
                dc => dc.GetPropertyValue("RootNumber"),
                true,
                new SafeTypeConverter());

            var dtm = Mock.Create<IDynamicTypeManager>(Behavior.Loose);
            Mock.Arrange(() => dtm.NewEditableChild<IEditableRoot>(AnswerProcessName)).Returns(() => new TestAnswer());

            var mapping = new ChecklistFieldMapping(ReflectionHelper.GetProperty<TestEdit>(x => x.Checklist), null, new[] { childMapping1, childMapping2 }, dtm);

            var editItem = new TestEdit();

            // Act.
            mapping.Update(dataContext, editItem);

            // Assert.
            Assert.AreEqual(1, editItem.Checklist.AnswerProcessList.Count);

            var answer = (TestAnswer)editItem.Checklist.AnswerProcessList[0];
            Assert.AreEqual("abc", answer.Text);
            Assert.AreEqual(123, answer.Number);
        }