Пример #1
0
        public void InitializeTest()
        {
            // Arrange.
            const string ProcessName = "TestProcess";
            const string TriggerName = "Test Trigger";
            var triggerGuid = new Guid("{A05F4E80-E1C6-4115-8582-0A823081BB19}");
            const string ProcessToModify = "DestinationProcess";
            const string FilterDefinition = "Test Filter";
            const DataTriggerModificationType ModificationType = DataTriggerModificationType.Update;

            var fieldMapping1 = new DataTriggerFieldMapping("Field1", false, (s, d) => null);
            var fieldMapping2 = new DataTriggerFieldMapping("Field2", false, (s, d) => null);

            var listMapping1 = new DataTriggerListFieldMapping(
                Enumerable.Empty<FieldMappingDataSourceDefinition>(),
                "Field3",
                DataTriggerModificationType.Insert,
                Enumerable.Empty<DataTriggerFieldMapping>());

            var listMapping2 = new DataTriggerListFieldMapping(
                Enumerable.Empty<FieldMappingDataSourceDefinition>(),
                "Field4",
                DataTriggerModificationType.Insert,
                Enumerable.Empty<DataTriggerFieldMapping>());

            var triggerMap = new DataTriggerMap(new[] { fieldMapping1, fieldMapping2 }, new[] { listMapping1, listMapping2 });

            var triggerDefinition = new DataTriggerDefinition(TriggerName, triggerGuid, ProcessToModify, FilterDefinition, ModificationType, Enumerable.Empty<IActionRule>(), triggerMap);

            var fieldUpdater1 = Mock.Create<IFieldUpdater>();
            var fieldUpdater2 = Mock.Create<IFieldUpdater>();
            var fieldUpdaterFactory = Mock.Create<IFieldUpdaterFactory>();
            Mock.Arrange(() => fieldUpdaterFactory.CreateFieldUpdater(ProcessToModify, fieldMapping1)).Returns(fieldUpdater1);
            Mock.Arrange(() => fieldUpdaterFactory.CreateFieldUpdater(ProcessToModify, fieldMapping2)).Returns(fieldUpdater2);

            var listUpdater1 = Mock.Create<IListFieldUpdater>();
            var listUpdater2 = Mock.Create<IListFieldUpdater>();
            var listUpdaterFactory = Mock.Create<IListFieldUpdaterFactory>();
            Mock.Arrange(() => listUpdaterFactory.CreateFieldUpdater(ProcessToModify, listMapping1)).Returns(listUpdater1);
            Mock.Arrange(() => listUpdaterFactory.CreateFieldUpdater(ProcessToModify, listMapping2)).Returns(listUpdater2);

            var trigger = new DataTrigger { FieldUpdaterFactory = fieldUpdaterFactory, ListFieldUpdaterFactory = listUpdaterFactory };

            // Act.
            trigger.Initialize(ProcessName, triggerDefinition);

            // Assert.
            Assert.AreEqual(TriggerName, trigger.Name);
            Assert.AreEqual(triggerGuid, trigger.Guid);
            Assert.AreEqual(ModificationType, trigger.ModificationType);
            Assert.AreEqual(ProcessToModify, trigger.DestinationProcess);
            Assert.AreEqual(FilterDefinition, trigger.FilterDefinition);
            Assert.AreEqual(2, trigger.FieldUpdaters.Count);
            Assert.IsTrue(trigger.FieldUpdaters.Contains(fieldUpdater1));
            Assert.IsTrue(trigger.FieldUpdaters.Contains(fieldUpdater2));
            Assert.AreEqual(2, trigger.ListFieldUpdaters.Count);
            Assert.IsTrue(trigger.ListFieldUpdaters.Contains(listUpdater1));
            Assert.IsTrue(trigger.ListFieldUpdaters.Contains(listUpdater2));
        }