@@ -35,6 +35,31 @@ protected override void OnDatabaseCreating(CouchDatabaseBuilder databaseBuilder)
35
35
. ToDatabase ( "shared-rebels" ) ;
36
36
}
37
37
}
38
+
39
+ private class MyDeathStarContextCustomSplit : CouchContext
40
+ {
41
+ public CouchDatabase < OtherRebel > OtherRebels { get ; set ; }
42
+ public CouchDatabase < SimpleRebel > SimpleRebels { get ; set ; }
43
+
44
+ protected override void OnConfiguring ( CouchOptionsBuilder optionsBuilder )
45
+ {
46
+ optionsBuilder
47
+ . UseEndpoint ( "http://localhost:5984/" )
48
+ . UseBasicAuthentication ( "admin" , "admin" )
49
+ . WithDatabaseSplitDiscriminator ( "docType" ) ;
50
+ }
51
+
52
+ protected override void OnDatabaseCreating ( CouchDatabaseBuilder databaseBuilder )
53
+ {
54
+ databaseBuilder
55
+ . Document < OtherRebel > ( )
56
+ . ToDatabase ( "shared-rebels" ) ;
57
+
58
+ databaseBuilder
59
+ . Document < SimpleRebel > ( )
60
+ . ToDatabase ( "shared-rebels" ) ;
61
+ }
62
+ }
38
63
39
64
[ Fact ]
40
65
public async Task Context_Query ( )
@@ -111,6 +136,50 @@ await context.OtherRebels.AddAsync(new OtherRebel
111
136
Assert . Equal ( @"{""selector"":{""split_discriminator"":""OtherRebel""}}" , httpTest . CallLog [ 2 ] . RequestBody ) ;
112
137
}
113
138
139
+ [ Fact ]
140
+ public async Task Context_Query_Discriminator_Override ( )
141
+ {
142
+ using var httpTest = new HttpTest ( ) ;
143
+ httpTest . RespondWithJson ( new
144
+ {
145
+ Id = "176694" ,
146
+ Ok = true ,
147
+ Rev = "1-54f8e950cc338d2385d9b0cda2fd918e"
148
+ } ) ;
149
+ httpTest . RespondWithJson ( new
150
+ {
151
+ Id = "173694" ,
152
+ Ok = true ,
153
+ Rev = "1-54f8e950cc338d2385d9b0cda2fd918e"
154
+ } ) ;
155
+ httpTest . RespondWithJson ( new
156
+ {
157
+ docs = new object [ ] {
158
+ new {
159
+ Id = "176694" ,
160
+ Rev = "1-54f8e950cc338d2385d9b0cda2fd918e" ,
161
+ Name = "Luke"
162
+ }
163
+ }
164
+ } ) ;
165
+
166
+ await using var context = new MyDeathStarContextCustomSplit ( ) ;
167
+ await context . SimpleRebels . AddAsync ( new SimpleRebel
168
+ {
169
+ Name = "Leia"
170
+ } ) ;
171
+ await context . OtherRebels . AddAsync ( new OtherRebel
172
+ {
173
+ Name = "Luke"
174
+ } ) ;
175
+ var result = await context . OtherRebels . ToListAsync ( ) ;
176
+ Assert . NotEmpty ( result ) ;
177
+ Assert . Equal ( "Luke" , result [ 0 ] . Name ) ;
178
+ Assert . Equal ( @"{""name"":""Leia"",""age"":0,""docType"":""SimpleRebel"",""_attachments"":{}}" , httpTest . CallLog [ 0 ] . RequestBody ) ;
179
+ Assert . Equal ( @"{""rebel_bith_date"":""0001-01-01T00:00:00"",""name"":""Luke"",""age"":0,""isJedi"":false,""species"":0,""guid"":""00000000-0000-0000-0000-000000000000"",""docType"":""OtherRebel"",""_attachments"":{}}" , httpTest . CallLog [ 1 ] . RequestBody ) ;
180
+ Assert . Equal ( @"{""selector"":{""docType"":""OtherRebel""}}" , httpTest . CallLog [ 2 ] . RequestBody ) ;
181
+ }
182
+
114
183
[ Fact ]
115
184
public async Task Context_Query_MultiThread ( )
116
185
{
0 commit comments