Skip to content

Commit b90796f

Browse files
committed
Fix broken integration tests
When comparing ComparisonValues on PropertyName for equality, us .Equals() instead of == operator Add Automap documentation for ignoring properties on POCOs When writing a property as part of PropertyMapping, check that it is not a property that should be ignored
1 parent 9d3f09d commit b90796f

File tree

5 files changed

+74
-5
lines changed

5 files changed

+74
-5
lines changed

src/Nest/CommonAbstractions/Infer/PropertyName/PropertyName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public override bool Equals(object obj)
5656
var other = obj as PropertyName;
5757
if (other == null)
5858
return false;
59-
return ComparisonValue == other.ComparisonValue;
59+
60+
return ComparisonValue.Equals(other.ComparisonValue);
6061
}
6162

6263
string IUrlParameter.GetString(IConnectionConfigurationValues settings)

src/Nest/CommonAbstractions/SerializationBehavior/GenericJsonConverters/VerbatimDictionaryKeysConverter.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,28 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4444
else if (fieldName != null)
4545
key = settings.Inferrer.Field(fieldName);
4646
else if (propertyName != null)
47+
{
48+
if (propertyName.Property != null)
49+
{
50+
IPropertyMapping mapping;
51+
if (settings.PropertyMappings.TryGetValue(propertyName.Property, out mapping) && mapping.Ignore)
52+
{
53+
continue;
54+
}
55+
}
56+
4757
key = settings.Inferrer.PropertyName(propertyName);
58+
}
4859
else if (indexName != null)
4960
key = settings.Inferrer.IndexName(indexName);
5061
else if (typeName != null)
5162
key = settings.Inferrer.TypeName(typeName);
5263
else
5364
key = Convert.ToString(entry.Key, CultureInfo.InvariantCulture);
65+
5466
writer.WritePropertyName(key);
5567
serializer.Serialize(writer, entry.Value);
68+
5669
}
5770

5871
writer.WriteEndObject();

src/Tests/ClientConcepts/HighLevel/Mapping/AutoMap.doc.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,61 @@ public void OverridingAutoMappedAttributes()
581581
Expect(expected).WhenSerializing((ICreateIndexRequest) descriptor);
582582
}
583583

584+
[ElasticsearchType(Name = "company")]
585+
public class CompanyWithAttributesAndPropertiesToIgnore
586+
{
587+
public string Name { get; set; }
588+
589+
[String(Ignore = true)]
590+
public string PropertyToIgnore { get; set; }
591+
592+
public string AnotherPropertyToIgnore { get; set; }
593+
}
594+
595+
/**
596+
* Properties on a POCO can be ignored in a couple of ways:
597+
* - Using the `Ignore` property on a derived `ElasticsearchPropertyAttribute` type applied to the property that cshoule be ignored on the POCO
598+
* - Using the `.InferMappingFor<TDocument>(Func<ClrTypeMappingDescriptor<TDocument>, IClrTypeMapping<TDocument>> selector)` on the connection settings
599+
* This example demonstrates both ways, using the attribute way to ignore the property `PropertyToIgnore` and the infer mapping way to ignore the
600+
* property `AnotherPropertyToIgnore`
601+
*/
602+
[U]
603+
public void IgnoringProperties()
604+
{
605+
var descriptor = new CreateIndexDescriptor("myindex")
606+
.Mappings(ms => ms
607+
.Map<CompanyWithAttributesAndPropertiesToIgnore>(m => m
608+
.AutoMap()
609+
)
610+
);
611+
612+
/** Thus we do not map properties on the second occurrence of our Child property */
613+
var expected = new
614+
{
615+
mappings = new
616+
{
617+
company = new
618+
{
619+
properties = new
620+
{
621+
name = new
622+
{
623+
type = "string"
624+
}
625+
}
626+
}
627+
}
628+
};
629+
630+
var settings = WithConnectionSettings(s => s
631+
.InferMappingFor<CompanyWithAttributesAndPropertiesToIgnore>(i => i
632+
.Ignore(p => p.AnotherPropertyToIgnore)
633+
)
634+
);
635+
636+
settings.Expect(expected).WhenSerializing((ICreateIndexRequest) descriptor);
637+
}
638+
584639
/**
585640
* If you notice in our previous Company/Employee examples, the Employee type is recursive
586641
* in that itself contains a collection of type Employee. By default, AutoMap() will only
@@ -593,7 +648,7 @@ public void OverridingAutoMappedAttributes()
593648
*
594649
* Let's introduce a very simple class A, to reduce the noise, which itself has a property
595650
* Child of type A.
596-
*/
651+
*/
597652
public class A
598653
{
599654
public A Child { get; set; }

src/Tests/Framework/Integration/Process/ElasticsearchNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public IObservable<ElasticsearchMessage> Start(string[] additionalSettings = nul
8787
if (!this.RunningIntegrations) return Observable.Empty<ElasticsearchMessage>();
8888

8989
this.Stop();
90-
var timeout = TimeSpan.FromSeconds(60);
90+
var timeout = TimeSpan.FromMinutes(1);
9191
var handle = new ManualResetEvent(false);
9292

9393
if (_doNotSpawnIfAlreadyRunning)

src/Tests/Framework/TestClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public static ConnectionSettings CreateSettings(
5959
public static IElasticClient GetInMemoryClient(Func<ConnectionSettings, ConnectionSettings> modifySettings = null, int port = 9200) =>
6060
new ElasticClient(CreateSettings(modifySettings, port, forceInMemory: true));
6161

62-
public static IElasticClient GetInMemoryClient(Func<ConnectionSettings, ConnectionSettings> modifySettings, Func<ConnectionSettings, IElasticsearchSerializer> _serializerFactory) =>
63-
new ElasticClient(CreateSettings(modifySettings, forceInMemory: true, serializerFactory: _serializerFactory));
62+
public static IElasticClient GetInMemoryClient(Func<ConnectionSettings, ConnectionSettings> modifySettings, Func<ConnectionSettings, IElasticsearchSerializer> serializerFactory) =>
63+
new ElasticClient(CreateSettings(modifySettings, forceInMemory: true, serializerFactory: serializerFactory));
6464

6565
public static IElasticClient GetClient(
6666
Func<ConnectionSettings, ConnectionSettings> modifySettings = null, int port = 9200, Func<Uri, IConnectionPool> createPool = null) =>

0 commit comments

Comments
 (0)