Пример #1
0
        public void ValidatePropertyValue_Choice_WithIds_UniqueValidValues_Success()
        {
            // Arrange
            _propertyType.IsRequired        = true;
            _propertyType.IsMultipleAllowed = true;
            _propertyType.ValidValues       = new List <ValidValue>
            {
                new ValidValue {
                    Id = 1, Value = "value"
                },
                new ValidValue {
                    Id = 2, Value = "value"
                }
            };
            var action = new IePropertyChangeAction
            {
                ValidValues = new List <IeValidValue>
                {
                    new IeValidValue {
                        Id = 1, Value = "value"
                    },
                    new IeValidValue {
                        Id = 2, Value = "value"
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        private void Validate(IePropertyChangeAction action, bool ignoreIds)
        {
            var factory   = new PropertyValueValidatorFactory();
            var validator = factory.Create(_propertyType, null, null, ignoreIds);

            validator.Validate(action, _propertyType, _result);
        }
        public void ValidatePropertyValue_User_GroupNotFoundById_Failure()
        {
            // Arrange
            _propertyType.IsRequired = true;
            var group  = Tuple.Create("user", (int?)99);
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup
                        {
                            Id             = 22,
                            Name           = group.Item1,
                            GroupProjectId = group.Item2,
                            IsGroup        = true
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionGroupNotFoundById, _result.Errors.Single().ErrorCode);
        }
        public void ValidatePropertyValue_User_UserNotFoundById_Failure()
        {
            // Arrange
            _propertyType.IsRequired = true;
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup
                        {
                            Id      = 22,
                            Name    = "user",
                            IsGroup = false
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionUserNotFoundById, _result.Errors.Single().ErrorCode);
        }
Пример #5
0
        private static XmlPropertyChangeAction ToXmlModel(IePropertyChangeAction ieAction, WorkflowDataMaps dataMaps)
        {
            if (ieAction == null)
            {
                return(null);
            }

            var xmlAction = new XmlPropertyChangeAction
            {
                Name          = ieAction.Name,
                PropertyValue = ieAction.PropertyValue,
                UsersGroups   = ToXmlModel(ieAction.UsersGroups, dataMaps)
            };

            int propertyTypeId;

            if (!dataMaps.PropertyTypeMap.TryGetValue(ieAction.PropertyName, out propertyTypeId) &&
                !WorkflowHelper.TryGetNameOrDescriptionPropertyTypeId(ieAction.PropertyName, out propertyTypeId))
            {
                throw new ExceptionWithErrorCode(I18NHelper.FormatInvariant("Id of Standard Property Type '{0}' is not found.", ieAction.PropertyName),
                                                 ErrorCodes.UnexpectedError);
            }
            xmlAction.PropertyTypeId = propertyTypeId;

            ToXmlModel(ieAction.ValidValues, propertyTypeId, ieAction.PropertyName, dataMaps, xmlAction);

            return(xmlAction);
        }
Пример #6
0
        public void ValidatePropertyValue_Choice_WithIds_DuplicateValidValues_Failure()
        {
            // Arrange
            _propertyType.IsRequired        = true;
            _propertyType.IsMultipleAllowed = true;
            _propertyType.ValidValues       = new List <ValidValue>
            {
                new ValidValue {
                    Id = 1, Value = "value"
                },
                new ValidValue {
                    Id = 2, Value = "value"
                }
            };
            var action = new IePropertyChangeAction
            {
                ValidValues = new List <IeValidValue>
                {
                    new IeValidValue {
                        Id = 1, Value = "value"
                    },
                    new IeValidValue {
                        Id = 1, Value = "value"
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionDuplicateValidValueFound, _result.Errors.Single().ErrorCode);
        }
Пример #7
0
        public override void Validate(IePropertyChangeAction action, PropertyType propertyType, WorkflowDataValidationResult result)
        {
            if (!action.ValidValues.IsEmpty())
            {
                result.Errors.Add(new WorkflowDataValidationError
                {
                    Element   = action.PropertyName,
                    ErrorCode = WorkflowDataValidationErrorCodes.PropertyChangeActionNotChoicePropertyValidValuesNotApplicable
                });
                return;
            }

            if (action.UsersGroups != null)
            {
                result.Errors.Add(new WorkflowDataValidationError
                {
                    Element   = action.PropertyName,
                    ErrorCode = WorkflowDataValidationErrorCodes.PropertyChangeActionNotUserPropertyUsersGroupsNotApplicable
                });
                return;
            }

            if (!IsPropertyRequired(propertyType.IsRequired.GetValueOrDefault(), action.PropertyValue, true, true))
            {
                result.Errors.Add(new WorkflowDataValidationError
                {
                    Element   = action.PropertyName,
                    ErrorCode = WorkflowDataValidationErrorCodes.PropertyChangeActionRequiredPropertyValueEmpty
                });
            }
        }
        public void ValidatePropertyChangeActionData_PropertyValueValidationFailure_Error()
        {
            // Arrange
            const string propertyName = "some";
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            var propertyType = new PropertyType { Id = 1, Name = propertyName };
            var itemType = new ItemType { Id = 1, CustomPropertyTypeIds = { propertyType.Id } };
            result.StandardPropertyTypeMapByName.Add(propertyName, propertyType);
            result.StandardTypes.ArtifactTypes.Add(itemType);
            result.AssociatedArtifactTypeIds.Add(itemType.Id);
            var action = new IePropertyChangeAction { PropertyName = propertyName };
            const WorkflowDataValidationErrorCodes errorCode = WorkflowDataValidationErrorCodes.ProjectByIdNotFound;
            _propertyValueValidatorMock
                .Setup(m => m.Validate(action, propertyType, result))
                .Callback(() => result.Errors.Add(new WorkflowDataValidationError { Element = propertyName, ErrorCode = errorCode }));

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeActionData(result, action, true);

            // Assert
            Assert.IsTrue(result.HasErrors);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(errorCode, result.Errors[0].ErrorCode);
            Assert.AreEqual(propertyName, result.Errors[0].Element as string);
        }
        public void ValidatePropertyValue_User_UsersGroups_Required_Success()
        {
            // Arrange
            _propertyType.IsRequired = true;
            const string user = "******";

            _users.Add(new SqlUser {
                Login = user
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Name = user
                        }
                    }
                }
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyValue_WithIds_UniqueUsers_Success()
        {
            // Arrange
            _users.Add(new SqlUser {
                Login = "******", UserId = 1
            });
            _users.Add(new SqlUser {
                Login = "******", UserId = 2
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Id = 1, Name = "value1"
                        },
                        new IeUserGroup {
                            Id = 2, Name = "value2"
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyValue_DuplicateUsers_Failure()
        {
            // Arrange
            _users.Add(new SqlUser {
                Login = "******", UserId = 1
            });
            _users.Add(new SqlUser {
                Login = "******", UserId = 2
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Name = "value1"
                        },
                        new IeUserGroup {
                            Name = "value1"
                        }
                    }
                }
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionDuplicateUserOrGroupFound, _result.Errors.Single().ErrorCode);
        }
        public void ValidatePropertyValue_WithIds_UniqueGroupsWithSameName_Success()
        {
            // Arrange
            _groups.Add(new SqlGroup {
                Name = "value1", GroupId = 1
            });
            _groups.Add(new SqlGroup {
                Name = "value1", GroupId = 2
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Id = 1, Name = "value1", IsGroup = true
                        },
                        new IeUserGroup {
                            Id = 2, Name = "value1", IsGroup = true
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyValue_WithIds_DuplicateGroups_Failure()
        {
            // Arrange
            _groups.Add(new SqlGroup {
                Name = "value1", GroupId = 1
            });
            _groups.Add(new SqlGroup {
                Name = "value2", GroupId = 2
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Id = 1, Name = "value1", IsGroup = true
                        },
                        new IeUserGroup {
                            Id = 1, Name = "value1", IsGroup = true
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionDuplicateUserOrGroupFound, _result.Errors.Single().ErrorCode);
        }
        public void ValidatePropertyValue_WithIds_DuplicateUsersAndGroups_Success()
        {
            // Arrange
            _users.Add(new SqlUser {
                Login = "******", UserId = 1
            });
            _groups.Add(new SqlGroup {
                Name = "value1", GroupId = 1
            });
            var action = new IePropertyChangeAction
            {
                UsersGroups = new IeUsersGroups
                {
                    UsersGroups = new List <IeUserGroup>
                    {
                        new IeUserGroup {
                            Id = 1, Name = "value1"
                        },
                        new IeUserGroup {
                            Id = 1, Name = "value1", IsGroup = true
                        }
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
Пример #15
0
        public void ValidatePropertyValue_Choice_ValidValueNotFoundById_Failure()
        {
            // Arrange
            const string valueValue = "valid value";

            _propertyType.IsRequired  = true;
            _propertyType.IsValidated = true;
            _propertyType.ValidValues = new List <ValidValue>
            {
                new ValidValue {
                    Id = 22, Value = valueValue
                }
            };
            var action = new IePropertyChangeAction
            {
                ValidValues = new List <IeValidValue>
                {
                    new IeValidValue {
                        Id = 33, Value = "invalid valid value"
                    }
                }
            };

            // Act
            Validate(action, false);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionValidValueNotFoundById, _result.Errors.Single().ErrorCode);
        }
Пример #16
0
        public void ValidatePropertyValue_Choice_Required_Success()
        {
            // Arrange
            const string valueValue = "valid value";

            _propertyType.IsRequired  = true;
            _propertyType.IsValidated = true;
            _propertyType.ValidValues = new List <ValidValue>
            {
                new ValidValue {
                    Id = 11, Value = valueValue
                }
            };
            var action = new IePropertyChangeAction
            {
                ValidValues = new List <IeValidValue>
                {
                    new IeValidValue {
                        Value = valueValue
                    }
                }
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
Пример #17
0
        public virtual void ValidatePropertyChangeActionData(WorkflowDataValidationResult result,
                                                             IePropertyChangeAction action, bool ignoreIds)
        {
            if (action == null)
            {
                return;
            }

            PropertyType propertyType;

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

                action.PropertyName = propertyType?.Name;
            }

            if (action.PropertyName == null)
            {
                return;
            }

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

                return;
            }

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

                return;
            }

            var propertyValueValidator = _propertyValueValidatorFactory.Create(propertyType, result.Users, result.Groups, ignoreIds);

            propertyValueValidator.Validate(action, propertyType, result);
        }
Пример #18
0
        private static void NormalizePropertyChangeAction(IePropertyChangeAction action)
        {
            if (action == null)
            {
                return;
            }

            action.ValidValues = NormalizeList(action.ValidValues);
            action.UsersGroups = NormalizeUsersGroups(action.UsersGroups);
        }
        public void ValidateActionData_PropertyChangeAction_CalledRespectiveValidationMethod()
        {
            // Arrange
            var result = new WorkflowDataValidationResult();
            var action = new IePropertyChangeAction();
            _dataValidatorMock.Setup(m => m.ValidatePropertyChangeActionData(result, action, true)).Verifiable();

            // Act
            _dataValidatorMock.Object.ValidateActionData(result, action, true);

            // Assert
            _dataValidatorMock.Verify();
        }
Пример #20
0
        public void ValidatePropertyValue_Date_MinAllowedValue_Success()
        {
            // Arrange
            var action = new IePropertyChangeAction {
                PropertyValue = "1753-01-01"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyValue_Text_Required_Success()
        {
            // Arrange
            _propertyType.IsRequired = true;
            var action = new IePropertyChangeAction {
                PropertyValue = "value"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
Пример #22
0
        public void ValidatePropertyValue_Date_Required_Iso8601_Success()
        {
            // Arrange
            _propertyType.IsRequired = true;
            var action = new IePropertyChangeAction {
                PropertyValue = "2017-07-21"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
Пример #23
0
        public void ValidatePropertyValue_Date_OutsideTheValidRange_Failure()
        {
            // Arrange
            var action = new IePropertyChangeAction {
                PropertyValue = "1752-01-01"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionDateOutOfRange,
                            _result.Errors.Single().ErrorCode);
        }
        public void ValidatePropertyValue_Text_Required_Failure()
        {
            // Arrange
            _propertyType.IsRequired = true;
            var action = new IePropertyChangeAction {
                PropertyValue = "  "
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionRequiredPropertyValueEmpty, _result.Errors.Single().ErrorCode);
        }
Пример #25
0
        public void ValidatePropertyValue_Date_NotRequiredEmpty_Success()
        {
            // Arrange
            _propertyType.IsRequired  = false;
            _propertyType.IsValidated = false;
            var action = new IePropertyChangeAction {
                PropertyValue = " "
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyValue_Number_InvalidFormat_Failure()
        {
            // Arrange
            _propertyType.IsRequired  = true;
            _propertyType.IsValidated = false;
            var action = new IePropertyChangeAction {
                PropertyValue = "aaa"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionInvalidNumberFormat, _result.Errors.Single().ErrorCode);
        }
Пример #27
0
        public void ValidatePropertyValue_Date_InRange_Success()
        {
            // Arrange
            _propertyType.IsRequired  = true;
            _propertyType.IsValidated = true;
            _propertyType.MinDate     = DateTime.ParseExact("2017-08-01", "yyyy-MM-dd", CultureInfo.InvariantCulture);
            _propertyType.MaxDate     = DateTime.ParseExact("2017-08-30", "yyyy-MM-dd", CultureInfo.InvariantCulture);
            var action = new IePropertyChangeAction {
                PropertyValue = "2017-08-30"
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsFalse(_result.HasErrors);
        }
        public void ValidatePropertyChangeActionData_PropertyTypeNotAssociated_Error()
        {
            // Arrange
            const string propertyName = "some";
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            result.StandardPropertyTypeMapByName.Add(propertyName, new PropertyType { Name = propertyName });
            var action = new IePropertyChangeAction { PropertyName = propertyName };

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeActionData(result, action, true);

            // Assert
            Assert.AreEqual(true, result.HasErrors);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionPropertyTypeNotAssociated, result.Errors[0].ErrorCode);
            Assert.AreEqual(propertyName, result.Errors[0].Element as string);
        }
        public void ValidatePropertyValue_Text_HasValidValues_Failure()
        {
            // Arrange
            var action = new IePropertyChangeAction
            {
                ValidValues = new List <IeValidValue>
                {
                    new IeValidValue()
                }
            };

            // Act
            Validate(action, true);

            // Assert
            Assert.IsTrue(_result.HasErrors);
            Assert.AreEqual(WorkflowDataValidationErrorCodes.PropertyChangeActionNotChoicePropertyValidValuesNotApplicable, _result.Errors.Single().ErrorCode);
        }
        public void ValidatePropertyChangeActionData_PropertyValueValidationSuccess_Success()
        {
            // Arrange
            const string propertyName = "some";
            var result = new WorkflowDataValidationResult { StandardTypes = new ProjectTypes() };
            var propertyType = new PropertyType { Id = 1, Name = propertyName };
            var itemType = new ItemType { Id = 1, CustomPropertyTypeIds = { propertyType.Id } };
            result.StandardPropertyTypeMapByName.Add(propertyName, propertyType);
            result.StandardTypes.ArtifactTypes.Add(itemType);
            result.AssociatedArtifactTypeIds.Add(itemType.Id);
            var action = new IePropertyChangeAction { PropertyName = propertyName };

            // Act
            _dataValidatorMock.Object.ValidatePropertyChangeActionData(result, action, true);

            // Assert
            Assert.AreEqual(false, result.HasErrors);
        }