Exemple #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));
        }
Exemple #2
0
        public void DataTriggerCanRemoveItems()
        {
            // Arrange.
            const string DestinationProcess = "DestinationProcess";
            const string FilterDefinition = "Test Filter";

            var destinationInfo1 = Mock.Create<IInfoClass>();
            Mock.Arrange(() => destinationInfo1.Id).Returns(111);

            var destinationEdit1 = Mock.Create<IEditableRootStub>();
            var savable1 = destinationEdit1 as ISavable;
            var ebo1 = destinationEdit1 as IEditableBusinessObject;
            Mock.Arrange(() => destinationEdit1.Id).Returns(111);

            var destinationInfo2 = Mock.Create<IInfoClass>();
            Mock.Arrange(() => destinationInfo2.Id).Returns(222);

            var destinationEdit2 = Mock.Create<IEditableRootStub>();
            var savable2 = destinationEdit2 as ISavable;
            var ebo2 = destinationEdit2 as IEditableBusinessObject;
            Mock.Arrange(() => destinationEdit2.Id).Returns(222);

            var sourceItem = Mock.Create<IEditableRoot>();
            var oldSourceItem = Mock.Create<IEditableRoot>();

            SetupGetEditableRoot(DestinationProcess, destinationEdit1, destinationEdit2);

            var filter = Mock.Create<IFilterDescriptor>();

            Mock.Arrange(() => _dtm.GetList<IInfoList>(DestinationProcess, string.Empty, 0, int.MaxValue, null, Arg.IsAny<FilterList>(), Arg.IsAny<bool>()))
                .Returns<string, string, int, int, SortList, FilterList, bool>(
                    (processName, globalFilter, pageNumber, pageSize, sortList, filterList, calculateAccess) =>
                        {
                            if (filterList != null && filterList.Count == 1 && filterList.Contains(filter)) return new InfoListBase { destinationInfo1, destinationInfo2 };

                            return new InfoListBase();
                        });

            var filterFactory = Mock.Create<IFilterDescriptorFactory>();
            Mock.Arrange(() => filterFactory.CreateFilterFromJSON(FilterDefinition)).Returns(filter);

            var trigger = new DataTrigger
                              {
                                  DynamicTypeManager = _dtm,
                                  FilterDescriptorFactory = filterFactory,
                                  Name = "Test Trigger",
                                  Logger = Mock.Create<ILogger>(),
                                  Guid = Guid.NewGuid(),
                                  DestinationProcess = DestinationProcess,
                                  ModificationType = DataTriggerModificationType.Remove,
                                  FilterDefinition = FilterDefinition
                              };

            // Act.
            trigger.AfterItemUpdate(sourceItem, oldSourceItem);

            // Assert.
            Mock.Assert(() => filter.ReplacePredefinedValues(sourceItem), Occurs.Once());

            Mock.Assert(() => ebo1.Delete(), Occurs.Once());
            Mock.Assert(() => savable1.Save(), Occurs.Once());

            Mock.Assert(() => ebo2.Delete(), Occurs.Once());
            Mock.Assert(() => savable2.Save(), Occurs.Once());
        }
