Exemplo 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);
        }
Exemplo 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));
        }
Exemplo n.º 3
0
        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);
        }
Exemplo 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));
        }
Exemplo n.º 6
0
        public static void FormatValue_GuardClause()
        {
            var mapping = new ElasticMapping();

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

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

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

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

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

            Assert.Throws<ArgumentNullException>(() => mapping.GetFieldName("", null));
        }
Exemplo 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);
        }
Exemplo 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);
        }