22
33namespace CodeLineCounter . Tests
44{
5- public class CodeDuplicationCheckerTests
5+ public class CodeDuplicationCheckerTests : IDisposable
66 {
7+ private readonly string _testDirectory ;
8+ private bool _disposed ;
9+
10+ public CodeDuplicationCheckerTests ( )
11+ {
12+ _testDirectory = Path . Combine ( Path . GetTempPath ( ) , "CodeDuplicationCheckerTests" ) ;
13+ Directory . CreateDirectory ( _testDirectory ) ;
14+ }
15+
716 [ Fact ]
817 public void DetectCodeDuplicationInFiles_ShouldDetectDuplicates ( )
918 {
1019 // Arrange
11- var file1 = "TestFile1.cs" ;
12- var file2 = "TestFile2.cs" ;
20+ var file1 = Path . Combine ( _testDirectory , "TestFile1.cs" ) ;
21+ var file2 = Path . Combine ( _testDirectory , "TestFile2.cs" ) ;
1322
1423 var code1 = @"
1524 public class TestClass
@@ -85,8 +94,8 @@ public void AnotherTestMethod()
8594 }
8695 }" ;
8796
88- var file1 = "TestFile3.cs" ;
89- var file2 = "TestFile4.cs" ;
97+ var file1 = Path . Combine ( _testDirectory , "TestFile3.cs" ) ;
98+ var file2 = Path . Combine ( _testDirectory , "TestFile4.cs" ) ;
9099
91100 // Act
92101 checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
@@ -126,8 +135,8 @@ public void AnotherTestMethod()
126135 }
127136 }" ;
128137
129- var file1 = "TestFile5.cs" ;
130- var file2 = "TestFile6.cs" ;
138+ var file1 = Path . Combine ( _testDirectory , "TestFile5.cs" ) ;
139+ var file2 = Path . Combine ( _testDirectory , "TestFile6.cs" ) ;
131140
132141 // Act
133142 checker . DetectCodeDuplicationInSourceCode ( file1 , sourceCode1 ) ;
@@ -137,5 +146,32 @@ public void AnotherTestMethod()
137146 // Assert
138147 Assert . Empty ( result ) ; // No duplicates should be detected
139148 }
149+
150+ protected virtual void Dispose ( bool disposing )
151+ {
152+ if ( ! _disposed )
153+ {
154+ if ( disposing && Directory . Exists ( _testDirectory ) )
155+ {
156+ // Dispose managed resources
157+ Directory . Delete ( _testDirectory , true ) ;
158+ }
159+
160+ // Dispose unmanaged resources (if any)
161+
162+ _disposed = true ;
163+ }
164+ }
165+
166+ public void Dispose ( )
167+ {
168+ Dispose ( true ) ;
169+ GC . SuppressFinalize ( this ) ;
170+ }
171+
172+ ~ CodeDuplicationCheckerTests ( )
173+ {
174+ Dispose ( false ) ;
175+ }
140176 }
141177}
0 commit comments