예제 #1
0
        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);
        }
예제 #2
0
 public void TestInitialize()
 {
     _validator    = new DatePropertyValidator();
     _propertyLite = new PropertyLite
     {
         PropertyTypeId = DefaultInstancePropertyTypeId,
         DateValue      = new DateTime(2018, 1, 1)
     };
     _propertyType = new DatePropertyType
     {
         PropertyTypeId         = DefaultPropertyTypeId,
         InstancePropertyTypeId = DefaultInstancePropertyTypeId,
         Range = new Range <DateTime?>
         {
             Start = new DateTime(2017, 1, 1),
             End   = new DateTime(2019, 1, 1)
         },
         IsValidate = true
     };
     _propertyTypes = new List <WorkflowPropertyType>
     {
         _propertyType
     };
     _validationContextMock = new Mock <IValidationContext>();
 }
 public void TestInitialize()
 {
     _validator    = new UserPropertyValidator();
     _propertyLite = new PropertyLite()
     {
         PropertyTypeId = DefaultInstancePropertyTypeId
     };
     _propertyType = new UserPropertyType()
     {
         PropertyTypeId         = DefaultPropertyTypeId,
         InstancePropertyTypeId = DefaultInstancePropertyTypeId
     };
     _validationContext = new ValidationContext(
         new List <SqlUser>()
     {
         new SqlUser()
         {
             UserId = DefaultUser.Id.Value
         }
     },
         new List <SqlGroup>()
     {
         new SqlGroup()
         {
             GroupId = DefaultGroup.Id.Value
         }
     });
 }
예제 #4
0
        private static string GetCustomPropertyChar(PropertyLite propertyValue, WorkflowPropertyType propertyType)
        {
            // BluePrintSys.RC.CrossCutting.Logging.Log.Assert(
            //    (propertyValue != null) && propertyValue.SaveState.HasFlag(NodeSaveState.MemoryNode));
            if ( /*propertyValue.NodeDeleted ||*/
                (((int)PropertyTypePredefined.GroupMask & (int)propertyType.Predefined) !=
                 (int)PropertyTypePredefined.CustomGroup))
            {
                return(null);
            }
            PropertyPrimitiveType primitiveType;

            if (propertyType is NumberPropertyType)
            {
                primitiveType = PropertyPrimitiveType.Number;
            }
            else if (propertyType is DatePropertyType)
            {
                primitiveType = PropertyPrimitiveType.Date;
            }
            else if (propertyType is TextPropertyType)
            {
                primitiveType = PropertyPrimitiveType.Text;
            }
            else if (propertyType is UserPropertyType)
            {
                primitiveType = PropertyPrimitiveType.User;
            }
            else if (propertyType is ChoicePropertyType)
            {
                primitiveType = PropertyPrimitiveType.Choice;
            }
            // else if (propertyValue is DImagePropertyValue)
            // {
            //    primitiveType = PropertyPrimitiveType.Image;
            // }
            else
            {
                // BluePrintSys.RC.CrossCutting.Logging.Log.Assert(false);
                return(null);
            }
            XmlCustomProperties customProperties = new XmlCustomProperties();
            XmlCustomProperty   customProperty   = XmlCustomProperty.CreateAsValue(propertyType.PropertyTypeId,
                                                                                   (int)primitiveType);

            customProperties.CustomProperties.Add(customProperty);
            if (propertyType is ChoicePropertyType)
            {
                List <XmlCustomPropertyValidValue> validValues = customProperty.ValidValues;
                foreach (int choiceId in propertyValue.ChoiceIds)
                {
                    var customChoice = (propertyType as ChoicePropertyType).ValidValues
                                       .Where(v => v.Sid.Value == choiceId)
                                       .Select(v => v.Id).FirstOrDefault().Value;
                    XmlCustomPropertyValidValue validValue = XmlCustomPropertyValidValue.CreateAsValue(customChoice);
                    validValues.Add(validValue);
                }
            }
            return(XmlModelSerializer.SerializeCustomProperties(customProperties));
        }
예제 #5
0
 private PropertySetResult PopulateNumberPropertyLite()
 {
     if (ValidValues != null && ValidValues.Any())
     {
         return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty,
                                      "Property type is now number property. Property change action is currently invalid."));
     }
     if (String.IsNullOrEmpty(PropertyValue))
     {
         PropertyLiteValue = new PropertyLite()
         {
             PropertyTypeId = InstancePropertyTypeId,
             NumberValue    = null
         };
     }
     else
     {
         decimal value;
         if (
             !Decimal.TryParse(PropertyValue, NumberStyles.Number, CultureInfo.InvariantCulture, out value))
         {
             return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty,
                                          "Property type is now number property. Property change action is currently invalid."));
         }
         PropertyLiteValue = new PropertyLite()
         {
             PropertyTypeId = InstancePropertyTypeId,
             NumberValue    = value
         };
     }
     return(null);
 }
예제 #6
0
 private static string GetSearchableValue(PropertyLite propertyLite, WorkflowPropertyType propertyType)
 {
     if (propertyType is TextPropertyType)
     {
         return(propertyLite.TextOrChoiceValue);
     }
     return(null);
 }
