Skip to content

Commit b925dc6

Browse files
committed
FileCodeFix Tests
1 parent 34b9e78 commit b925dc6

5 files changed

Lines changed: 71 additions & 2 deletions

File tree

System.IO.Abstractions.Analyzers.Tests/Analyzers/FileAnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Analyzer_is_triggered(string filename, int diagnosticLine, int diagn
2525

2626
var expectedDiagnostic = new DiagnosticResult
2727
{
28-
Id = FileAnalyzer.DiagnosticId,
28+
Id = Constants.Io0002,
2929
Message = FileAnalyzer.MessageFormat,
3030
Severity = DiagnosticSeverity.Warning,
3131
Locations = new[] { new DiagnosticResultLocation("Test0.cs", diagnosticLine, diagnosticColumn) }

System.IO.Abstractions.Analyzers.Tests/Analyzers/FileServiceInterfaceInjectionAnalyzerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void Analyzer_is_triggered(string filename, int diagnosticLine, int diagn
2525

2626
var expectedDiagnostic = new DiagnosticResult
2727
{
28-
Id = FileServiceInterfaceInjectionAnalyzer.DiagnosticId,
28+
Id = Constants.Io0001,
2929
Message = FileServiceInterfaceInjectionAnalyzer.MessageFormat,
3030
Severity = DiagnosticSeverity.Warning,
3131
Locations = new[] { new DiagnosticResultLocation("Test0.cs", diagnosticLine, diagnosticColumn) }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections.Generic;
2+
using System.IO.Abstractions.Analyzers.Analyzers.FileSystemTypeAnalyzers;
3+
using System.IO.Abstractions.Analyzers.CodeFixes;
4+
using Microsoft.CodeAnalysis;
5+
using Roslyn.Testing.CodeFix;
6+
using Xunit;
7+
8+
namespace System.IO.Abstractions.Analyzers.Tests.CodeFixes
9+
{
10+
public class FileCodeFixTests :
11+
CSharpCodeFixProviderTest<FileAnalyzer, FileCodeFix>
12+
{
13+
[Theory]
14+
[InlineData("BeforeFix.txt", "AfterFix.txt")]
15+
public void CodeFix(string sourceBefore, string sourceAfter)
16+
{
17+
var sourceBeforeFix = ReadFile(sourceBefore);
18+
var sourceAfterFix = ReadFile(sourceAfter);
19+
VerifyFix(sourceBeforeFix, sourceAfterFix, 0, true);
20+
}
21+
22+
protected override IEnumerable<MetadataReference> GetAdditionalReferences() => new[]
23+
{
24+
MetadataReference.CreateFromFile(typeof(IFileSystem).Assembly.Location)
25+
};
26+
}
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO.Abstractions;
2+
3+
namespace SomeNameSpace
4+
{
5+
public class WithOutFileSystem
6+
{
7+
private readonly IFileSystem _fileSystem;
8+
9+
public WithOutFileSystem(IFileSystem fileSystem)
10+
{
11+
_fileSystem = fileSystem;
12+
}
13+
14+
public void SomeMethod()
15+
{
16+
const string filePath = "C:\\temp.txt";
17+
18+
_fileSystem.File.Delete(filePath);
19+
}
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO.Abstractions;
2+
3+
namespace SomeNameSpace
4+
{
5+
public class WithOutFileSystem
6+
{
7+
private readonly IFileSystem _fileSystem;
8+
9+
public WithOutFileSystem(IFileSystem fileSystem)
10+
{
11+
_fileSystem = fileSystem;
12+
}
13+
14+
public void SomeMethod()
15+
{
16+
const string filePath = "C:\\temp.txt";
17+
18+
File.Delete(filePath);
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)