public static void Format_WithEnumPropertyProducesIntWhenMappingSpecifiesIntFormat() { var mapping = new ElasticMapping(enumFormat: EnumFormat.Integer); var memberInfo = TypeHelper.GetMemberInfo((FormatClass f) => f.DayProperty); var actual = mapping.FormatValue(memberInfo, (int)Day.Saturday); Assert.Equal((int)Day.Saturday, actual); }
public static void FormatValue(bool lowerCaseAnalyzedFieldValues, string propertyName, object inputValue, string expected) { var memberInfo = typeof(FormatClass).GetProperty(propertyName); var mapping = new ElasticMapping(lowerCaseAnalyzedFieldValues: lowerCaseAnalyzedFieldValues); var result = mapping.FormatValue(memberInfo, inputValue); Assert.Equal(expected, result.ToString(Formatting.None)); }
public static void GetFieldName(bool camelCaseFieldNames, string prefix, string expected) { var memberInfo = MethodBase.GetCurrentMethod(); var mapping = new ElasticMapping(camelCaseFieldNames: camelCaseFieldNames); var actual = mapping.GetFieldName(prefix, memberInfo); Assert.Equal(expected, actual); }
public void ConstructorWithAllArgsSetsPropertiesFromParameters() { var expectedMapping = new ElasticMapping(); var expectedLog = new SpyLog(); const int expectedAttempts = 5; var expectedTimeout = TimeSpan.FromSeconds(21.3); var context = new TestableElasticContext(expectedMapping, expectedLog, expectedAttempts, expectedTimeout); Assert.NotNull(context.Connection); Assert.Equal(expectedMapping, context.Mapping); Assert.NotNull(context.Provider); Assert.NotNull(context.Requests); Assert.Equal(expectedLog, context.Log); var retryPolicy = Assert.IsType<RetryPolicy>(context.RetryPolicy); Assert.Equal(expectedAttempts, retryPolicy.MaxAttempts); }
public static void Format_WithEnumPropertyThrowsArgumentOutOfRangeWithUndefinedEnum() { var mapping = new ElasticMapping(enumFormat: EnumFormat.String); var memberInfo = TypeHelper.GetMemberInfo((FormatClass f) => f.DayProperty); Assert.Throws<ArgumentOutOfRangeException>(() => mapping.FormatValue(memberInfo, 127)); }
public static void FormatValue_GuardClause() { var mapping = new ElasticMapping(); Assert.Throws<ArgumentNullException>(() => mapping.FormatValue(null, "value")); }
public static void GetTypeSelectionCriteria_GuardClause() { var mapping = new ElasticMapping(); Assert.Throws<ArgumentNullException>(() => mapping.GetTypeSelectionCriteria(null)); }
public static void GetTypeSelectionCriteria() { var mapping = new ElasticMapping(); var criteria = mapping.GetTypeSelectionCriteria(typeof(FormatClass)); Assert.Null(criteria); }
public static void GetFieldName_HonorsJsonPropertyName() { var memberInfo = TypeHelper.GetMemberInfo((FormatClass f) => f.NotSoCustom); var mapping = new ElasticMapping(); var actual = mapping.GetFieldName("", memberInfo); Assert.Equal("CustomPropertyName", actual); }
public static void GetFieldName_GuardClause() { var mapping = new ElasticMapping(); Assert.Throws<ArgumentNullException>(() => mapping.GetFieldName("", (MemberExpression)null)); Assert.Throws<NotSupportedException>(() => mapping.GetFieldName("", Expression.Field(Expression.Constant(new FieldClass { AField = "test" }), "AField"))); Assert.Throws<ArgumentNullException>(() => mapping.GetFieldName("", (MemberInfo)null)); }
public static void GetDocumentType_GuardClause() { var mapping = new ElasticMapping(); Assert.Throws<ArgumentNullException>(() => mapping.GetDocumentType(null)); }
public static void GetDocumentType(bool camelCaseTypeNames, bool pluralizeTypeNames, Type type, string expected) { var mapping = new ElasticMapping(camelCaseTypeNames: camelCaseTypeNames, pluralizeTypeNames: pluralizeTypeNames); var actual = mapping.GetDocumentType(type); Assert.Equal(expected, actual); }
[ExcludeFromCodeCoverage] // Expression isn't "executed" public static void GetFieldName_GuardClause() { var mapping = new ElasticMapping(); Assert.Throws<ArgumentNullException>(() => mapping.GetFieldName("", null)); }
public static void GetTypeExistsCriteria() { var mapping = new ElasticMapping(); var criteria = mapping.GetTypeExistsCriteria(typeof(FormatClass)); var exists = Assert.IsType<ExistsCriteria>(criteria); Assert.Equal("integerValue", exists.Field); }
public static void GetFieldName_Correctly_Cases_Property_Name(bool camelCaseFieldNames, string expected) { Expression<Func<Sample, string>> stringAccess = (Sample s) => s.StringProperty; var mapping = new ElasticMapping(camelCaseFieldNames: camelCaseFieldNames); var actual = mapping.GetFieldName(typeof(Sample), (MemberExpression) stringAccess.Body); Assert.Equal(expected, actual); }