示例#1
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());
        }
示例#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());
        }
示例#3
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());
        }