Exemple #3
0
        public void DataTriggerCanStartNewVersions()
        {
            // Arrange.
            const string DestinationProcess = "DestinationProcess";
            const string FilterDefinition = "Test Filter";

            var destinationInfo1 = Mock.Create<IInfoClass>();
            Mock.Arrange(() => destinationInfo1.Id).Returns(111);

            var destinationEdit1 = Mock.Create<ISupportVersioningStub>();
            var newDestinationEdit1 = Mock.Create<ISupportVersioningStub>();
            var savable1 = newDestinationEdit1 as ISavable;
            Mock.Arrange(() => destinationEdit1.Id).Returns(111);
            Mock.Arrange(() => destinationEdit1.StartNewVersion()).Returns(newDestinationEdit1);

            var destinationInfo2 = Mock.Create<IInfoClass>();
            Mock.Arrange(() => destinationInfo2.Id).Returns(222);

            var destinationEdit2 = Mock.Create<ISupportVersioningStub>();
            var newDestinationEdit2 = Mock.Create<ISupportVersioningStub>();
            var savable2 = newDestinationEdit2 as ISavable;
            Mock.Arrange(() => destinationEdit2.Id).Returns(222);
            Mock.Arrange(() => destinationEdit2.StartNewVersion()).Returns(newDestinationEdit2);

            var sourceItem = Mock.Create<IEditableRoot>();
            var oldSourceItem = Mock.Create<IEditableRoot>();

            SetupGetEditableRoot(DestinationProcess, destinationEdit1, destinationEdit2);

            var filter = Mock.Create<IFilterDescriptor>();

            Mock.Arrange(() => _dtm.GetList<IInfoList>(DestinationProcess, string.Empty, 0, int.MaxValue, null, Arg.IsAny<FilterList>(), Arg.IsAny<bool>()))
                .Returns<string, string, int, int, SortList, FilterList, bool>(
                    (processName, globalFilter, pageNumber, pageSize, sortList, filterList, calculateAccess) =>
                    {
                        if (filterList != null && filterList.Count == 1 && filterList.Contains(filter)) return new InfoListBase { destinationInfo1, destinationInfo2 };

                        return new InfoListBase();
                    });

            var filterFactory = Mock.Create<IFilterDescriptorFactory>();
            Mock.Arrange(() => filterFactory.CreateFilterFromJSON(FilterDefinition)).Returns(filter);

            var fieldUpdater1 = Mock.Create<IFieldUpdater>();
            Mock.Arrange(() => fieldUpdater1.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), Arg.IsAny<IEditableRoot>())).DoInstead<DataTriggerSourceData, IEditableRoot>(
                (s, d) =>
                {
                    if (s.GetSourceItem(DataTriggerMappingExpressionNames.SourceItem) != sourceItem) Assert.Fail("Source item not found.");
                });

            var fieldUpdater2 = Mock.Create<IFieldUpdater>();
            Mock.Arrange(() => fieldUpdater2.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), Arg.IsAny<IEditableRoot>())).DoInstead<DataTriggerSourceData, IEditableRoot>(
                (s, d) =>
                {
                    if (s.GetSourceItem(DataTriggerMappingExpressionNames.SourceItem) != sourceItem) Assert.Fail("Source item not found.");
                });

            var listUpdater1 = Mock.Create<IListFieldUpdater>();
            var listUpdater2 = Mock.Create<IListFieldUpdater>();

            var trigger = new DataTrigger
                              {
                                  DynamicTypeManager = _dtm,
                                  Logger = Mock.Create<ILogger>(),
                                  FilterDescriptorFactory = filterFactory,
                                  Name = "Test Trigger",
                                  Guid = Guid.NewGuid(),
                                  DestinationProcess = DestinationProcess,
                                  ModificationType = DataTriggerModificationType.StartVersion,
                                  FilterDefinition = FilterDefinition
                              };

            trigger.FieldUpdaters.Add(fieldUpdater1);
            trigger.FieldUpdaters.Add(fieldUpdater2);
            trigger.ListFieldUpdaters.Add(listUpdater1);
            trigger.ListFieldUpdaters.Add(listUpdater2);

            // Act.
            trigger.AfterItemUpdate(sourceItem, oldSourceItem);

            // Assert.
            Mock.Assert(() => listUpdater1.AfterItemUpdate(sourceItem, oldSourceItem), Occurs.Once());
            Mock.Assert(() => listUpdater2.AfterItemUpdate(sourceItem, oldSourceItem), Occurs.Once());

            Mock.Assert(() => filter.ReplacePredefinedValues(sourceItem), Occurs.Once());

            Mock.Assert(() => fieldUpdater1.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), newDestinationEdit1), Occurs.Once());
            Mock.Assert(() => fieldUpdater1.Update(newDestinationEdit1), Occurs.Once());

            Mock.Assert(() => fieldUpdater2.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), newDestinationEdit1), Occurs.Once());
            Mock.Assert(() => fieldUpdater2.Update(newDestinationEdit1), Occurs.Once());

            Mock.Assert(() => listUpdater1.Update(sourceItem, newDestinationEdit1), Occurs.Once());
            Mock.Assert(() => listUpdater2.Update(sourceItem, newDestinationEdit1), Occurs.Once());

            Mock.Assert(() => savable1.Save(), Occurs.Once());

            Mock.Assert(() => fieldUpdater1.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), newDestinationEdit2), Occurs.Once());
            Mock.Assert(() => fieldUpdater1.Update(newDestinationEdit2), Occurs.Once());

            Mock.Assert(() => fieldUpdater2.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), newDestinationEdit2), Occurs.Once());
            Mock.Assert(() => fieldUpdater2.Update(newDestinationEdit2), Occurs.Once());

            Mock.Assert(() => listUpdater1.Update(sourceItem, newDestinationEdit2), Occurs.Once());
            Mock.Assert(() => listUpdater2.Update(sourceItem, newDestinationEdit2), Occurs.Once());

            Mock.Assert(() => savable2.Save(), Occurs.Once());
        }
