Skip to content

Commit 770c152

Browse files
committed
More tests.
1 parent 5f6cbbe commit 770c152

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

IDisposableAnalyzers.Test/IDISP003DisposeBeforeReassigningTests/Valid.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,5 +1455,44 @@ public class Winform : Form
14551455
}".AssertReplace("this.components.Add(this.stream)", expression);
14561456
RoslynAssert.NoAnalyzerDiagnostics(Analyzer, code);
14571457
}
1458+
1459+
[Test]
1460+
public static void TwoConstructors()
1461+
{
1462+
var code = @"
1463+
namespace N
1464+
{
1465+
using System;
1466+
1467+
public sealed class C : IDisposable
1468+
{
1469+
private readonly IDisposable disposable;
1470+
private bool disposed;
1471+
1472+
public C(int _)
1473+
{
1474+
this.disposable = new Disposable();
1475+
}
1476+
1477+
public C(string _)
1478+
{
1479+
this.disposable = new Disposable();
1480+
}
1481+
1482+
public void Dispose()
1483+
{
1484+
if (this.disposed)
1485+
{
1486+
return;
1487+
}
1488+
1489+
this.disposed = true;
1490+
this.disposable?.Dispose();
1491+
}
1492+
}
1493+
}";
1494+
1495+
RoslynAssert.Valid(Analyzer, DisposableCode, code);
1496+
}
14581497
}
14591498
}

ValidCode/Constructors/Chained.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// ReSharper disable All
2-
namespace N
1+
namespace ValidCode.Constructors
32
{
43
using System;
54

ValidCode/Constructors/Two.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace ValidCode.Constructors
2+
{
3+
using System;
4+
5+
public sealed class Two : IDisposable
6+
{
7+
private readonly IDisposable disposable;
8+
private bool disposed;
9+
10+
public Two(int _)
11+
{
12+
this.disposable = new Disposable();
13+
}
14+
15+
public Two(string _)
16+
{
17+
this.disposable = new Disposable();
18+
}
19+
20+
public void Dispose()
21+
{
22+
if (this.disposed)
23+
{
24+
return;
25+
}
26+
27+
this.disposed = true;
28+
this.disposable?.Dispose();
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)