コード例 #1
0
        public void IsExcludedChildType_Returns_Expected(string parentType, string childType, bool expectedResult)
        {
            var excludedChildTypes = new List <ParentChildTypePair>
            {
                new ParentChildTypePair
                {
                    ParentType = "cms.role",
                    ChildType  = "cms.userrole"
                },
                new ParentChildTypePair
                {
                    ParentType = "cms.user",
                    ChildType  = "cms.badge"
                }
            };

            var mockSettingsRepository =
                CreateMockSettingsRepository(excludedChildTypes: excludedChildTypes);
            var mockEventLogService                 = CreateMockEventLogService();
            var stagingCustomizationHelper          = new StagingConfigurationHelper(mockSettingsRepository.Object, mockEventLogService.Object);
            var stagingChildProcessingTypeEventArgs = new StagingChildProcessingTypeEventArgs()
            {
                ParentObjectType = parentType,
                ObjectType       = childType
            };
            bool result = stagingCustomizationHelper.IsExcludedChildType(stagingChildProcessingTypeEventArgs);

            Assert.AreEqual(expectedResult, result);
        }
コード例 #2
0
        /// <summary>
        /// Test if the provided StagingChildProcessingTypeEventArgs represents a parent type/child type relationship that is in
        /// the exclusion list.
        /// </summary>
        /// <param name="eventArgs"></param>
        /// <returns>Returns true if the parent/child type relationship is in the exclusion list.</returns>
        public bool IsExcludedChildType(StagingChildProcessingTypeEventArgs eventArgs)
        {
            string currentParentType = eventArgs.ParentObjectType;
            string currentChildType  = eventArgs.ObjectType;

            return(_excludedChildTypes.Exists(pair =>
                                              pair.ParentType.Equals(currentParentType, StringComparison.OrdinalIgnoreCase) &&
                                              pair.ChildType.Equals(currentChildType, StringComparison.OrdinalIgnoreCase)));
        }
        /// <summary>
        /// Modify how object relationships are processed in the target environment, by changing the `ProcessingType` from
        /// `IncludeToParentEnum.Complete` to `IncludeToParentEnum.None`.  This will prevent a staging task from wiping out the
        /// child collection of an object, like deleting all the user relationships in a role.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        public void GetChildProcessingType(object sender, StagingChildProcessingTypeEventArgs eventArgs)
        {
            var currentParentType = eventArgs.ParentObjectType;
            var currentChildType  = eventArgs.ObjectType;

            if (_stagingCustomizationModuleHelper.IsExcludedChildType(eventArgs))
            {
                var message = $"Preventing {currentChildType} from being synchronized with {currentParentType}.";
                _stagingCustomizationModuleHelper.LogInformation("ExcludeChildType", message);
                eventArgs.ProcessingType = IncludeToParentEnum.None;
            }
        }