@@ -118,6 +118,123 @@ private static bool Equals(QuerySql.GetAuthorByIdRow x, QuerySql.GetAuthorByIdRo
118
118
return x . Id . Equals ( y . Id ) && x . Name . Equals ( y . Name ) && x . Bio . Equals ( y . Bio ) ;
119
119
}
120
120
121
+ [ Test ]
122
+ public async Task TestJoinEmbed ( )
123
+ {
124
+ var createAuthorArgs = new QuerySql . CreateAuthorReturnIdArgs
125
+ {
126
+ Name = DataGenerator . BojackAuthor ,
127
+ Bio = DataGenerator . BojackTheme
128
+ } ;
129
+ var bojackAuthorId = await QuerySql . CreateAuthorReturnId ( createAuthorArgs ) ;
130
+ var createBookArgs = new QuerySql . CreateBookArgs
131
+ {
132
+ Name = DataGenerator . BojackBookTitle ,
133
+ AuthorId = bojackAuthorId
134
+ } ;
135
+ await QuerySql . CreateBook ( createBookArgs ) ;
136
+ createAuthorArgs = new QuerySql . CreateAuthorReturnIdArgs
137
+ {
138
+ Name = DataGenerator . DrSeussAuthor ,
139
+ Bio = DataGenerator . DrSeussQuote
140
+ } ;
141
+ var drSeussAuthorId = await QuerySql . CreateAuthorReturnId ( createAuthorArgs ) ;
142
+ createBookArgs = new QuerySql . CreateBookArgs
143
+ {
144
+ Name = DataGenerator . DrSeussBookTitle ,
145
+ AuthorId = drSeussAuthorId
146
+ } ;
147
+ await QuerySql . CreateBook ( createBookArgs ) ;
148
+ var expected = new List < QuerySql . ListAllAuthorsBooksRow > ( )
149
+ {
150
+ new QuerySql . ListAllAuthorsBooksRow
151
+ {
152
+ Author = new Author
153
+ {
154
+ Name = DataGenerator . BojackAuthor ,
155
+ Bio = DataGenerator . BojackTheme ,
156
+ } ,
157
+ Book = new Book
158
+ {
159
+ Name = DataGenerator . BojackBookTitle ,
160
+ }
161
+ } ,
162
+ new QuerySql . ListAllAuthorsBooksRow
163
+ {
164
+ Author = new Author
165
+ {
166
+ Name = DataGenerator . DrSeussAuthor ,
167
+ Bio = DataGenerator . DrSeussQuote ,
168
+ } ,
169
+ Book = new Book
170
+ {
171
+ Name = DataGenerator . DrSeussBookTitle ,
172
+ }
173
+ }
174
+ } ;
175
+ var actual = await QuerySql . ListAllAuthorsBooks ( ) ;
176
+ Assert . That ( SequenceEquals ( expected , actual ) ) ;
177
+ }
178
+
179
+ private static bool Equals ( QuerySql . ListAllAuthorsBooksRow x , QuerySql . ListAllAuthorsBooksRow y )
180
+ {
181
+ return x . Author . Name . Equals ( y . Author . Name ) && x . Author . Bio . Equals ( y . Author . Bio ) && x . Book . Name . Equals ( y . Book . Name ) ;
182
+ }
183
+
184
+ private static bool SequenceEquals ( List < QuerySql . ListAllAuthorsBooksRow > x , List < QuerySql . ListAllAuthorsBooksRow > y )
185
+ {
186
+ if ( x . Count != y . Count )
187
+ return false ;
188
+ x = x . OrderBy < QuerySql . ListAllAuthorsBooksRow , object > ( o => o . Author . Name + o . Book . Name ) . ToList ( ) ;
189
+ y = y . OrderBy < QuerySql . ListAllAuthorsBooksRow , object > ( o => o . Author . Name + o . Book . Name ) . ToList ( ) ;
190
+ return ! x . Where ( ( t , i ) => ! Equals ( t , y [ i ] ) ) . Any ( ) ;
191
+ }
192
+
193
+ [ Test ]
194
+ public async Task TestSelfJoinEmbed ( )
195
+ {
196
+ var createAuthorArgs = new QuerySql . CreateAuthorArgs
197
+ {
198
+ Name = DataGenerator . BojackAuthor ,
199
+ Bio = DataGenerator . BojackTheme
200
+ } ;
201
+ await QuerySql . CreateAuthor ( createAuthorArgs ) ;
202
+ await QuerySql . CreateAuthor ( createAuthorArgs ) ;
203
+ var expected = new List < QuerySql . GetDuplicateAuthorsRow > ( )
204
+ {
205
+ new QuerySql . GetDuplicateAuthorsRow
206
+ {
207
+ Author = new Author
208
+ {
209
+ Name = DataGenerator . BojackAuthor ,
210
+ Bio = DataGenerator . BojackTheme
211
+ } ,
212
+ Author2 = new Author
213
+ {
214
+ Name = DataGenerator . BojackAuthor ,
215
+ Bio = DataGenerator . BojackTheme
216
+ }
217
+ }
218
+ } ;
219
+ var actual = await QuerySql . GetDuplicateAuthors ( ) ;
220
+ Assert . That ( SequenceEquals ( expected , actual ) ) ;
221
+ Assert . That ( actual [ 0 ] . Author . Id , Is . Not . EqualTo ( actual [ 0 ] . Author2 . Id ) ) ;
222
+ }
223
+
224
+ private static bool Equals ( QuerySql . GetDuplicateAuthorsRow x , QuerySql . GetDuplicateAuthorsRow y )
225
+ {
226
+ return x . Author . Name . Equals ( y . Author . Name ) && x . Author . Bio . Equals ( y . Author . Bio ) && x . Author2 . Name . Equals ( y . Author2 . Name ) && x . Author2 . Bio . Equals ( y . Author2 . Bio ) ;
227
+ }
228
+
229
+ private static bool SequenceEquals ( List < QuerySql . GetDuplicateAuthorsRow > x , List < QuerySql . GetDuplicateAuthorsRow > y )
230
+ {
231
+ if ( x . Count != y . Count )
232
+ return false ;
233
+ x = x . OrderBy < QuerySql . GetDuplicateAuthorsRow , object > ( o => o . Author . Name + o . Author2 . Name ) . ToList ( ) ;
234
+ y = y . OrderBy < QuerySql . GetDuplicateAuthorsRow , object > ( o => o . Author . Name + o . Author2 . Name ) . ToList ( ) ;
235
+ return ! x . Where ( ( t , i ) => ! Equals ( t , y [ i ] ) ) . Any ( ) ;
236
+ }
237
+
121
238
[ Test ]
122
239
public async Task TestSliceIds ( )
123
240
{
0 commit comments