Skip to content

Commit 7591b5d

Browse files
committed
modernize codebase
1 parent 4ab4540 commit 7591b5d

File tree

11 files changed

+56
-147
lines changed

11 files changed

+56
-147
lines changed

DeepCloner.Core.Tests/ArraysSpec.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ArraysSpec
99
[Test]
1010
public void IntArray_Should_Be_Cloned()
1111
{
12-
int[] arr = new[] { 1, 2, 3 };
12+
int[] arr = [1, 2, 3];
1313
int[] cloned = arr.DeepClone();
1414
Assert.That(cloned.Length, Is.EqualTo(3));
1515
CollectionAssert.AreEqual(arr, cloned);
@@ -18,7 +18,7 @@ public void IntArray_Should_Be_Cloned()
1818
[Test]
1919
public void StringArray_Should_Be_Cloned()
2020
{
21-
string[] arr = new[] { "1", "2", "3" };
21+
string[] arr = ["1", "2", "3"];
2222
string[] cloned = arr.DeepClone();
2323
Assert.That(cloned.Length, Is.EqualTo(3));
2424
CollectionAssert.AreEqual(arr, cloned);
@@ -28,7 +28,7 @@ public void StringArray_Should_Be_Cloned()
2828
public void StringArray_Should_Be_Cloned_Two_Arrays()
2929
{
3030
// checking that cached object correctly clones arrays of different length
31-
string[]? arr = new[] { "111111111111111111111", "2", "3" };
31+
string[]? arr = ["111111111111111111111", "2", "3"];
3232
string[] cloned = arr.DeepClone();
3333
Assert.That(cloned.Length, Is.EqualTo(3));
3434
CollectionAssert.AreEqual(arr, cloned);
@@ -85,7 +85,7 @@ public class C1
8585
[Test]
8686
public void ClassArray_Should_Be_Cloned()
8787
{
88-
C1[] arr = new[] { new C1(1), new C1(2) };
88+
C1[] arr = [new C1(1), new C1(2)];
8989
C1[] cloned = arr.DeepClone();
9090
Assert.That(cloned.Length, Is.EqualTo(2));
9191
Assert.That(cloned[0].X, Is.EqualTo(1));
@@ -109,7 +109,7 @@ public struct S2
109109
[Test]
110110
public void StructArray_Should_Be_Cloned()
111111
{
112-
S1[] arr = new[] { new S1(1), new S1(2) };
112+
S1[] arr = [new S1(1), new S1(2)];
113113
S1[] cloned = arr.DeepClone();
114114
Assert.That(cloned.Length, Is.EqualTo(2));
115115
Assert.That(cloned[0].X, Is.EqualTo(1));
@@ -119,7 +119,7 @@ public void StructArray_Should_Be_Cloned()
119119
[Test]
120120
public void StructArray_With_Class_Should_Be_Cloned()
121121
{
122-
S2[] arr = new[] { new S2 { C = new C1(1) }, new S2 { C = new C1(2) } };
122+
S2[] arr = [new S2 { C = new C1(1) }, new S2 { C = new C1(2) }];
123123
S2[] cloned = arr.DeepClone();
124124
Assert.That(cloned.Length, Is.EqualTo(2));
125125
Assert.That(cloned[0].C.X, Is.EqualTo(1));
@@ -131,7 +131,7 @@ public void StructArray_With_Class_Should_Be_Cloned()
131131
[Test]
132132
public void NullArray_hould_Be_Cloned()
133133
{
134-
C1[] arr = new C1[] { null, null };
134+
C1[] arr = [null, null];
135135
C1[] cloned = arr.DeepClone();
136136
Assert.That(cloned.Length, Is.EqualTo(2));
137137
Assert.That(cloned[0], Is.Null);
@@ -152,7 +152,7 @@ public void NullAsArray_hould_Be_Cloned()
152152
public void IntList_Should_Be_Cloned()
153153
{
154154
// TODO: better performance for this type
155-
List<int> arr = new List<int> { 1, 2, 3 };
155+
List<int> arr = [1, 2, 3];
156156
List<int> cloned = arr.DeepClone();
157157
Assert.That(cloned.Count, Is.EqualTo(3));
158158
Assert.That(cloned[0], Is.EqualTo(1));
@@ -176,8 +176,8 @@ public void Dictionary_Should_Be_Cloned()
176176
[Test]
177177
public void Array_Of_Same_Arrays_Should_Be_Cloned()
178178
{
179-
int[] c1 = new[] { 1, 2, 3 };
180-
int[][] arr = new[] { c1, c1, c1, c1, c1 };
179+
int[] c1 = [1, 2, 3];
180+
int[][] arr = [c1, c1, c1, c1, c1];
181181
int[][] cloned = arr.DeepClone();
182182

183183
Assert.That(cloned.Length, Is.EqualTo(5));
@@ -309,7 +309,7 @@ public void NonZero_Based_MultiDim_Array_Should_Be_Cloned()
309309
[Test]
310310
public void Array_As_Generic_Array_Should_Be_Cloned()
311311
{
312-
int[] arr = new[] { 1, 2, 3 };
312+
int[] arr = [1, 2, 3];
313313
Array genArr = arr;
314314
int[] clone = (int[])genArr.DeepClone();
315315
Assert.That(clone.Length, Is.EqualTo(3));
@@ -321,7 +321,7 @@ public void Array_As_Generic_Array_Should_Be_Cloned()
321321
[Test]
322322
public void Array_As_IEnumerable_Should_Be_Cloned()
323323
{
324-
int[] arr = new[] { 1, 2, 3 };
324+
int[] arr = [1, 2, 3];
325325
IEnumerable<int> genArr = arr;
326326
int[] clone = (int[])genArr.DeepClone();
327327
// ReSharper disable PossibleMultipleEnumeration
@@ -351,7 +351,7 @@ public void MultiDimensional_Array_Should_Be_Cloned()
351351
[Test]
352352
public void Issue_17_Spec()
353353
{
354-
HashSet<string> set = new HashSet<string> { "value" };
354+
HashSet<string> set = ["value"];
355355
Assert.That(set.Contains("value"), Is.True);
356356

357357
HashSet<string> cloned = set.DeepClone();

DeepCloner.Core.Tests/ClrExceptionSpec.cs

Lines changed: 0 additions & 97 deletions
This file was deleted.

DeepCloner.Core.Tests/ConstructorsSpec.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void GetOrAdd_ParallelAccess_ShouldBeThreadSafe()
4646
{
4747
// Arrange
4848
int iterations = 1000;
49-
List<Task>? parallelTasks = new List<Task>();
49+
List<Task>? parallelTasks = [];
5050
ConcurrentDictionary<Type, string> typeCache = new ConcurrentDictionary<Type, string>();
5151

5252
// Act

DeepCloner.Core.Tests/CopyToObjectSpec.cs

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public void MultipleHashSetsAtSameLevelShouldBeClonedCorrectly()
104104
// Arrange
105105
HashSetContainer container = new HashSetContainer
106106
{
107-
Set1 = new HashSet<KeyClass>(),
108-
Set2 = new HashSet<KeyClass>(),
109-
Set3 = new HashSet<KeyClass>()
107+
Set1 = [],
108+
Set2 = [],
109+
Set3 = []
110110
};
111111

112112
KeyClass item1 = new KeyClass { Value = "Item1" };
@@ -211,7 +211,7 @@ public void NestedDictionariesShouldBeClonedCorrectly()
211211
public void SetBrokenAfterCloningTest()
212212
{
213213
// Arrange
214-
HashSet<KeyClass> originalSet = new HashSet<KeyClass>();
214+
HashSet<KeyClass> originalSet = [];
215215
KeyClass key = new KeyClass { Value = "TestKey" };
216216
originalSet.Add(key);
217217

@@ -229,6 +229,14 @@ public void SetBrokenAfterCloningTest()
229229
Assert.That(clonedKey.Value is "TestKey", Is.True);
230230
});
231231
}
232+
233+
[Test]
234+
public void CanCopyTypes()
235+
{
236+
Type original = typeof(string);
237+
Type result = original.DeepClone();
238+
Assert.That(original, Is.EqualTo(result));
239+
}
232240

233241
[Test]
234242
public void OrderedDictionaryBrokenAfterCloningTest()
@@ -307,14 +315,14 @@ public void SingleGenericDictionaryCloneTest()
307315
// Assert
308316
Assert.Multiple(() =>
309317
{
310-
Assert.That(ReferenceEquals(key, clonedKey), Is.False, "Klíč by měl být nová instance");
311-
Assert.That(key.Value, Is.EqualTo(clonedKey.Value), "Hodnota klíče by měla být zachována");
318+
Assert.That(ReferenceEquals(key, clonedKey), Is.False);
319+
Assert.That(key.Value, Is.EqualTo(clonedKey.Value));
312320

313-
Assert.That(originalDict.Count, Is.EqualTo(clonedDict.Count), "Počet položek by měl být stejný");
314-
Assert.That(clonedDict.Contains(clonedKvp), Is.True, "Naklonovaný slovník by měl obsahovat naklonovanou KeyValuePair");
321+
Assert.That(originalDict.Count, Is.EqualTo(clonedDict.Count));
322+
Assert.That(clonedDict.Contains(clonedKvp), Is.True);
315323

316-
Assert.That(clonedKey.Value, Is.EqualTo("TestKey"), "Hodnota klíče by měla být zachována");
317-
Assert.That(clonedKvp.Value, Is.EqualTo("TestValue"), "Hodnota by měla být zachována");
324+
Assert.That(clonedKey.Value, Is.EqualTo("TestKey"));
325+
Assert.That(clonedKvp.Value, Is.EqualTo("TestValue"));
318326
});
319327
}
320328

@@ -463,14 +471,12 @@ public void Descendant_Class_Should_Be_Cloned(bool isDeep)
463471
D = 42.3m
464472
};
465473

466-
C2 cToRef = cTo;
467-
468474
if (isDeep)
469475
cFrom.DeepCloneTo(cTo);
470476
else
471477
cFrom.ShallowCloneTo(cTo);
472478

473-
Assert.That(ReferenceEquals(cTo, cToRef), Is.True);
479+
Assert.That(ReferenceEquals(cTo, cTo), Is.True);
474480
Assert.That(cTo.A, Is.EqualTo(11));
475481
Assert.That(((C1)cTo).A, Is.EqualTo(12));
476482
Assert.That(cTo.D, Is.EqualTo(42.3m));
@@ -545,7 +551,7 @@ public void Struct_As_Interface_ShouldNot_Be_Cloned(bool isDeep)
545551
{
546552
S1 sFrom = new S1 { A = 42 };
547553
S1 sTo = new S1();
548-
I1? objTo = (I1)sTo;
554+
I1? objTo = sTo;
549555
objTo.A = 23;
550556
if (isDeep)
551557
// ReSharper disable once ExpressionIsAlwaysNull
@@ -568,8 +574,8 @@ public void String_Should_Not_Be_Cloned()
568574
[TestCase(true)]
569575
public void Array_Should_Be_Cloned_Correct_Size(bool isDeep)
570576
{
571-
int[] arrFrom = new[] { 1, 2, 3 };
572-
int[] arrTo = new[] { 4, 5, 6 };
577+
int[] arrFrom = [1, 2, 3];
578+
int[] arrTo = [4, 5, 6];
573579
if (isDeep) arrFrom.DeepCloneTo(arrTo);
574580
else arrFrom.ShallowCloneTo(arrTo);
575581
Assert.That(arrTo.Length, Is.EqualTo(3));
@@ -583,8 +589,8 @@ public void Array_Should_Be_Cloned_Correct_Size(bool isDeep)
583589
[TestCase(true)]
584590
public void Array_Should_Be_Cloned_From_Is_Bigger(bool isDeep)
585591
{
586-
int[] arrFrom = new[] { 1, 2, 3 };
587-
int[] arrTo = new[] { 4, 5 };
592+
int[] arrFrom = [1, 2, 3];
593+
int[] arrTo = [4, 5];
588594
if (isDeep) arrFrom.DeepCloneTo(arrTo);
589595
else arrFrom.ShallowCloneTo(arrTo);
590596
Assert.That(arrTo.Length, Is.EqualTo(2));
@@ -597,8 +603,8 @@ public void Array_Should_Be_Cloned_From_Is_Bigger(bool isDeep)
597603
[TestCase(true)]
598604
public void Array_Should_Be_Cloned_From_Is_Smaller(bool isDeep)
599605
{
600-
int[] arrFrom = new[] { 1, 2 };
601-
int[] arrTo = new[] { 4, 5, 6 };
606+
int[] arrFrom = [1, 2];
607+
int[] arrTo = [4, 5, 6];
602608
if (isDeep) arrFrom.DeepCloneTo(arrTo);
603609
else arrFrom.ShallowCloneTo(arrTo);
604610
Assert.That(arrTo.Length, Is.EqualTo(3));
@@ -611,7 +617,7 @@ public void Array_Should_Be_Cloned_From_Is_Smaller(bool isDeep)
611617
public void Shallow_Array_Should_Be_Cloned()
612618
{
613619
C1 c1 = new C1();
614-
C1[] arrFrom = new[] { c1, c1, c1 };
620+
C1[] arrFrom = [c1, c1, c1];
615621
C1[] arrTo = new C1[4];
616622
arrFrom.ShallowCloneTo(arrTo);
617623
Assert.That(arrTo.Length, Is.EqualTo(4));
@@ -626,7 +632,7 @@ public void Deep_Array_Should_Be_Cloned()
626632
{
627633
C4 c1 = new C4();
628634
C3 c3 = new C3 { A = c1, B = c1 };
629-
C3[] arrFrom = new[] { c3, c3, c3 };
635+
C3[] arrFrom = [c3, c3, c3];
630636
C3[] arrTo = new C3[4];
631637
arrFrom.DeepCloneTo(arrTo);
632638
Assert.That(arrTo.Length, Is.EqualTo(4));
@@ -686,7 +692,7 @@ public void MultiDim_Array_Should_Be_Cloned(bool isDeep)
686692
[TestCase(true)]
687693
public void TwoDim_Array_Should_Be_Cloned(bool isDeep)
688694
{
689-
int[,] arrFrom = new[,] { { 1, 2 }, { 3, 4 } };
695+
int[,] arrFrom = { { 1, 2 }, { 3, 4 } };
690696
// with offset. its ok
691697
int[,] arrTo = new int[3, 1];
692698
if (isDeep) arrFrom.DeepCloneTo(arrTo);
@@ -741,7 +747,7 @@ public void MultiDimensional_Array_Should_Be_Cloned()
741747
public void Shallow_Clone_Of_MultiDim_Array_Should_Not_Perform_Deep()
742748
{
743749
C1 c1 = new C1();
744-
C1[,] arrFrom = new[,] { { c1, c1 }, { c1, c1 } };
750+
C1[,] arrFrom = { { c1, c1 }, { c1, c1 } };
745751
// with offset. its ok
746752
C1[,] arrTo = new C1[3, 1];
747753
arrFrom.ShallowCloneTo(arrTo);
@@ -759,7 +765,7 @@ public void Shallow_Clone_Of_MultiDim_Array_Should_Not_Perform_Deep()
759765
public void Deep_Clone_Of_MultiDim_Array_Should_Perform_Deep()
760766
{
761767
C1 c1 = new C1();
762-
C1[,] arrFrom = new[,] { { c1, c1 }, { c1, c1 } };
768+
C1[,] arrFrom = { { c1, c1 }, { c1, c1 } };
763769
// with offset. its ok
764770
C1[,] arrTo = new C1[3, 1];
765771
arrFrom.DeepCloneTo(arrTo);

DeepCloner.Core.Tests/InheritanceSpec.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void Descendant_In_Array_Should_Be_Cloned()
158158
{
159159
C1? c1 = new C1();
160160
C2? c2 = new C2();
161-
C1[]? arr = new[] { c1, c2 };
161+
C1[]? arr = [c1, c2];
162162

163163
C1[]? cloned = arr.DeepClone();
164164
Assert.That(cloned[0], Is.TypeOf<C1>());
@@ -222,7 +222,7 @@ public void Struct_Casted_To_Interface_With_Class_As_Interface_Should_Be_Cloned(
222222
public void Array_Of_Struct_Casted_To_Interface_Should_Be_Cloned()
223223
{
224224
S1 s1 = new S1();
225-
IDisposable[]? arr = new IDisposable[] { s1, s1 };
225+
IDisposable[]? arr = [s1, s1];
226226
IDisposable[]? clonedArr = arr.DeepClone();
227227
Assert.That(clonedArr[0], Is.EqualTo(clonedArr[1]));
228228
}

0 commit comments

Comments
 (0)