예제 #1
0
        public void UniqueKey_Set_and_get() {
            var mgr = new MappingManager();
            var property = typeof (Entity).GetProperty("Id");
            mgr.Add(property, "id");
            mgr.SetUniqueKey(property);
            var key = mgr.GetUniqueKey(typeof (Entity));

            Assert.AreEqual(property, key.Property);
            Assert.AreEqual("id", key.FieldName);
        }
 public void SchemaNull_MappingNotNull_generates_error() {
     var rule = new UniqueKeyMatchesMappingRule();
     var mapper = new MappingManager();
     var idProperty = typeof (SchemaMappingTestDocument).GetProperty("ID");
     mapper.Add(idProperty);
     mapper.SetUniqueKey(idProperty);
     var validations = rule.Validate(typeof (SchemaMappingTestDocument), new SolrSchema(), mapper).ToList();
     Assert.IsNotNull(validations);
     Assert.AreEqual(1, validations.Count);
     foreach (var v in validations)
         Console.WriteLine("{0}: {1}", v.GetType(), v.Message);
     Assert.IsInstanceOfType<ValidationError>(validations[0]);
 }
        public void MatchingUniqueKeyMappingShouldNotReturnError() {
            var mgr = new MappingManager();
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof (SchemaMappingTestDocument).GetProperty("ID"));

            var schemaManager = new MappingValidator(mgr, new[] {new UniqueKeyMatchesMappingRule()});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(0, validationResults.Count);
        }
        public void RequiredSolrFieldForWhichNoCopyFieldExistsShouldReturnError() {
            var mgr = new MappingManager();
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof (SchemaMappingTestDocument).GetProperty("ID"));

            var schemaManager = new MappingValidator(mgr, new[] {new RequiredFieldsAreMappedRule()});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(1, validationResults.Count);
        }
        public void MappedPropertyForWhichDynamicFieldExistsInSchemaShouldNotReturnError() {
            var mgr = new MappingManager();
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("ID"), "id");
            mgr.SetUniqueKey(typeof (SchemaMappingTestDocument).GetProperty("ID"));
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("Name"), "name");
            mgr.Add(typeof (SchemaMappingTestDocument).GetProperty("Producer"), "producer_s");

            var schemaManager = new MappingValidator(mgr, new[] {new MappedPropertiesIsInSolrSchemaRule()});

            var schemaXmlDocument = EmbeddedResource.GetEmbeddedXml(GetType(), "Resources.solrSchemaBasic.xml");
            var solrSchemaParser = new SolrSchemaParser();
            var schema = solrSchemaParser.Parse(schemaXmlDocument);

            var validationResults = schemaManager.EnumerateValidationResults(typeof (SchemaMappingTestDocument), schema).ToList();
            Assert.AreEqual(0, validationResults.Count);
        }
예제 #6
0
 private static MappingManager MakeMapper(Type t)
 {
     // See https://github.com/mausch/SolrNet/blob/master/Documentation/Overriding-mapper.md
     var mapper = new MappingManager();
     foreach (var prop in t.GetProperties())
     {
         foreach (Attribute attribute in prop.GetCustomAttributes(true))
         {
             if (attribute is FieldAttribute)
             {
                 var fa = attribute as FieldAttribute;
                 string fieldName = string.IsNullOrWhiteSpace(fa.FieldName) ? prop.Name : fa.FieldName;
                 mapper.Add(prop, fieldName, fa.Boost);
             }
             else if (attribute is SolrFieldAttribute)
             {
                 var fa = attribute as SolrFieldAttribute;
                 string fieldName = string.IsNullOrWhiteSpace(fa.FieldName) ? prop.Name : fa.FieldName;
                 mapper.Add(prop, fieldName, fa.Boost);
             }
             if (attribute is UniqueKeyAttribute)
             {
                 var uka = attribute as UniqueKeyAttribute;
                 mapper.SetUniqueKey(prop);
             }
             if (attribute is SolrUniqueKeyAttribute)
             {
                 var uka = attribute as SolrUniqueKeyAttribute;
                 mapper.SetUniqueKey(prop);
             }
         }
     }
     return mapper;
 }
 public void SetUniqueKey_without_mapping_throws()
 {
     var mgr = new MappingManager();
     var property = typeof (Entity).GetProperty("Id");
     mgr.SetUniqueKey(property);
 }
 public void SetUniqueKey_doesnt_admit_null()
 {
     var mgr = new MappingManager();
     mgr.SetUniqueKey(null);
 }