Skip to content

Commit 6f59783

Browse files
committed
Better asserts.
1 parent f6a317f commit 6f59783

File tree

1 file changed

+29
-79
lines changed

1 file changed

+29
-79
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient.Tests/FbArrayTests.cs

Lines changed: 29 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using System;
1919
using System.Collections;
20+
using System.Linq;
2021
using System.Security.Cryptography;
2122
using FirebirdSql.Data.FirebirdClient;
2223
using FirebirdSql.Data.TestsBase;
@@ -71,12 +72,8 @@ public void IntegerArrayTest()
7172
if (!reader.IsDBNull(0))
7273
{
7374
int[] select_values = new int[insert_values.Length];
74-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
75-
76-
for (int i = 0; i < insert_values.Length; i++)
77-
{
78-
Assert.AreEqual(insert_values[i], select_values[i]);
79-
}
75+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
76+
CollectionAssert.AreEqual(insert_values, select_values);
8077
}
8178
}
8279
reader.Close();
@@ -115,12 +112,8 @@ public void ShortArrayTest()
115112
if (!reader.IsDBNull(0))
116113
{
117114
short[] select_values = new short[insert_values.Length];
118-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
119-
120-
for (int i = 0; i < insert_values.Length; i++)
121-
{
122-
Assert.AreEqual(insert_values[i], select_values[i]);
123-
}
115+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
116+
CollectionAssert.AreEqual(insert_values, select_values);
124117
}
125118
}
126119
reader.Close();
@@ -159,12 +152,8 @@ public void BigIntArrayTest()
159152
if (!reader.IsDBNull(0))
160153
{
161154
long[] select_values = new long[insert_values.Length];
162-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
163-
164-
for (int i = 0; i < insert_values.Length; i++)
165-
{
166-
Assert.AreEqual(insert_values[i], select_values[i]);
167-
}
155+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
156+
CollectionAssert.AreEqual(insert_values, select_values);
168157
}
169158
}
170159
reader.Close();
@@ -203,12 +192,8 @@ public void FloatArrayTest()
203192
if (!reader.IsDBNull(0))
204193
{
205194
float[] select_values = new float[insert_values.Length];
206-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
207-
208-
for (int i = 0; i < insert_values.Length; i++)
209-
{
210-
Assert.AreEqual(insert_values[i], select_values[i]);
211-
}
195+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
196+
CollectionAssert.AreEqual(insert_values, select_values);
212197
}
213198
}
214199
reader.Close();
@@ -247,12 +232,8 @@ public void DoubleArrayTest()
247232
if (!reader.IsDBNull(0))
248233
{
249234
double[] select_values = new double[insert_values.Length];
250-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
251-
252-
for (int i = 0; i < insert_values.Length; i++)
253-
{
254-
Assert.AreEqual(insert_values[i], select_values[i]);
255-
}
235+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
236+
CollectionAssert.AreEqual(insert_values, select_values);
256237
}
257238
}
258239
reader.Close();
@@ -291,12 +272,8 @@ public void NumericArrayTest()
291272
if (!reader.IsDBNull(0))
292273
{
293274
decimal[] select_values = new decimal[insert_values.Length];
294-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
295-
296-
for (int i = 0; i < insert_values.Length; i++)
297-
{
298-
Assert.AreEqual(insert_values[i], select_values[i]);
299-
}
275+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
276+
CollectionAssert.AreEqual(insert_values, select_values);
300277
}
301278
}
302279
reader.Close();
@@ -335,12 +312,8 @@ public void DateArrayTest()
335312
if (!reader.IsDBNull(0))
336313
{
337314
DateTime[] select_values = new DateTime[insert_values.Length];
338-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
339-
340-
for (int i = 0; i < insert_values.Length; i++)
341-
{
342-
Assert.AreEqual(insert_values[i], select_values[i]);
343-
}
315+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
316+
CollectionAssert.AreEqual(insert_values, select_values);
344317
}
345318
}
346319
reader.Close();
@@ -379,12 +352,8 @@ public void TimeArrayTest()
379352
if (!reader.IsDBNull(0))
380353
{
381354
TimeSpan[] select_values = new TimeSpan[insert_values.Length];
382-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
383-
384-
for (int i = 0; i < insert_values.Length; i++)
385-
{
386-
Assert.AreEqual(insert_values[i], select_values[i]);
387-
}
355+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
356+
CollectionAssert.AreEqual(insert_values, select_values);
388357
}
389358
}
390359
reader.Close();
@@ -423,13 +392,9 @@ public void TimeStampArrayTest()
423392
if (!reader.IsDBNull(0))
424393
{
425394
DateTime[] select_values = new DateTime[insert_values.Length];
426-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
427-
428-
for (int i = 0; i < insert_values.Length; i++)
429-
{
430-
var truncatedPrecision = new DateTime(insert_values[i].Ticks / 1000 * 1000);
431-
Assert.AreEqual(truncatedPrecision, select_values[i]);
432-
}
395+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
396+
insert_values = insert_values.Select(x => new DateTime(x.Ticks / 1000 * 1000)).ToArray();
397+
CollectionAssert.AreEqual(insert_values, select_values);
433398
}
434399
}
435400
reader.Close();
@@ -468,12 +433,9 @@ public void CharArrayTest()
468433
if (!reader.IsDBNull(0))
469434
{
470435
string[] select_values = new string[insert_values.Length];
471-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
472-
473-
for (int i = 0; i < insert_values.Length; i++)
474-
{
475-
Assert.AreEqual(insert_values[i], select_values[i].TrimEnd(' '));
476-
}
436+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
437+
select_values = select_values.Select(x => x.TrimEnd(' ')).ToArray();
438+
CollectionAssert.AreEqual(insert_values, select_values);
477439
}
478440
}
479441
reader.Close();
@@ -512,12 +474,8 @@ public void VarCharArrayTest()
512474
if (!reader.IsDBNull(0))
513475
{
514476
string[] select_values = new string[insert_values.Length];
515-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
516-
517-
for (int i = 0; i < insert_values.Length; i++)
518-
{
519-
Assert.AreEqual(insert_values[i], select_values[i]);
520-
}
477+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
478+
CollectionAssert.AreEqual(insert_values, select_values);
521479
}
522480
}
523481
reader.Close();
@@ -768,12 +726,8 @@ public void BigArrayTest()
768726
if (!reader.IsDBNull(0))
769727
{
770728
int[] select_values = new int[insert_values.Length];
771-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
772-
773-
for (int i = 0; i < insert_values.Length; i++)
774-
{
775-
Assert.AreEqual(insert_values[i], select_values[i]);
776-
}
729+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
730+
CollectionAssert.AreEqual(insert_values, select_values);
777731
}
778732
}
779733

@@ -814,12 +768,8 @@ public void PartialUpdatesTest()
814768
if (!reader.IsDBNull(0))
815769
{
816770
int[] select_values = new int[insert_values.Length];
817-
System.Array.Copy((System.Array)reader.GetValue(0), select_values, select_values.Length);
818-
819-
for (int i = 0; i < insert_values.Length; i++)
820-
{
821-
Assert.AreEqual(insert_values[i], select_values[i]);
822-
}
771+
Array.Copy((Array)reader.GetValue(0), select_values, select_values.Length);
772+
CollectionAssert.AreEqual(insert_values, select_values);
823773
}
824774
}
825775

0 commit comments

Comments
 (0)