Skip to content

Commit 82dbc33

Browse files
committed
Add StyleCop.Analyzers
1 parent 5f8e6bb commit 82dbc33

File tree

11 files changed

+472
-344
lines changed

11 files changed

+472
-344
lines changed

FollowingFileStream.ConsoleTestTool/FollowingFileStream.ConsoleTestTool.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,19 @@
99
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
1010
<LangVersion>7.1</LangVersion>
1111
<IsPackable>false</IsPackable>
12+
<noWarn>SA0001</noWarn>
1213
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.5" PrivateAssets="All"/>
17+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All"/>
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Include="../LICENSE"/>
22+
<AdditionalFiles Include="$(MSBuildThisFileDirectory)..\stylecop.json">
23+
<Link>stylecop.json</Link>
24+
</AdditionalFiles>
25+
</ItemGroup>
26+
1327
</Project>
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
using System;
2-
using System.IO;
3-
using System.Threading.Tasks;
1+
// --------------------------------------------------------------------------------------------------
2+
// <copyright file="Program.cs" company="Manandre">
3+
// Copyright (c) Manandre. All rights reserved.
4+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
// </copyright>
6+
// --------------------------------------------------------------------------------------------------
47

58
namespace Manandre.IO
69
{
7-
static class Program
10+
using System;
11+
using System.IO;
12+
using System.Threading.Tasks;
13+
14+
internal static class Program
815
{
916
private const string InputPath = "source.txt";
1017
private const string OutputPath = "destination.txt";
1118

12-
static async Task Main()
19+
public static async Task Main()
1320
{
1421
var input = WriteInput().ConfigureAwait(false);
1522
await CopyToOutput().ConfigureAwait(false);
@@ -21,9 +28,10 @@ private static async Task WriteInput()
2128
using (var sw = new StreamWriter(new FileStream(InputPath, FileMode.Create, FileAccess.Write, FileShare.Read)))
2229
using (var sr = new StreamReader(Console.OpenStandardInput()))
2330
{
24-
await sr.CopyToAsync(sw, stopOn:"quit").ConfigureAwait(false);
31+
await sr.CopyToAsync(sw, stopOn: "quit").ConfigureAwait(false);
2532
}
2633
}
34+
2735
private static async Task CopyToOutput()
2836
{
2937
using (var source = new FollowingFileStream(InputPath))
@@ -33,17 +41,4 @@ private static async Task CopyToOutput()
3341
}
3442
}
3543
}
36-
37-
static class TextReaderExtensions
38-
{
39-
public static async Task CopyToAsync(this TextReader reader, TextWriter writer, string stopOn)
40-
{
41-
string line = string.Empty;
42-
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != stopOn)
43-
{
44-
await writer.WriteLineAsync(line).ConfigureAwait(false);
45-
await writer.FlushAsync().ConfigureAwait(false);
46-
}
47-
}
48-
}
49-
}
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// --------------------------------------------------------------------------------------------------
2+
// <copyright file="TextReaderExtensions.cs" company="Manandre">
3+
// Copyright (c) Manandre. All rights reserved.
4+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
// </copyright>
6+
// --------------------------------------------------------------------------------------------------
7+
8+
namespace Manandre.IO
9+
{
10+
using System.IO;
11+
using System.Threading.Tasks;
12+
13+
internal static class TextReaderExtensions
14+
{
15+
public static async Task CopyToAsync(this TextReader reader, TextWriter writer, string stopOn)
16+
{
17+
string line = string.Empty;
18+
while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != stopOn)
19+
{
20+
await writer.WriteLineAsync(line).ConfigureAwait(false);
21+
await writer.FlushAsync().ConfigureAwait(false);
22+
}
23+
}
24+
}
25+
}

FollowingFileStream.Tests/AsyncStreamTest.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using Moq;
3-
using System;
4-
using System.IO;
5-
using System.Linq.Expressions;
6-
using System.Threading;
1+
// --------------------------------------------------------------------------------------------------
2+
// <copyright file="AsyncStreamTest.cs" company="Manandre">
3+
// Copyright (c) Manandre. All rights reserved.
4+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
5+
// </copyright>
6+
// --------------------------------------------------------------------------------------------------
77

88
namespace Manandre.IO
99
{
10+
using System;
11+
using System.IO;
12+
using System.Linq.Expressions;
13+
using System.Threading;
14+
using Microsoft.VisualStudio.TestTools.UnitTesting;
15+
using Moq;
16+
1017
[TestClass]
1118
public class AsyncStreamTest
1219
{
1320
[TestMethod]
14-
public void AS_Read()
21+
public void ASRead()
1522
{
1623
var sut = new Mock<AsyncStream>() { CallBase = true };
1724
var expected = 42;
@@ -25,7 +32,7 @@ public void AS_Read()
2532
}
2633

2734
[TestMethod]
28-
public void AS_Write()
35+
public void ASWrite()
2936
{
3037
var sut = new Mock<AsyncStream>() { CallBase = true };
3138
sut.Setup(x => x.WriteAsync(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
@@ -38,7 +45,7 @@ public void AS_Write()
3845
}
3946

4047
[TestMethod]
41-
public void AS_Flush()
48+
public void ASFlush()
4249
{
4350
var sut = new Mock<AsyncStream>() { CallBase = true };
4451
sut.Setup(x => x.FlushAsync(It.IsAny<CancellationToken>())).Verifiable();
@@ -47,15 +54,15 @@ public void AS_Flush()
4754
}
4855

4956
[TestMethod]
50-
public void AS_Dispose()
57+
public void ASDispose()
5158
{
5259
var sut = new Mock<AsyncStream>() { CallBase = true };
5360
sut.Object.Dispose();
5461
sut.Object.Dispose();
5562
}
5663

5764
[TestMethod]
58-
public void AS_Synchronized()
65+
public void ASSynchronized()
5966
{
6067
Assert.ThrowsException<ArgumentNullException>(() => AsyncStream.Synchronized(null));
6168
var sut = new Mock<AsyncStream>() { CallBase = true };
@@ -69,7 +76,7 @@ public void AS_Synchronized()
6976
x => x.CanRead,
7077
x => x.CanWrite,
7178
x => x.CanSeek,
72-
x => x.CanTimeout
79+
x => x.CanTimeout,
7380
};
7481
foreach (var func in funcs)
7582
{

FollowingFileStream.Tests/FollowingFileStream.Tests.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netcoreapp3.0;netcoreapp2.2</TargetFrameworks>
44
<IsPackable>false</IsPackable>
5+
<noWarn>SA0001</noWarn>
56
</PropertyGroup>
67
<ItemGroup>
78
<PackageReference Include="coverlet.msbuild" Version="2.6.3">
@@ -12,8 +13,16 @@
1213
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0"/>
1314
<PackageReference Include="MSTest.TestFramework" Version="1.4.0"/>
1415
<PackageReference Include="Moq" Version="4.12.0"/>
16+
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.5" PrivateAssets="All"/>
17+
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All"/>
1518
</ItemGroup>
1619
<ItemGroup>
1720
<ProjectReference Include="..\FollowingFileStream\FollowingFileStream.csproj"/>
1821
</ItemGroup>
22+
<ItemGroup>
23+
<None Include="../LICENSE"/>
24+
<AdditionalFiles Include="$(MSBuildThisFileDirectory)..\stylecop.json">
25+
<Link>stylecop.json</Link>
26+
</AdditionalFiles>
27+
</ItemGroup>
1928
</Project>

0 commit comments

Comments
 (0)