예제 #7
0
        private string GetTextPropertyValue(WorkflowPropertyType propertyType, PropertyLite property)
        {
            if (property.TextOrChoiceValue == null)
            {
                return(null);
            }

            if (propertyType.Predefined == PropertyTypePredefined.Name)
            {
                return(property.TextOrChoiceValue);
            }
            else
            {
                return("<html><head/><p>" + property.TextOrChoiceValue + "</p></html>");
            }
        }
        protected override PropertySetResult PopulatePropertyLite(WorkflowPropertyType propertyType)
        {
            if (!propertyType.PrimitiveType.HasValue ||
                propertyType.PrimitiveType.Value != PropertyPrimitiveType.User ||
                !String.IsNullOrEmpty(PropertyValue))
            {
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty,
                                             "Property type is not a user property anymore. Property change action is currently invalid"));
            }

            PropertyLiteValue = new PropertyLite()
            {
                PropertyTypeId = InstancePropertyTypeId
            };
            PropertyLiteValue.UsersAndGroups.AddRange(UserGroups);
            return(null);
        }
예제 #9
0
        protected virtual PropertySetResult PopulatePropertyLite(WorkflowPropertyType propertyType)
        {
            switch (propertyType?.PrimitiveType)
            {
            case PropertyPrimitiveType.Text:
                PropertyLiteValue = new PropertyLite()
                {
                    PropertyTypeId    = InstancePropertyTypeId,
                    TextOrChoiceValue = PropertyValue
                };
                break;

            case PropertyPrimitiveType.Number:
                return(PopulateNumberPropertyLite());

            case PropertyPrimitiveType.Date:
                return(PopulateDatePropertyLite());

            case PropertyPrimitiveType.Choice:
                PropertyLiteValue = new PropertyLite
                {
                    PropertyTypeId = InstancePropertyTypeId,
                };
                if (!ValidValues.Any() && !propertyType.Validate.GetValueOrDefault(false))
                {
                    PropertyLiteValue.TextOrChoiceValue = PropertyValue;
                }
                else
                {
                    PropertyLiteValue.ChoiceIds.AddRange(ValidValues);
                }
                break;

            case PropertyPrimitiveType.User:
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now user, but does not contain user and group change actions"));

            default:
                PropertyLiteValue = new PropertyLite()
                {
                    PropertyTypeId = InstancePropertyTypeId
                };
                break;
            }
            return(null);
        }
예제 #10
0
 public void TestInitialize()
 {
     _property = new PropertyLite
     {
         PropertyTypeId = DefaultInstancePropertyTypeId,
         NumberValue    = 15.01M
     };
     _propertyType = new NumberPropertyType
     {
         PropertyTypeId         = DefaultPropertyTypeId,
         InstancePropertyTypeId = DefaultInstancePropertyTypeId,
         Range = new Range <decimal> {
             Start = 10, End = 20
         },
         DecimalPlaces = 2,
         IsValidate    = true
     };
 }
        public void TestInitialize()
        {
            _validator    = new ChoicePropertyValidator();
            _propertyLite = new PropertyLite
            {
                PropertyTypeId = DefaultInstancePropertyTypeId
                                 // ,TextOrChoiceValue = "99"
            };
            _propertyLite.ChoiceIds.AddRange(new List <int> {
                26
            });

            _propertyType = new ChoicePropertyType
            {
                PropertyTypeId         = DefaultPropertyTypeId,
                InstancePropertyTypeId = DefaultInstancePropertyTypeId,
                ValidValues            = new List <ValidValue>
                {
                    new ValidValue {
                        Id = 35, Sid = 25, Value = "1"
                    },
                    new ValidValue {
                        Id = 36, Sid = 26, Value = "2"
                    },
                    new ValidValue {
                        Id = 37, Sid = 27, Value = "3"
                    },
                    new ValidValue {
                        Id = 38, Sid = 28, Value = "4"
                    }
                },
                IsValidate    = true,
                AllowMultiple = false
            };

            _propertyTypes = new List <WorkflowPropertyType>
            {
                _propertyType
            };
        }
예제 #12
0
        private PropertySetResult PopulateDatePropertyLite()
        {
            // was Choice property
            if (ValidValues != null && ValidValues.Any())
            {
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, "Property type is now date property. Property change action is currently invalid."));
            }

            // is null
            if (string.IsNullOrEmpty(PropertyValue))
            {
                PropertyLiteValue = new PropertyLite
                {
                    PropertyTypeId = InstancePropertyTypeId,
                    DateValue      = null
                };
                return(null);
            }

            DateTime date;

            try
            {
                date = PropertyHelper.ParseDateValue(PropertyValue, new TimeProvider());
            }
            catch (Exception ex)
            {
                // invalid date format
                return(new PropertySetResult(InstancePropertyTypeId, ErrorCodes.InvalidArtifactProperty, $"Property type is now date property. Property change action is currently invalid. {ex.Message}"));
            }

            // valid date format
            PropertyLiteValue = new PropertyLite
            {
                PropertyTypeId = InstancePropertyTypeId,
                DateValue      = date
            };
            return(null);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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));
        }
예제 #15
0
        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));
        }