public async Task AddCustomAttributeAsync(CustomAttributeConfigDetail customAttribute) { var newCustomAttribute = new CustomAttributeConfiguration() { ExtendableTypeName = customAttribute.EntityName, Category = customAttribute.Category, AttributeKey = customAttribute.AttributeName, AttributeDetail = customAttribute.AttributeDetail, CustomAttributeType = customAttribute.CustomAttributeType, IsRequired = customAttribute.Required, IsSearchable = customAttribute.Searchable }; switch (newCustomAttribute.CustomAttributeType) { case CustomAttributeType.Numeric: if (customAttribute.NumericMinValue.HasValue) { newCustomAttribute.NumericMinValue = customAttribute.NumericMinValue.Value; } if (customAttribute.NumericMaxValue.HasValue) { newCustomAttribute.NumericMaxValue = customAttribute.NumericMaxValue.Value; } break; case CustomAttributeType.String: if (customAttribute.StringMaxLength.HasValue) { newCustomAttribute.StringMaxLength = customAttribute.StringMaxLength.Value; } break; case CustomAttributeType.DateTime: newCustomAttribute.FutureDateOnly = customAttribute.FutureDateOnly; newCustomAttribute.PastDateOnly = customAttribute.PastDateOnly; break; default: break; } await _customAttributeConfigRepository.SaveAsync(newCustomAttribute); if (newCustomAttribute.CustomAttributeType == CustomAttributeType.Selection) { var newSelectionDataItem = new SelectionDataItem() { AttributeKey = customAttribute.AttributeName, Value = "", SelectionKey = "0" }; await _selectionDataItemRepository.SaveAsync(newSelectionDataItem); } }
public void ValidateAndSetAttributeValue_WhenRequiredAndNotSpecified_ThrowsCustomAttributeValidationException() { // Arrange var stringCustomAttributeConfig = new CustomAttributeConfiguration { CustomAttributeType = CustomAttributeType.String, IsRequired = true }; // Act classUnderTest.ValidateAndSetAttributeValue(stringCustomAttributeConfig, default(string), "UserName"); }
public void ValidateAndSetCustomAttribute_WhenDateTimeMustBeInFutureAndIsNot_ThrowsCustomAttributeValidationException() { // Arrange var dateTimeCustomAttributeConfig = new CustomAttributeConfiguration { CustomAttributeType = CustomAttributeType.DateTime, FutureDateOnly = true }; // Act classUnderTest.ValidateAndSetAttributeValue(dateTimeCustomAttributeConfig, DateTime.Now.AddDays(-1), "UserName"); }
public void ValidateAndSetAttributeValue_WhenNumericAndHigherThanMaxValue_ThrowsCustomAttributeException() { // Arrange var numericCustomAttributeConfig = new CustomAttributeConfiguration { CustomAttributeType = CustomAttributeType.Numeric, NumericMaxValue = 5 }; // Act classUnderTest.ValidateAndSetAttributeValue(numericCustomAttributeConfig, 6m, "UserName"); }
public void ValidateAndSetAttributeValue_WhenStringAndExceedsStringMaxLength_ThrowsCustomAttributeException() { // Arrange var stringCustomAttributeConfig = new CustomAttributeConfiguration { AttributeKey = "StringWithMaxLength", CustomAttributeType = CustomAttributeType.String, StringMaxLength = 5 }; // Act classUnderTest.ValidateAndSetAttributeValue(stringCustomAttributeConfig, "StringLongerThan5Characters", "UserName"); }
public void ValidateAndSetAttributeValue_WhenStringDoesNotExeedStringMaxLength_SetsValue() { // Arrange var stringCustomAttributeConfig = new CustomAttributeConfiguration { AttributeKey = "StringWithMaxLength", CustomAttributeType = CustomAttributeType.String, StringMaxLength = 500 }; // Act classUnderTest.ValidateAndSetAttributeValue(stringCustomAttributeConfig, "ValidString", "UserName"); // Assert var customStringAttribute = classUnderTest.CustomStringAttributes.SingleOrDefault(a => a.Key == "StringWithMaxLength"); Assert.IsNotNull(customStringAttribute); Assert.AreEqual("ValidString", customStringAttribute.Value); }
public void ValidateAndSetAttributeValue_WhenNumericAndWithInValidRange_SetsValue() { // Arrange var numericCustomAttributeConfig = new CustomAttributeConfiguration { AttributeKey = "ValidNumeric", CustomAttributeType = CustomAttributeType.Numeric, NumericMinValue = 5, NumericMaxValue = 10 }; // Act classUnderTest.ValidateAndSetAttributeValue(numericCustomAttributeConfig, 6m, "UserName"); // Assert var customNumericAttribute = classUnderTest.CustomNumericAttributes.SingleOrDefault(a => a.Key == "ValidNumeric"); Assert.IsNotNull(customNumericAttribute); Assert.AreEqual(6m, customNumericAttribute.Value); }
public void ValidateAndSetAttributeValue <T>(CustomAttributeConfiguration attributeConfig, T attributeValue, string updatedByUser) { customAttributes.ValidateAndSetAttributeValue(attributeConfig, attributeValue, updatedByUser); }