Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
        public static void FormatValue_GuardClause()
        {
            var mapping = new ElasticMapping();

            Assert.Throws<ArgumentNullException>(() => mapping.FormatValue(null, "value"));
        }
Esempio n. 7
0
        public static void GetTypeSelectionCriteria_GuardClause()
        {
            var mapping = new ElasticMapping();

            Assert.Throws<ArgumentNullException>(() => mapping.GetTypeSelectionCriteria(null));
        }
Esempio n. 8
0
        public static void GetTypeSelectionCriteria()
        {
            var mapping = new ElasticMapping();

            var criteria = mapping.GetTypeSelectionCriteria(typeof(FormatClass));

            Assert.Null(criteria);
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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));
        }
Esempio n. 11
0
        public static void GetDocumentType_GuardClause()
        {
            var mapping = new ElasticMapping();

            Assert.Throws<ArgumentNullException>(() => mapping.GetDocumentType(null));
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        [ExcludeFromCodeCoverage] // Expression isn't "executed"
        public static void GetFieldName_GuardClause()
        {
            var mapping = new ElasticMapping();

            Assert.Throws<ArgumentNullException>(() => mapping.GetFieldName("", null));
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }