public void Invalid_index_name_should_throw() { Assert.Throws <ArgumentNullException>(() => { SchemaMetadata <InvalidIndexNameTest> .GetSchemaMetadata(); }); }
public static AddCommand Create <TEntity>(IRedisearchSerializer serializer, TEntity entity, double score, string language) where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var indexName = schemaMetadata.IndexName; var entityId = string.Concat(schemaMetadata.DocumentIdPrefix, schemaMetadata.PrimaryKey.GetPrimaryKeyFromEntity(entity)); if (string.IsNullOrEmpty(language)) { language = schemaMetadata.Language; } var parameters = new List <object> { indexName, entityId, score, RedisearchIndexCache.GetBoxedLiteral("LANGUAGE"), RedisearchIndexCache.GetBoxedLiteral(language), RedisearchIndexCache.GetBoxedLiteral("FIELDS") }; foreach (var fieldPairs in serializer.Serialize(entity)) { parameters.Add(fieldPairs.Key); parameters.Add(fieldPairs.Value); } return(new AddCommand(parameters)); }
protected void DropCreatedIndex <TEntity>() where TEntity : RedisearchSerializable <TEntity>, new() { var indexName = SchemaMetadata <TEntity> .GetSchemaMetadata().IndexName; Assert.That((string)Connection.GetDatabase().Execute("FT.DROP", indexName), Is.EqualTo("OK")); }
public void Default_id_should_be_overridable() { var schemaMetadata = SchemaMetadata <OverriddenIdPropertyTest> .GetSchemaMetadata(); Assert.That(schemaMetadata.PrimaryKey.EntityClrType, Is.EqualTo(typeof(OverriddenIdPropertyTest))); Assert.That(schemaMetadata.PrimaryKey.PropertyName, Is.EqualTo("InterestingId")); Assert.That(schemaMetadata.PrimaryKey.PropertyClrType, Is.EqualTo(typeof(DateTime))); }
public void GetPrimaryKeyFromProperty_should_throw_when_the_property_type_is_different() { var schemaMetadata = SchemaMetadata <GetPrimaryKeyFromEntityTests> .GetSchemaMetadata(); Assert.Throws <ArgumentException>(() => { schemaMetadata.PrimaryKey.GetPrimaryKeyFromProperty(Guid.Empty); }); }
public void Serialized_properties_should_include_all_get_set_properties_by_default() { var schemaMetadata = SchemaMetadata <SerializedPropertiesTest> .GetSchemaMetadata(); var serializedProperties = schemaMetadata.Properties.Where(p => !p.IsIgnored).Select(p => p.PropertyName); Assert.That(serializedProperties, Is.EquivalentTo(new[] { "Id", "Property1" })); }
public void GetPrimaryKeyFromEntity_should_return_the_id_value_as_a_RedisValue() { var schemaMetadata = SchemaMetadata <GetPrimaryKeyFromEntityTests> .GetSchemaMetadata(); var entity = new GetPrimaryKeyFromEntityTests { Id = 42 }; Assert.That(schemaMetadata.PrimaryKey.GetPrimaryKeyFromEntity(entity), Is.EqualTo((RedisValue)42)); }
public void Default_id_should_be_recognizable_by_convention() { var schemaMetadata1 = SchemaMetadata <IdPropertiesTest1> .GetSchemaMetadata(); Assert.That(schemaMetadata1.PrimaryKey.EntityClrType, Is.EqualTo(typeof(IdPropertiesTest1))); Assert.That(schemaMetadata1.PrimaryKey.PropertyName, Is.EqualTo("Id")); Assert.That(schemaMetadata1.PrimaryKey.PropertyClrType, Is.EqualTo(typeof(Guid))); var schemaMetadata2 = SchemaMetadata <IdPropertiesTest2> .GetSchemaMetadata(); Assert.That(schemaMetadata2.PrimaryKey.EntityClrType, Is.EqualTo(typeof(IdPropertiesTest2))); Assert.That(schemaMetadata2.PrimaryKey.PropertyName, Is.EqualTo("IdPropertiesTest2Id")); Assert.That(schemaMetadata2.PrimaryKey.PropertyClrType, Is.EqualTo(typeof(int))); }
public static DeleteCommand Create <TEntity>(TEntity entity, bool deleteFromDatabase) where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var documentKey = string.Concat(schemaMetadata.DocumentIdPrefix, schemaMetadata.PrimaryKey.GetPrimaryKeyFromEntity(entity)); if (deleteFromDatabase) { return(new DeleteFromIndexAndDatabaseCommand(schemaMetadata.IndexName, documentKey)); } return(new DeleteFromIndexCommand(schemaMetadata.IndexName, documentKey)); }
public IWhereOrOptions <TEntity> WithId <TProperty>(params TProperty[] ids) { if (ids == null || ids.Length == 0) { throw new ArgumentException("The id array must not be null or empty."); } var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); _ids = ids .Select(id => (RedisValue)string.Concat(schemaMetadata.DocumentIdPrefix, schemaMetadata.PrimaryKey.GetPrimaryKeyFromProperty(id))) .ToArray(); return(this); }
public IWhereOrOptions <TEntity> WithId <TProperty>(TProperty id) { if (id == null) { throw new ArgumentException("The id must not be null."); } var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); _ids = new[] { (RedisValue)string.Concat(schemaMetadata.DocumentIdPrefix, schemaMetadata.PrimaryKey.GetPrimaryKeyFromProperty(id)) }; return(this); }
internal List <object> CreateMGetArgs() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var args = new List <object>() { schemaMetadata.IndexName }; foreach (var id in _ids) { args.Add(id); } return(args); }
private void EnsureEntityMappingsAreRegistered <TEntity>() where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); if (!RedisMapper.IsRegisteredType <TEntity>()) { try { RedisMapper.RegisterType <TEntity>(schemaMetadata.Properties.Where(p => !p.IsIgnored).Select(p => p.PropertyName).ToArray()); } catch (Exception ex) { throw new ArgumentException($"Entity type cannot be serialized: {typeof(TEntity)}", ex); } } }
public static CreateIndexCommand Create <TEntity>() where TEntity : RedisearchSerializable <TEntity>, new() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var parameters = new List <object> { RedisearchIndexCache.GetBoxedIndexName(schemaMetadata.IndexName), RedisearchIndexCache.GetBoxedLiteral("SCHEMA") }; foreach (var propertyMetadata in schemaMetadata.Properties.Where(pm => !pm.IsIgnored)) { AddPropertyParametersTo(parameters, propertyMetadata); } return(new CreateIndexCommand(parameters)); }
public void Primary_key_with_of_an_IFormattable_should_return_a_value_with_InvariantCulture() { var schemaMetadata = SchemaMetadata <IFormattableTest> .GetSchemaMetadata(); var entity = new IFormattableTest { Id = new DateTime(2010, 10, 11, 12, 0, 0) }; var property = new DateTime(2010, 10, 11, 12, 0, 0); Assert.That( schemaMetadata.PrimaryKey.GetPrimaryKeyFromEntity(entity), Is.EqualTo((RedisValue) new DateTime(2010, 10, 11, 12, 0, 0).ToString(CultureInfo .InvariantCulture))); Assert.That( schemaMetadata.PrimaryKey.GetPrimaryKeyFromProperty(property), Is.EqualTo((RedisValue) new DateTime(2010, 10, 11, 12, 0, 0).ToString(CultureInfo .InvariantCulture))); }
public void Default_redisearch_properties_should_be_recognized() { var schemaMetadata = SchemaMetadata <DefaultRedisearchPropertyTypeTest> .GetSchemaMetadata(); var propertiesWithTypes = schemaMetadata.Properties.ToDictionary(p => p.PropertyName, p => p.RedisearchType); Assert.That(propertiesWithTypes["ByteProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["SByteProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["ShortProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["UShortProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["IntProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["UIntProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["LongProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["ULongProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["FloatProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["DoubleProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["DecimalProperty"], Is.EqualTo(RedisearchPropertyType.Numeric)); Assert.That(propertiesWithTypes["DateTimeProperty"], Is.EqualTo(RedisearchPropertyType.Fulltext)); Assert.That(propertiesWithTypes["CharProperty"], Is.EqualTo(RedisearchPropertyType.Fulltext)); Assert.That(propertiesWithTypes["StringProperty"], Is.EqualTo(RedisearchPropertyType.Fulltext)); Assert.That(propertiesWithTypes["GeoPositionProperty"], Is.EqualTo(RedisearchPropertyType.Geo)); Assert.That(propertiesWithTypes["ObjectProperty"], Is.EqualTo(RedisearchPropertyType.Fulltext)); }
internal List <object> CreateSearchArgs() { var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata(); var args = new List <object> { schemaMetadata.IndexName, BuildQueryString() }; if (Options.Verbatim) { args.Add(RedisearchIndexCache.GetBoxedLiteral("VERBATIM")); } if (Options.DisableStopwordFiltering) { args.Add(RedisearchIndexCache.GetBoxedLiteral("NOSTOPWORDS")); } if (Options.WithScores) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHSCORES")); } if (Options.WithPayloads) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHPAYLOADS")); } if (Options.WithScoreKeys) { args.Add(RedisearchIndexCache.GetBoxedLiteral("WITHSCOREKEYS")); } if (_ids != null && _ids.Length != 0) { args.Add(RedisearchIndexCache.GetBoxedLiteral("INKEYS")); args.Add(_ids.Length); foreach (var id in _ids) { args.Add(id); } } if (Options.Slop > -1) { args.Add(RedisearchIndexCache.GetBoxedLiteral("SLOP")); args.Add(Options.Slop); } if (Options.InOrder) { args.Add(RedisearchIndexCache.GetBoxedLiteral("INORDER")); } args.Add(RedisearchIndexCache.GetBoxedLiteral("LANGUAGE")); args.Add(string.IsNullOrEmpty(Options.Language) ? schemaMetadata.Language : RedisearchIndexCache.GetBoxedLiteral(Options.Language)); if (_sortingBy != null) { args.Add(RedisearchIndexCache.GetBoxedLiteral("SORTBY")); args.Add(_sortingBy); args.Add(_sortingOrder == SortingOrder.Ascending ? RedisearchIndexCache.GetBoxedLiteral("ASC") : RedisearchIndexCache.GetBoxedLiteral( "DESC")); } if (_paging.Offset != 0 || _paging.Count != 10) { args.Add(RedisearchIndexCache.GetBoxedLiteral("LIMIT")); args.Add(_paging.Offset); args.Add(_paging.Count); } return(args); }
public void Should_return_default_document_id_prefix_when_not_set() { var carSchemaInfo = SchemaMetadata <Car> .GetSchemaMetadata(); Assert.That(carSchemaInfo.DocumentIdPrefix, Is.EqualTo((RedisValue)"cars:")); }
public void Language_should_be_set_to_default_when_not_overridden() { var schemaMetadata = SchemaMetadata <DefaultLanguageTest> .GetSchemaMetadata(); Assert.That(schemaMetadata.Language, Is.EqualTo((RedisValue)"english")); }
public void Language_should_be_overridable() { var schemaMetadata = SchemaMetadata <OverriddenLanguageTest> .GetSchemaMetadata(); Assert.That(schemaMetadata.Language, Is.EqualTo((RedisValue)"hungarian")); }
protected FieldInfo[] GetFieldsInfo <TEntity>() where TEntity : RedisearchSerializable <TEntity>, new() { return(GetFieldsInfo(SchemaMetadata <TEntity> .GetSchemaMetadata().IndexName)); }
public void Should_throw_when_no_default_id_can_be_detected_and_no_override_was_specified() { Assert.Throws <ArgumentException>(() => SchemaMetadata <ThrowingIdPropertyTest> .GetSchemaMetadata()); }
public void GetPrimaryKeyFromProperty_should_return_the_property_value_as_a_RedisValue() { var schemaMetadata = SchemaMetadata <GetPrimaryKeyFromEntityTests> .GetSchemaMetadata(); Assert.That(schemaMetadata.PrimaryKey.GetPrimaryKeyFromProperty(42), Is.EqualTo((RedisValue)42)); }
public void Should_return_set_document_id_prefix() { var bossSchemaInfo = SchemaMetadata <Boss> .GetSchemaMetadata(); Assert.That(bossSchemaInfo.DocumentIdPrefix, Is.EqualTo((RedisValue)"boss-prefix")); }
public void Should_return_default_index_name_when_not_set() { var schemaMetadata = SchemaMetadata <Boss> .GetSchemaMetadata(); Assert.That(schemaMetadata.IndexName, Is.EqualTo((RedisValue)"boss-index")); }
public void Should_return_set_index_name() { var schemaMetadata = SchemaMetadata <Car> .GetSchemaMetadata(); Assert.That(schemaMetadata.IndexName, Is.EqualTo((RedisValue)"cars-indexname")); }