private static XmlEmailNotificationAction ToXmlModel(IeEmailNotificationAction ieAction, IDictionary <string, int> propertyTypeMap) { if (ieAction == null) { return(null); } var xmlAction = new XmlEmailNotificationAction { Name = ieAction.Name, Emails = ieAction.Emails, Message = ieAction.Message }; if (ieAction.PropertyName != null) { int propertyTypeId; if (!propertyTypeMap.TryGetValue(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; } return(xmlAction); }
public virtual void ValidateEmailNotificationActionData(WorkflowDataValidationResult result, IeEmailNotificationAction 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)) { result.Errors.Add(new WorkflowDataValidationError { Element = action.PropertyId.Value, ErrorCode = WorkflowDataValidationErrorCodes.EmailNotificationActionPropertyTypeNotFoundById }); } action.PropertyName = propertyType?.Name; } if (action.PropertyName == null) { return; } if (!result.StandardPropertyTypeMapByName.TryGetValue(action.PropertyName, out propertyType)) { result.Errors.Add(new WorkflowDataValidationError { Element = action.PropertyName, ErrorCode = WorkflowDataValidationErrorCodes.EmailNotificationActionPropertyTypeNotFoundByName }); } else { if (propertyType.PrimitiveType != PropertyPrimitiveType.Text && propertyType.PrimitiveType != PropertyPrimitiveType.User) { result.Errors.Add(new WorkflowDataValidationError { Element = action.PropertyName, ErrorCode = WorkflowDataValidationErrorCodes.EmailNotificationActionUnacceptablePropertyType }); } if (!IsAssociatedWithWorkflowArtifactTypes(propertyType, result)) { result.Errors.Add(new WorkflowDataValidationError { Element = action.PropertyName, ErrorCode = WorkflowDataValidationErrorCodes.EmailNotificationActionPropertyTypeNotAssociated }); } } }
private static void NormalizeEmailNotificationAction(IeEmailNotificationAction action) { if (action == null) { return; } action.Emails = NormalizeList(action.Emails); }
public void ValidateActionData_EmailNotificationAction_CalledRespectiveValidationMethod() { // Arrange var result = new WorkflowDataValidationResult(); var action = new IeEmailNotificationAction(); _dataValidatorMock.Setup(m => m.ValidateEmailNotificationActionData(result, action, true)).Verifiable(); // Act _dataValidatorMock.Object.ValidateActionData(result, action, true); // Assert _dataValidatorMock.Verify(); }
public void ValidateEmailNotificationActionData_Description_ArtifactTypesAssociated_NoError() { // Arrange var propertyType = new PropertyType { Id = WorkflowConstants.PropertyTypeFakeIdDescription, Name = "Description", PrimitiveType = PropertyPrimitiveType.Text }; 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 action = new IeEmailNotificationAction { PropertyName = propertyType.Name }; // Act _dataValidatorMock.Object.ValidateEmailNotificationActionData(result, action, true); // Assert Assert.AreEqual(false, result.HasErrors); Assert.AreEqual(0, result.Errors.Count); }
public void ValidateEmailNotificationActionData_Name_NoArtifactTypesAssociated_Error() { // Arrange var propertyType = new PropertyType { Id = WorkflowConstants.PropertyTypeFakeIdName, Name = "Name", PrimitiveType = PropertyPrimitiveType.Text }; 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 action = new IeEmailNotificationAction { PropertyName = propertyType.Name }; // Act _dataValidatorMock.Object.ValidateEmailNotificationActionData(result, action, true); // Assert Assert.AreEqual(true, result.HasErrors); Assert.AreEqual(1, result.Errors.Count); Assert.AreEqual(WorkflowDataValidationErrorCodes.EmailNotificationActionPropertyTypeNotAssociated, result.Errors[0].ErrorCode); Assert.AreEqual(propertyType.Name, result.Errors[0].Element as string); }
public void ValidateEmailNotificationActionData_CustomProperty_AssociatedWithArtifactTypes_NoError() { // Arrange var propertyType = new PropertyType { Id = 1, Name = "My Standard Property", PrimitiveType = PropertyPrimitiveType.User }; 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 action = new IeEmailNotificationAction { PropertyName = propertyType.Name }; artifactType.CustomPropertyTypeIds.Add(propertyType.Id); // Act _dataValidatorMock.Object.ValidateEmailNotificationActionData(result, action, true); // Assert Assert.AreEqual(false, result.HasErrors); Assert.AreEqual(0, result.Errors.Count); }