Exemple #4
0
        public void DataTriggerCanInsertItems()
        {
            // Arrange.
            const string DestinationProcess = "DestinationProcess";

            var destinationItem = Mock.Create<IEditableRootStub>();
            var savableDestinationItem = destinationItem as ISavable;

            var sourceItem = Mock.Create<IEditableRoot>();
            var oldSourceItem = Mock.Create<IEditableRoot>();

            var dtm = Mock.Create<IDynamicTypeManager>();
            Mock.Arrange(() => dtm.NewEditableRoot<IEditableRoot>(DestinationProcess)).Returns(destinationItem);

            var fieldUpdater1 = Mock.Create<IFieldUpdater>();
            Mock.Arrange(() => fieldUpdater1.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), destinationItem)).DoInstead<DataTriggerSourceData, IEditableRoot>(
                (s, d) =>
                    {
                        if (s.GetSourceItem(DataTriggerMappingExpressionNames.SourceItem) != sourceItem) Assert.Fail("Source item not found.");
                    });

            var fieldUpdater2 = Mock.Create<IFieldUpdater>();
            Mock.Arrange(() => fieldUpdater2.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), destinationItem)).DoInstead<DataTriggerSourceData, IEditableRoot>(
                (s, d) =>
                    {
                        if (s.GetSourceItem(DataTriggerMappingExpressionNames.SourceItem) != sourceItem) Assert.Fail("Source item not found.");
                    });

            var listUpdater1 = Mock.Create<IListFieldUpdater>();
            var listUpdater2 = Mock.Create<IListFieldUpdater>();

            var trigger = new DataTrigger
                              {
                                  DynamicTypeManager = dtm,
                                  Logger = Mock.Create<ILogger>(),
                                  Name = "Test Trigger",
                                  Guid = Guid.NewGuid(),
                                  DestinationProcess = DestinationProcess,
                                  ModificationType = DataTriggerModificationType.Insert
                              };

            trigger.FieldUpdaters.Add(fieldUpdater1);
            trigger.FieldUpdaters.Add(fieldUpdater2);
            trigger.ListFieldUpdaters.Add(listUpdater1);
            trigger.ListFieldUpdaters.Add(listUpdater2);

            // Act.
            trigger.AfterItemUpdate(sourceItem, oldSourceItem);

            // Assert.
            Mock.Assert(() => listUpdater1.AfterItemUpdate(sourceItem, oldSourceItem), Occurs.Once());
            Mock.Assert(() => listUpdater2.AfterItemUpdate(sourceItem, oldSourceItem), Occurs.Once());

            Mock.Assert(() => fieldUpdater1.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), destinationItem), Occurs.Once());
            Mock.Assert(() => fieldUpdater1.Update(destinationItem), Occurs.Once());

            Mock.Assert(() => fieldUpdater2.CalculateNewValue(Arg.IsAny<DataTriggerSourceData>(), destinationItem), Occurs.Once());
            Mock.Assert(() => fieldUpdater2.Update(destinationItem), Occurs.Once());

            Mock.Assert(() => listUpdater1.Update(sourceItem, destinationItem), Occurs.Once());
            Mock.Assert(() => listUpdater2.Update(sourceItem, destinationItem), Occurs.Once());

            Mock.Assert(() => (savableDestinationItem as ISavable).Save(), Occurs.Once());
        }
Exemple #5
0
        public void BeforeItemUpdateTest()
        {
            // Arrange.
            var listUpdater1 = Mock.Create<IListFieldUpdater>();
            var listUpdater2 = Mock.Create<IListFieldUpdater>();

            var trigger = new DataTrigger();
            trigger.ListFieldUpdaters.Add(listUpdater1);
            trigger.ListFieldUpdaters.Add(listUpdater2);

            var item = Mock.Create<IEditableRoot>();
            var oldItem = Mock.Create<IEditableRoot>();

            // Act.
            trigger.BeforeItemUpdate(item, oldItem);

            // Assert.
            Mock.Assert(() => listUpdater1.BeforeItemUpdate(item, oldItem), Occurs.Once());
            Mock.Assert(() => listUpdater2.BeforeItemUpdate(item, oldItem), Occurs.Once());
        }
        public void FactoryCreateExportShouldReturnNewDataTrigger()
        {
            var trigger = new DataTrigger();
            var factory = new DataTriggerFactory();
            var triggerDefinition = new DataTriggerDefinition(
                "test",
                Guid.Empty,
                "test",
                "test",
                DataTriggerModificationType.Insert,
                Enumerable.Empty<IActionRule>(),
                new DataTriggerMap(Enumerable.Empty<DataTriggerFieldMapping>(), Enumerable.Empty<DataTriggerListFieldMapping>()));

            factory.ProcessTriggerFactory = new ExportFactory<DataTrigger>(() => new Tuple<DataTrigger, Action>(trigger, () => { }));

            Assert.AreSame(trigger, factory.CreateDataTrigger("test", triggerDefinition));
        }