/// <summary> /// Get the attribute value. /// </summary> /// <typeparam name="TAttributeValue">The attribute value generic type.</typeparam> /// <param name="attributeName">The attribute name.</param> /// <returns>The attribute value.</returns> public TAttributeValue GetAttributeValue <TAttributeValue>(string attributeName) { object attributeValue = default(TAttributeValue); if (typeof(TAttributeValue) == typeof(string)) { attributeValue = new SingleLineAdapter(this.SearchResult.Properties[attributeName]).Value; } else if (typeof(TAttributeValue) == typeof(byte[])) { attributeValue = new ByteArrayAdapter(this.SearchResult.Properties[attributeName]).Value; } else if (typeof(TAttributeValue) == typeof(DateTime)) { attributeValue = new DateTimeAdapter(this.SearchResult, attributeName).Value; } else if (typeof(TAttributeValue) == typeof(Guid)) { attributeValue = new GuidAdapter(this.SearchResult.Properties[attributeName]).Value; } else if (typeof(TAttributeValue) == typeof(int)) { attributeValue = new IntegerAdapter(this.SearchResult.Properties[attributeName]).Value; } else if (typeof(TAttributeValue) == typeof(IList <string>) || typeof(TAttributeValue) == typeof(List <string>)) { attributeValue = new MultipleLineAdapter(this.SearchResult.Properties[attributeName]).Value; } return((TAttributeValue)attributeValue); }
public IntegerAdapterTests() { attributes = new Dictionary<String, String>(); adapter = new IntegerAdapter(new IntegerAttribute()); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Integer"); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public IntegerAdapterTests() { attributes = new Dictionary <String, String>(); adapter = new IntegerAdapter(new IntegerAttribute()); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AllTypesView), "StringField"); context = new ClientModelValidationContext(new ActionContext(), metadata, provider, attributes); }
public void GetClientValidationRules_ReturnsIntegerValidationRule() { ModelMetadata metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(AdaptersModel), "Integer"); IntegerAdapter adapter = new IntegerAdapter(metadata, new ControllerContext(), new IntegerAttribute()); String expectedMessage = new IntegerAttribute().FormatErrorMessage(metadata.GetDisplayName()); ModelClientValidationRule actual = adapter.GetClientValidationRules().Single(); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("integer", actual.ValidationType); Assert.Empty(actual.ValidationParameters); }
public void GetClientValidationRules_ReturnsIntegerValidationRule() { IServiceProvider services = Substitute.For <IServiceProvider>(); IModelMetadataProvider provider = new EmptyModelMetadataProvider(); IntegerAdapter adapter = new IntegerAdapter(new IntegerAttribute()); ModelMetadata metadata = provider.GetMetadataForProperty(typeof(AdaptersModel), "Integer"); ClientModelValidationContext context = new ClientModelValidationContext(metadata, provider, services); ModelClientValidationRule actual = adapter.GetClientValidationRules(context).Single(); String expectedMessage = new IntegerAttribute().FormatErrorMessage("Integer"); Assert.Equal(expectedMessage, actual.ErrorMessage); Assert.Equal("integer", actual.ValidationType); Assert.Empty(actual.ValidationParameters); }