Skip to content

Commit 0cc9327

Browse files
committed
More tests.
1 parent 561e489 commit 0cc9327

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

IDisposableAnalyzers.Test/IDISP003DisposeBeforeReassigningTests/Valid.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public Stream Stream
332332
}
333333

334334
[Test]
335-
public static void AssigningFieldInCtor()
335+
public static void FieldAssignedInCtor()
336336
{
337337
var code = @"
338338
namespace N
@@ -353,6 +353,31 @@ public C()
353353
RoslynAssert.Valid(Analyzer, code);
354354
}
355355

356+
[Test]
357+
public static void FieldAssignDisposeAssignInCtor()
358+
{
359+
var code = @"
360+
namespace N
361+
{
362+
using System;
363+
using System.IO;
364+
365+
public class C
366+
{
367+
private readonly Stream stream;
368+
369+
public C()
370+
{
371+
this.stream = File.OpenRead(string.Empty);
372+
this.stream.Dispose();
373+
this.stream = File.OpenRead(string.Empty);
374+
}
375+
}
376+
}";
377+
378+
RoslynAssert.Valid(Analyzer, code);
379+
}
380+
356381
[Test]
357382
public static void FieldSwapCached()
358383
{

IDisposableAnalyzers.Test/IDISP004DoNotIgnoreCreatedTests/NoFix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Microsoft.CodeAnalysis.Diagnostics;
66
using NUnit.Framework;
77

8-
public static partial class NoFix
8+
public static class NoFix
99
{
1010
private static readonly DiagnosticAnalyzer Analyzer = new CreationAnalyzer();
1111
private static readonly CodeFixProvider AddUsingFix = new AddUsingFix();

ValidCode/LeaveOpen/LeaveOpenLocals.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
1+
// ReSharper disable All
12
namespace ValidCode.LeaveOpen
23
{
34
using System.IO;
45
using System.Text;
56

67
public class LeaveOpenLocals
78
{
8-
public LeaveOpenLocals(string fileName)
9+
public static void UsingDeclarations(string fileName)
10+
{
11+
using var stream = File.OpenRead(fileName);
12+
using var reader = new StreamReader(stream, new UTF8Encoding(), true, 1024, leaveOpen: true);
13+
_ = reader.ReadLine();
14+
_ = stream.ReadByte();
15+
}
16+
17+
public static void UsingStatements(string fileName)
918
{
1019
using (var stream = File.OpenRead(fileName))
1120
{

0 commit comments

Comments
 (0)