public void ValidateText_ReturnsNull_WhenSuccess() { // Arrange var propertyLite = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, TextOrChoiceValue = "Text", }; var propertyType = new TextPropertyType { PropertyTypeId = 30, InstancePropertyTypeId = InstancePropertyTypeId, AllowMultiple = true, IsRequired = true, IsRichText = true, DefaultValue = "any" }; // Act var result = _validator.Validate(propertyLite, new List <WorkflowPropertyType> { propertyType }, null); // Assert Assert.IsNull(result); }
public void ValidateText_ReturnsNull_ForNonTextProperties() { // Arrange var propertyLite = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, TextOrChoiceValue = null, }; var propertyType = new TextPropertyType { PropertyTypeId = 30, InstancePropertyTypeId = InstancePropertyTypeId }; // Act var result = _validator.Validate(propertyLite, new List <WorkflowPropertyType> { propertyType }, null); // Assert Assert.IsNull(result); }
public void ValidateText_ReturnsError_WhenNameNull() { // Arrange var propertyLite = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, TextOrChoiceValue = null }; var propertyType = new TextPropertyType { PropertyTypeId = 30, InstancePropertyTypeId = InstancePropertyTypeId, Predefined = PropertyTypePredefined.Name }; // Act var result = _validator.Validate(propertyLite, new List <WorkflowPropertyType> { propertyType }, null); // Assert Assert.IsInstanceOfType(result, typeof(PropertySetResult)); }
public void ValidateText_ReturnsError_WhenRequiredButEmpty() { // Arrange var propertyLite = new PropertyLite { PropertyTypeId = InstancePropertyTypeId, TextOrChoiceValue = string.Empty, }; var propertyType = new TextPropertyType { PropertyTypeId = 30, InstancePropertyTypeId = InstancePropertyTypeId, IsRequired = true }; // Act var result = _validator.Validate(propertyLite, new List <WorkflowPropertyType> { propertyType }, null); // Assert Assert.IsInstanceOfType(result, typeof(PropertySetResult)); }
private Dictionary <int, List <WorkflowPropertyType> > ToItemTypePropertyTypesDictionary(IEnumerable <SqlPropertyType> sqlPropertyTypes) { var dictionary = new Dictionary <int, List <WorkflowPropertyType> >(); foreach (var sqlPropertyType in sqlPropertyTypes) { WorkflowPropertyType workflowProperty; switch (sqlPropertyType.PrimitiveType) { case PropertyPrimitiveType.Text: { workflowProperty = new TextPropertyType { AllowMultiple = sqlPropertyType.AllowMultiple, DefaultValidValueId = sqlPropertyType.DefaultValidValueId, InstancePropertyTypeId = GetInstancePropertyTypeId(sqlPropertyType.InstancePropertyTypeId, sqlPropertyType.Predefined), Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, StringDefaultValue = sqlPropertyType.StringDefaultValue, VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined, DefaultValue = sqlPropertyType.StringDefaultValue, IsValidate = sqlPropertyType.Validate.GetValueOrDefault(false), IsRichText = sqlPropertyType.IsRichText }; break; } case PropertyPrimitiveType.Number: { workflowProperty = new NumberPropertyType { AllowMultiple = sqlPropertyType.AllowMultiple, DefaultValue = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue), DecimalPlaces = sqlPropertyType.DecimalPlaces.GetValueOrDefault(0), DefaultValidValueId = sqlPropertyType.DefaultValidValueId, InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId, Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, Range = new Range <decimal> { End = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_End).GetValueOrDefault(0), Start = PropertyHelper.ToDecimal((byte[])sqlPropertyType.NumberRange_Start).GetValueOrDefault(0) }, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, IsValidate = sqlPropertyType.Validate.GetValueOrDefault(false), VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined }; break; } case PropertyPrimitiveType.Date: { workflowProperty = new DatePropertyType { AllowMultiple = sqlPropertyType.AllowMultiple, DefaultValue = sqlPropertyType.DateDefaultValue, DefaultValidValueId = sqlPropertyType.DefaultValidValueId, InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId, Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, Range = new Range <DateTime?> { End = sqlPropertyType.DateRange_End, Start = sqlPropertyType.DateRange_Start }, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, IsValidate = sqlPropertyType.Validate.GetValueOrDefault(false), VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined }; break; } case PropertyPrimitiveType.User: workflowProperty = new UserPropertyType() { DefaultLabels = sqlPropertyType.UserDefaultLabel, DefaultValues = sqlPropertyType.UserDefaultValue, InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId, Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined }; break; case PropertyPrimitiveType.Choice: { workflowProperty = new ChoicePropertyType { AllowMultiple = sqlPropertyType.AllowMultiple, // DefaultValue = PropertyHelper.ToDecimal((byte[])sqlPropertyType.DecimalDefaultValue), ValidValues = XmlModelSerializer.DeserializeCustomProperties(sqlPropertyType.CustomProperty).CustomProperties[0]?.ValidValues .OrderBy(v => I18NHelper.Int32ParseInvariant(v.OrderIndex)) .Select(v => { int?vvId = null; if (!string.IsNullOrWhiteSpace(v.LookupListItemId)) { int intValue; if (int.TryParse(v.LookupListItemId, out intValue)) { vvId = intValue; } } int?vvSid = null; if (!string.IsNullOrWhiteSpace(v.StandardLookupListItemId)) { int intValue; if (int.TryParse(v.StandardLookupListItemId, out intValue)) { vvSid = intValue; } } return(new ValidValue { Id = vvId, Value = v.Value, Sid = vvSid }); }).ToList(), DefaultValidValueId = sqlPropertyType.DefaultValidValueId, InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId, Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, IsValidate = sqlPropertyType.Validate.GetValueOrDefault(false), VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined }; break; } // TODO: add other DPropertyTypes default: { workflowProperty = new WorkflowPropertyType { AllowMultiple = sqlPropertyType.AllowMultiple, DefaultValidValueId = sqlPropertyType.DefaultValidValueId, InstancePropertyTypeId = sqlPropertyType.InstancePropertyTypeId, IsRichText = sqlPropertyType.IsRichText, Name = sqlPropertyType.Name, PropertyTypeId = sqlPropertyType.PropertyTypeId, PrimitiveType = sqlPropertyType.PrimitiveType, IsRequired = sqlPropertyType.Required != null && sqlPropertyType.Required.Value, StringDefaultValue = sqlPropertyType.StringDefaultValue, VersionId = sqlPropertyType.VersionId, Predefined = sqlPropertyType.Predefined }; break; } } if (dictionary.ContainsKey(sqlPropertyType.ItemTypeId)) { dictionary[sqlPropertyType.ItemTypeId].Add(workflowProperty); } else { dictionary.Add(sqlPropertyType.ItemTypeId, new List <WorkflowPropertyType> { workflowProperty }); } } return(dictionary); }