22
33namespace CodeLineCounter . Tests
44{
5- public class CodeDuplicationCheckerTests : IDisposable
5+ public class CodeDuplicationCheckerTests : IDisposable
66 {
77 private readonly string _testDirectory ;
88 private bool _disposed ;
@@ -12,13 +12,13 @@ public CodeDuplicationCheckerTests()
1212 _testDirectory = Path . Combine ( Path . GetTempPath ( ) , "CodeDuplicationCheckerTests" ) ;
1313 Directory . CreateDirectory ( _testDirectory ) ;
1414 }
15-
15+
1616 [ Fact ]
1717 public void DetectCodeDuplicationInFiles_ShouldDetectDuplicates ( )
1818 {
1919 using StringWriter consoleOutput = new ( ) ;
2020 Console . SetOut ( consoleOutput ) ;
21-
21+
2222 // Arrange
2323 var file1 = Path . Combine ( _testDirectory , "TestFile1.cs" ) ;
2424 var file2 = Path . Combine ( _testDirectory , "TestFile2.cs" ) ;
@@ -70,13 +70,14 @@ public void AnotherTestMethod()
7070 [ Fact ]
7171 public void DetectCodeDuplicationInSourceCode_ShouldDetectDuplicates ( )
7272 {
73- using StringWriter consoleOutput = new ( ) ;
74- Console . SetOut ( consoleOutput ) ;
73+ using ( StringWriter consoleOutput = new ( ) )
74+ {
75+ Console . SetOut ( consoleOutput ) ;
7576
76- // Arrange
77- var checker = new CodeDuplicationChecker ( ) ;
77+ // Arrange
78+ var checker = new CodeDuplicationChecker ( ) ;
7879
79- var sourceCode1 = @"
80+ var sourceCode1 = @"
8081 public class TestClass
8182 {
8283 public void TestMethod()
@@ -88,7 +89,7 @@ public void TestMethod()
8889 }
8990 }" ;
9091
91- var sourceCode2 = @"
92+ var sourceCode2 = @"
9293 public class AnotherTestClass
9394 {
9495 public void AnotherTestMethod()
@@ -100,30 +101,33 @@ public void AnotherTestMethod()
100101 }
101102 }" ;
102103
103- var file1 = Path . Combine ( _testDirectory , "TestFile3.cs" ) ;
104- var file2 = Path . Combine ( _testDirectory , "TestFile4.cs" ) ;
104+ var file1 = Path . Combine ( _testDirectory , "TestFile3.cs" ) ;
105+ var file2 = Path . Combine ( _testDirectory , "TestFile4.cs" ) ;
105106
106- // Act
107- checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
108- checker . DetectCodeDuplicationInSourceCode ( file2 , sourceCode2 ) ;
109- var result = checker . GetCodeDuplicationMap ( ) ;
107+ // Act
108+ checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
109+ checker . DetectCodeDuplicationInSourceCode ( file2 , sourceCode2 ) ;
110+ var result = checker . GetCodeDuplicationMap ( ) ;
111+
112+ // Assert
113+ Assert . NotEmpty ( result ) ;
114+ var duplicateEntry = result . First ( ) ;
115+ Assert . Equal ( 2 , duplicateEntry . Value . Count ) ; // Both methods should be detected as duplicates
116+ }
110117
111- // Assert
112- Assert . NotEmpty ( result ) ;
113- var duplicateEntry = result . First ( ) ;
114- Assert . Equal ( 2 , duplicateEntry . Value . Count ) ; // Both methods should be detected as duplicates
115118 }
116119
117120 [ Fact ]
118121 public void DetectCodeDuplicationInSourceCode_ShouldNotDetectDuplicatesForDifferentCode ( )
119122 {
120- using StringWriter consoleOutput = new ( ) ;
121- Console . SetOut ( consoleOutput ) ;
123+ using ( StringWriter consoleOutput = new ( ) )
124+ {
125+ Console . SetOut ( consoleOutput ) ;
122126
123- // Arrange
124- var checker = new CodeDuplicationChecker ( ) ;
127+ // Arrange
128+ var checker = new CodeDuplicationChecker ( ) ;
125129
126- var sourceCode1 = @"
130+ var sourceCode1 = @"
127131 public class TestClass
128132 {
129133 public void TestMethod()
@@ -135,7 +139,7 @@ public void TestMethod()
135139 }
136140 }" ;
137141
138- var sourceCode2 = @"
142+ var sourceCode2 = @"
139143 public class AnotherTestClass
140144 {
141145 public void AnotherTestMethod()
@@ -144,19 +148,21 @@ public void AnotherTestMethod()
144148 }
145149 }" ;
146150
147- var file1 = Path . Combine ( _testDirectory , "TestFile5.cs" ) ;
148- var file2 = Path . Combine ( _testDirectory , "TestFile6.cs" ) ;
151+ var file1 = Path . Combine ( _testDirectory , "TestFile5.cs" ) ;
152+ var file2 = Path . Combine ( _testDirectory , "TestFile6.cs" ) ;
149153
150- // Act
151- checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
152- checker . DetectCodeDuplicationInSourceCode ( file2 , sourceCode2 ) ;
153- var result = checker . GetCodeDuplicationMap ( ) ;
154+ // Act
155+ checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
156+ checker . DetectCodeDuplicationInSourceCode ( file2 , sourceCode2 ) ;
157+ var result = checker . GetCodeDuplicationMap ( ) ;
158+
159+ // Assert
160+ Assert . Empty ( result ) ; // No duplicates should be detected
161+ }
154162
155- // Assert
156- Assert . Empty ( result ) ; // No duplicates should be detected
157163 }
158164
159- protected virtual void Dispose ( bool disposing )
165+ protected virtual void Dispose ( bool disposing )
160166 {
161167 if ( ! _disposed )
162168 {
0 commit comments