-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathHelper.cs
More file actions
828 lines (769 loc) · 31.7 KB
/
Helper.cs
File metadata and controls
828 lines (769 loc) · 31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RepoDb.Extensions;
using RepoDb.IntegrationTests.Enumerations;
using RepoDb.IntegrationTests.Models;
using RepoDb.Interfaces;
using System;
using System.Collections.Generic;
using Microsoft.Data.SqlClient;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Reflection;
namespace RepoDb.IntegrationTests
{
/// <summary>
/// A helper class for the integration testing.
/// </summary>
public static class Helper
{
static Helper()
{
StatementBuilder = StatementBuilderMapper.Get<SqlConnection>();
EpocDate = new DateTime(1970, 1, 1, 0, 0, 0);
}
/// <summary>
/// Gets the instance of <see cref="IStatementBuilder"/> object.
/// </summary>
public static IStatementBuilder StatementBuilder { get; }
/// <summary>
/// Gets the value of the Epoc date.
/// </summary>
public static DateTime EpocDate { get; }
/// <summary>
/// Gets the description of the library.
/// </summary>
/// <returns>The description of the library.</returns>
public static string GetAssemblyDescription()
{
/* RepoDb: A dynamic, lightweight, and very fast ORM .NET Library. */
return typeof(TypeMapper)
.Assembly
.GetCustomAttributes(typeof(AssemblyDescriptionAttribute))?
.OfType<AssemblyDescriptionAttribute>()?
.FirstOrDefault()?
.Description;
}
/// <summary>
/// Gets a <see cref="Guid"/>-based random string.
/// </summary>
/// <returns>A <see cref="Guid"/>-based random string.</returns>
public static string GetGuidBasedRandomString()
{
return Guid.NewGuid().ToString();
}
/// <summary>
/// Gets a unicode string.
/// </summary>
/// <returns>A unicode string.</returns>
public static string GetUnicodeString()
{
return "ÀÆÇÈËÌÏÐÑÒØÙÜÝÞß";
}
/// <summary>
/// Converts the object into a type.
/// </summary>
/// <typeparam name="T">The target type to convert to.</typeparam>
/// <param name="obj">The object instance.</param>
/// <param name="strict">True if to be strict on the conversion.</param>
/// <returns>The instance of the converted object.</returns>
public static T ConverToType<T>(object obj, bool strict = true)
{
var fromType = obj.GetType();
var toTypeProperties = typeof(T).GetProperties();
var result = default(T);
fromType.GetProperties().AsList().ForEach(property =>
{
var toProperty = toTypeProperties.FirstOrDefault(p => p.Name == property.Name);
if (strict)
{
if (toProperty == null)
{
throw new NullReferenceException(property.Name);
}
}
if (toProperty == null)
{
return;
}
if (result == null)
{
result = Activator.CreateInstance<T>();
}
toProperty.SetValue(result, property.GetValue(obj));
});
return result;
}
/// <summary>
/// Asserts the properties equality of 2 types.
/// </summary>
/// <typeparam name="T1">The type of first object.</typeparam>
/// <typeparam name="T2">The type of second object.</typeparam>
/// <param name="t1">The instance of first object.</param>
/// <param name="t2">The instance of second object.</param>
public static void AssertPropertiesEquality<T1, T2>(T1 t1, T2 t2)
{
var propertiesOfType1 = typeof(T1).GetProperties();
var propertiesOfType2 = typeof(T2).GetProperties();
propertiesOfType1.AsList().ForEach(propertyOfType1 =>
{
if (propertyOfType1.Name == "Id")
{
return;
}
var propertyOfType2 = propertiesOfType2.FirstOrDefault(p => p.Name == propertyOfType1.Name);
if (propertyOfType2 == null)
{
return;
}
var value1 = propertyOfType1.GetValue(t1);
var value2 = propertyOfType2.GetValue(t2);
if (value1 is byte[] && value2 is byte[])
{
var b1 = (byte[])value1;
var b2 = (byte[])value2;
for (var i = 0; i < Math.Min(b1.Length, b2.Length); i++)
{
var v1 = b1[i];
var v2 = b2[i];
Assert.AreEqual(v1, v2,
$"Assert failed for '{propertyOfType1.Name}'. The values are '{value1} ({propertyOfType1.PropertyType.FullName})' and '{value2} ({propertyOfType2.PropertyType.FullName})'.");
}
}
else
{
Assert.AreEqual(value1, value2,
$"Assert failed for '{propertyOfType1.Name}'. The values are '{value1} ({propertyOfType1.PropertyType.FullName})' and '{value2} ({propertyOfType2.PropertyType.FullName})'.");
}
});
}
/// <summary>
/// Asserts the members equality of 2 object and <see cref="ExpandoObject"/>.
/// </summary>
/// <typeparam name="T">The type of first object.</typeparam>
/// <param name="obj">The instance of first object.</param>
/// <param name="expandoObj">The instance of second object.</param>
public static void AssertMembersEquality(object obj, object expandoObj)
{
var dictionary = new ExpandoObject() as IDictionary<string, object>;
foreach (var property in expandoObj.GetType().GetProperties())
{
dictionary.Add(property.Name, property.GetValue(expandoObj));
}
AssertMembersEquality(obj, dictionary);
}
/// <summary>
/// Asserts the members equality of 2 object and <see cref="ExpandoObject"/>.
/// </summary>
/// <typeparam name="T">The type of first object.</typeparam>
/// <param name="obj">The instance of first object.</param>
/// <param name="expandoObj">The instance of second object.</param>
public static void AssertMembersEquality(object obj, ExpandoObject expandoObj)
{
var dictionary = expandoObj as IDictionary<string, object>;
AssertMembersEquality(obj, dictionary);
}
/// <summary>
/// Asserts the members equality of 2 objects.
/// </summary>
/// <typeparam name="T">The type of first object.</typeparam>
/// <param name="obj">The instance of first object.</param>
/// <param name="dictionary">The instance of second object.</param>
public static void AssertMembersEquality(object obj, IDictionary<string, object> dictionary)
{
var properties = obj.GetType().GetProperties();
properties.AsList().ForEach(property =>
{
if (property.Name == "Id")
{
return;
}
if (dictionary.ContainsKey(property.Name))
{
var value1 = property.GetValue(obj);
var value2 = dictionary[property.Name];
if (value1 is byte[] && value2 is byte[])
{
var b1 = (byte[])value1;
var b2 = (byte[])value2;
for (var i = 0; i < Math.Min(b1.Length, b2.Length); i++)
{
var v1 = b1[i];
var v2 = b2[i];
Assert.AreEqual(v1, v2,
$"Assert failed for '{property.Name}'. The values are '{v1}' and '{v2}'.");
}
}
else
{
var propertyType = property.PropertyType.GetUnderlyingType();
if (propertyType == typeof(TimeSpan) && value2 is DateTime)
{
value2 = ((DateTime)value2).TimeOfDay;
}
Assert.AreEqual(Convert.ChangeType(value1, propertyType), Convert.ChangeType(value2, propertyType),
$"Assert failed for '{property.Name}'. The values are '{value1}' and '{value2}'.");
}
}
});
}
#region IdentityTable
/// <summary>
/// Creates a list of <see cref="IdentityTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="IdentityTable"/> objects.</returns>
public static List<IdentityTable> CreateIdentityTables(int count)
{
var tables = new List<IdentityTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new IdentityTable
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = index,
ColumnFloat = index,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="IdentityTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="IdentityTable"/> object.</returns>
public static IdentityTable CreateIdentityTable()
{
var random = new Random();
return new IdentityTable
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate,
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(random.Next(int.MinValue, int.MaxValue)),
ColumnFloat = Convert.ToSingle(random.Next(int.MinValue, int.MaxValue)),
ColumnInt = random.Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}
#endregion
#region NonIdentityTable
/// <summary>
/// Creates a list of <see cref="NonIdentityTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="IdentityTable"/> objects.</returns>
public static List<NonIdentityTable> CreateNonIdentityTables(int count)
{
var tables = new List<NonIdentityTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new NonIdentityTable
{
Id = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = index,
ColumnFloat = index,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="NonIdentityTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="NonIdentityTable"/> object.</returns>
public static NonIdentityTable CreateNonIdentityTable()
{
var random = new Random();
return new NonIdentityTable
{
Id = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate,
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(random.Next(int.MinValue, int.MaxValue)),
ColumnFloat = Convert.ToSingle(random.Next(int.MinValue, int.MaxValue)),
ColumnInt = random.Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}
#endregion
#region WithExtraFieldsIdentityTable
/// <summary>
/// Creates a list of <see cref="WithExtraFieldsIdentityTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="IdentityTable"/> objects.</returns>
public static List<WithExtraFieldsIdentityTable> CreateWithExtraFieldsIdentityTables(int count)
{
var tables = new List<WithExtraFieldsIdentityTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new WithExtraFieldsIdentityTable
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = index,
ColumnFloat = index,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}",
ExtraField = $"ExtraField{index}",
IdentityTables = new[]
{
CreateIdentityTable(),
CreateIdentityTable()
}
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="WithExtraFieldsIdentityTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="NonIdentityTable"/> object.</returns>
public static WithExtraFieldsIdentityTable CreateWithExtraFieldsIdentityTable()
{
var random = new Random();
return new WithExtraFieldsIdentityTable
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate,
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(random.Next(int.MinValue, int.MaxValue)),
ColumnFloat = Convert.ToSingle(random.Next(int.MinValue, int.MaxValue)),
ColumnInt = random.Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}
#endregion
#region IdentityTableWithDifferentPrimary
/// <summary>
/// Creates a list of <see cref="IdentityTableWithDifferentPrimary"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="IdentityTableWithDifferentPrimary"/> objects.</returns>
public static List<IdentityTableWithDifferentPrimary> CreateIdentityTableWithDifferentPrimaries(int count)
{
var tables = new List<IdentityTableWithDifferentPrimary>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new IdentityTableWithDifferentPrimary
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index).ToString(CultureInfo.InvariantCulture),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = index,
ColumnFloat = index,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="IdentityTableWithDifferentPrimary"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="IdentityTableWithDifferentPrimary"/> object.</returns>
public static IdentityTableWithDifferentPrimary CreateIdentityTableWithDifferentPrimary()
{
var random = new Random();
return new IdentityTableWithDifferentPrimary
{
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.ToString(CultureInfo.InvariantCulture),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(random.Next(int.MinValue, int.MaxValue)),
ColumnFloat = Convert.ToSingle(random.Next(int.MinValue, int.MaxValue)),
ColumnInt = random.Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}
#endregion
#region EnumCompleteTable
/// <summary>
/// Creates a list of <see cref="EnumCompleteTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="EnumCompleteTable"/> objects.</returns>
public static List<EnumCompleteTable> CreateEnumCompleteTables(int count)
{
var tables = new List<EnumCompleteTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new EnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnBit = BooleanValue.True,
ColumnNVarChar = Direction.West,
ColumnInt = Direction.West,
ColumnBigInt = Direction.West,
ColumnSmallInt = Direction.West
});
}
return tables;
}
/// <summary>
/// Creates a list of <see cref="EnumCompleteTable"/> objects with null properties.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="EnumCompleteTable"/> objects.</returns>
public static List<EnumCompleteTable> CreateEnumCompleteTablesAsNull(int count)
{
var tables = new List<EnumCompleteTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new EnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnBit = null,
ColumnNVarChar = null,
ColumnInt = null,
ColumnBigInt = null,
ColumnSmallInt = null,
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="EnumCompleteTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="EnumCompleteTable"/> object.</returns>
public static EnumCompleteTable CreateEnumCompleteTable()
{
return new EnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnBit = BooleanValue.True,
ColumnNVarChar = Direction.West,
ColumnInt = Direction.West,
ColumnBigInt = Direction.West,
ColumnSmallInt = Direction.West
};
}
/// <summary>
/// Creates an instance of <see cref="EnumCompleteTable"/> object with null properties.
/// </summary>
/// <returns>A new created instance of <see cref="EnumCompleteTable"/> object.</returns>
public static EnumCompleteTable CreateEnumCompleteTableAsNull()
{
return new EnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnBit = null,
ColumnNVarChar = null,
ColumnInt = null,
ColumnBigInt = null,
ColumnSmallInt = null
};
}
#endregion
#region EnumAsIntForStringCompleteTable
/// <summary>
/// Creates a list of <see cref="EnumAsIntForStringCompleteTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="EnumAsIntForStringCompleteTable"/> objects.</returns>
public static List<EnumAsIntForStringCompleteTable> CreateEnumAsIntForStringCompleteTables(int count)
{
var tables = new List<EnumAsIntForStringCompleteTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new EnumAsIntForStringCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = Direction.West
});
}
return tables;
}
/// <summary>
/// Creates a list of <see cref="EnumAsIntForStringCompleteTable"/> objects with null properties.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="EnumAsIntForStringCompleteTable"/> objects.</returns>
public static List<EnumAsIntForStringCompleteTable> CreateEnumAsIntForStringCompleteTablesAsNull(int count)
{
var tables = new List<EnumAsIntForStringCompleteTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new EnumAsIntForStringCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = null
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="EnumAsIntForStringCompleteTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="EnumAsIntForStringCompleteTable"/> object.</returns>
public static EnumAsIntForStringCompleteTable CreateEnumAsIntForStringCompleteTable()
{
return new EnumAsIntForStringCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = Direction.West
};
}
/// <summary>
/// Creates an instance of <see cref="EnumAsIntForStringCompleteTable"/> object with null properties.
/// </summary>
/// <returns>A new created instance of <see cref="EnumAsIntForStringCompleteTable"/> object.</returns>
public static EnumAsIntForStringCompleteTable CreateEnumAsIntForStringCompleteTableAsNull()
{
return new EnumAsIntForStringCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = null
};
}
#endregion
#region TypeLevelMappedForStringEnumCompleteTable
/// <summary>
/// Creates a list of <see cref="TypeLevelMappedForStringEnumCompleteTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="TypeLevelMappedForStringEnumCompleteTable"/> objects.</returns>
public static List<TypeLevelMappedForStringEnumCompleteTable> CreateTypeLevelMappedForStringEnumCompleteTables(int count)
{
var tables = new List<TypeLevelMappedForStringEnumCompleteTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new TypeLevelMappedForStringEnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = Continent.Asia
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="TypeLevelMappedForStringEnumCompleteTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="TypeLevelMappedForStringEnumCompleteTable"/> object.</returns>
public static TypeLevelMappedForStringEnumCompleteTable CreateTypeLevelMappedForStringEnumCompleteTable()
{
return new TypeLevelMappedForStringEnumCompleteTable
{
SessionId = Guid.NewGuid(),
ColumnNVarChar = Continent.Asia
};
}
#endregion
#region UnorganizedTable
/// <summary>
/// Creates a list of <see cref="UnorganizedTable"/> objects.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of <see cref="UnorganizedTable"/> objects.</returns>
public static List<UnorganizedTable> CreateUnorganizedTables(int count)
{
var tables = new List<UnorganizedTable>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new UnorganizedTable
{
SessionId = Guid.NewGuid(),
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates an instance of <see cref="UnorganizedTable"/> object.
/// </summary>
/// <returns>A new created instance of <see cref="UnorganizedTable"/> object.</returns>
public static UnorganizedTable CreateUnorganizedTable()
{
var random = new Random();
return new UnorganizedTable
{
SessionId = Guid.NewGuid(),
ColumnDateTime2 = DateTime.UtcNow,
ColumnInt = random.Next(int.MinValue, int.MaxValue),
ColumnNVarChar = Guid.NewGuid().ToString()
};
}
#endregion
#region Dynamics
#region IdentityTable
/// <summary>
/// Creates a an instance of dynamic object for [sc].[IdentityTable].
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A dynamic for [sc].[IdentityTable].</returns>
public static dynamic CreateDynamicIdentityTable()
{
return new
{
Id = 1,
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(1),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(1),
ColumnFloat = Convert.ToSingle(1),
ColumnInt = 1,
ColumnNVarChar = $"NVARCHAR{1}"
};
}
/// <summary>
/// Creates a list of dynamic objects for [sc].[IdentityTable].
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static List<dynamic> CreateDynamicIdentityTables(int count)
{
var tables = new List<dynamic>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
Id = index,
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(index),
ColumnFloat = Convert.ToSingle(index),
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates a list of dynamic objects for [sc].[IdentityTable] with limited columns.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static Tuple<List<dynamic>, IEnumerable<Field>> CreateDynamicIdentityTablesWithLimitedColumns(int count)
{
var tables = new List<dynamic>();
var fields = Field.From(new[]
{
"RowGuid",
"ColumnBit",
"ColumnDateTime2",
"ColumnNVarChar"
});
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
Id = index,
RowGuid = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime2 = DateTime.UtcNow,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return new Tuple<List<dynamic>, IEnumerable<Field>>(tables, fields);
}
#endregion
#region NonIdentityTable
/// <summary>
/// Creates a an instance of dynamic object for [sc].[NonIdentityTable].
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A dynamic for [sc].[NonIdentityTable].</returns>
public static dynamic CreateDynamicNonIdentityTable()
{
return new
{
Id = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(1),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(1),
ColumnFloat = Convert.ToSingle(1),
ColumnInt = 1,
ColumnNVarChar = $"NVARCHAR{1}"
};
}
/// <summary>
/// Creates a list of dynamic objects for [dbo].[NonIdentityTable].
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static List<dynamic> CreateDynamicNonIdentityTables(int count)
{
var tables = new List<dynamic>();
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
Id = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime = EpocDate.AddDays(index),
ColumnDateTime2 = DateTime.UtcNow,
ColumnDecimal = Convert.ToDecimal(index),
ColumnFloat = Convert.ToSingle(index),
ColumnInt = index,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return tables;
}
/// <summary>
/// Creates a list of dynamic objects for [dbo].[NonIdentityTable] with limited columns.
/// </summary>
/// <param name="count">The number of rows.</param>
/// <returns>A list of dynamic objects.</returns>
public static Tuple<List<dynamic>, IEnumerable<Field>> CreateDynamicNonIdentityTablesWithLimitedColumns(int count)
{
var tables = new List<dynamic>();
var fields = Field.From(new[]
{
"Id",
"ColumnBit",
"ColumnDateTime2",
"ColumnNVarChar"
});
for (var i = 0; i < count; i++)
{
var index = i + 1;
tables.Add(new
{
Id = Guid.NewGuid(),
ColumnBit = true,
ColumnDateTime2 = DateTime.UtcNow,
ColumnNVarChar = $"NVARCHAR{index}"
});
}
return new Tuple<List<dynamic>, IEnumerable<Field>>(tables, fields);
}
#endregion
#endregion
}
}