public void ValidatePropertyChangeEventData_Description_ArtifactTypesAssociated_NoError()
        {
            // Arrange
            var propertyType = new PropertyType { Id = WorkflowConstants.PropertyTypeFakeIdDescription, Name = "Description" };
            var artifactType = new ItemType { Id = 1 };
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            result.StandardPropertyTypeMapByName.Add(propertyType.Name, propertyType);
            result.StandardTypes.ArtifactTypes.Add(artifactType);
            result.AssociatedArtifactTypeIds.Add(artifactType.Id);
            var propertyChangeEvent = new IePropertyChangeEvent { PropertyName = propertyType.Name };

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeEventData(result, propertyChangeEvent, true);

            // Assert
            Assert.AreEqual(false, result.HasErrors);
            Assert.AreEqual(0, result.Errors.Count);
        }
        public void ValidatePropertyChangeEventData_Name_NoArtifactTypesAssociated_Error()
        {
            // Arrange
            var propertyType = new PropertyType { Id = WorkflowConstants.PropertyTypeFakeIdName, Name = "Name" };
            var artifactType = new ItemType { Id = 1 };
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            result.StandardPropertyTypeMapByName.Add(propertyType.Name, propertyType);
            result.StandardTypes.ArtifactTypes.Add(artifactType);
            var propertyChangeEvent = new IePropertyChangeEvent { PropertyName = propertyType.Name };

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeEventData(result, propertyChangeEvent, true);

            // Assert
            Assert.AreEqual(true, result.HasErrors);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyNotAssociated, result.Errors[0].ErrorCode);
            Assert.AreEqual(propertyType.Name, result.Errors[0].Element as string);
        }
        public void ValidatePropertyChangeEventData_CustomProperty_AssociatedWithArtifactTypes_NoError()
        {
            // Arrange
            var propertyType = new PropertyType { Id = 1, Name = "My Standard Property" };
            var artifactType = new ItemType { Id = 1 };
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            result.StandardPropertyTypeMapByName.Add(propertyType.Name, propertyType);
            result.StandardTypes.ArtifactTypes.Add(artifactType);
            result.AssociatedArtifactTypeIds.Add(artifactType.Id);
            var propertyChangeEvent = new IePropertyChangeEvent { PropertyName = propertyType.Name };


            artifactType.CustomPropertyTypeIds.Add(propertyType.Id);

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeEventData(result, propertyChangeEvent, true);

            // Assert
            Assert.AreEqual(false, result.HasErrors);
            Assert.AreEqual(0, result.Errors.Count);
        }
        internal void ValidatePropertyChangeEventData(WorkflowDataValidationResult result, IePropertyChangeEvent pcEvent, bool ignoreIds)
        {
            if (pcEvent == null)
            {
                return;
            }

            PropertyType propertyType;

            // Update Name where Id is present (to null if Id is not found)
            if (!ignoreIds && pcEvent.PropertyId.HasValue)
            {
                if (!WorkflowHelper.TryGetNameOrDescriptionPropertyType(pcEvent.PropertyId.Value, out propertyType) &&
                    !result.StandardPropertyTypeMapById.TryGetValue(pcEvent.PropertyId.Value, out propertyType))
                {
                    result.Errors.Add(new WorkflowDataValidationError
                    {
                        Element   = pcEvent.PropertyId.Value,
                        ErrorCode = WorkflowDataValidationErrorCodes.PropertyNotFoundById
                    });
                }

                pcEvent.PropertyName = propertyType?.Name;
            }

            if (pcEvent.PropertyName != null)
            {
                if (!WorkflowHelper.TryGetNameOrDescriptionPropertyType(pcEvent.PropertyName, out propertyType) &&
                    !result.StandardPropertyTypeMapByName.TryGetValue(pcEvent.PropertyName, out propertyType))
                {
                    result.Errors.Add(new WorkflowDataValidationError
                    {
                        Element   = pcEvent.PropertyName,
                        ErrorCode = WorkflowDataValidationErrorCodes.PropertyNotFoundByName
                    });

                    return;
                }

                if (!IsAssociatedWithWorkflowArtifactTypes(propertyType, result))
                {
                    result.Errors.Add(new WorkflowDataValidationError
                    {
                        Element   = pcEvent.PropertyName,
                        ErrorCode = WorkflowDataValidationErrorCodes.PropertyNotAssociated
                    });

                    return;
                }
            }

            pcEvent.Triggers?.ForEach(t => ValidateTriggerData(result, t, ignoreIds));
        }