11using System . Reflection ;
22using NUnit . Framework ;
33using Nest . Tests . MockData . Domain ;
4+ using Newtonsoft . Json ;
45
56namespace Nest . Tests . Unit . Core . Update
67{
78 [ TestFixture ]
89 public class UpdateTests : BaseJsonTests
910 {
10- public class PartialElasticSearchProject
11+ public class PartialElasticsearchProject
1112 {
1213 public string Name { get ; set ; }
1314 public string Country { get ; set ; }
1415 }
16+
17+ /// <summary>
18+ /// This POCO models an ElasticsearchProject that allows country to serialize to null explicitly
19+ /// So that we can use it to clear contents in the Update API
20+ /// </summary>
21+ public class PartialElasticsearchProjectWithNull
22+ {
23+ [ JsonProperty ( NullValueHandling = NullValueHandling . Include ) ]
24+ public string Country { get ; set ; }
25+ }
26+
1527 public class UpsertCount
1628 {
1729 public int Count { get ; set ; }
@@ -26,8 +38,9 @@ public void UpsertUsingScript()
2638 . Add ( "count" , 4 )
2739 )
2840 . Upsert ( new UpsertCount { Count = 1 } ) ;
29- this . JsonEquals ( s , MethodInfo . GetCurrentMethod ( ) ) ;
41+ this . JsonEquals ( s , MethodBase . GetCurrentMethod ( ) ) ;
3042 }
43+
3144 [ Test ]
3245 public void UpsertUsingScriptAndPartialObject ( )
3346 {
@@ -38,20 +51,33 @@ public void UpsertUsingScriptAndPartialObject()
3851 )
3952 . Upsert ( new { count = 4 } ) ;
4053
41- this . JsonEquals ( s , MethodInfo . GetCurrentMethod ( ) ) ;
54+ this . JsonEquals ( s , MethodBase . GetCurrentMethod ( ) ) ;
4255 }
4356
4457 [ Test ]
4558 public void UpdateUsingPartial ( )
4659 {
4760 var originalProject = new ElasticsearchProject { Id = 1 , Name = "NeST" , Country = "UK" } ;
48- var partialUpdate = new PartialElasticSearchProject { Name = "NEST" , Country = "Netherlands" } ;
61+ var partialUpdate = new PartialElasticsearchProject { Name = "NEST" , Country = "Netherlands" } ;
62+
63+ var s = new UpdateDescriptor < ElasticsearchProject , PartialElasticsearchProject > ( )
64+ . IdFrom ( originalProject ) //only used to infer the id
65+ . Doc ( partialUpdate ) ; //the actual partial update statement;
66+
67+ this . JsonEquals ( s , MethodBase . GetCurrentMethod ( ) ) ;
68+ }
69+
70+ [ Test ]
71+ public void UpdateUsingPartialWithNull ( )
72+ {
73+ var originalProject = new ElasticsearchProject { Id = 1 , Name = "NEST" , Country = "UK" } ;
74+ var partialUpdate = new PartialElasticsearchProjectWithNull { Country = null } ;
4975
50- var s = new UpdateDescriptor < ElasticsearchProject , PartialElasticSearchProject > ( )
76+ var s = new UpdateDescriptor < ElasticsearchProject , PartialElasticsearchProjectWithNull > ( )
5177 . IdFrom ( originalProject ) //only used to infer the id
5278 . Doc ( partialUpdate ) ; //the actual partial update statement;
5379
54- this . JsonEquals ( s , MethodInfo . GetCurrentMethod ( ) ) ;
80+ this . JsonEquals ( s , MethodBase . GetCurrentMethod ( ) ) ;
5581 }
5682
5783 }
0 commit comments