Skip to content

Commit 88be53d

Browse files
Add unit test for FileInfo.CountLines()
1 parent d4c4653 commit 88be53d

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET
2+
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
3+
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
4+
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
5+
// More projects: http://www.zzzprojects.com/
6+
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
7+
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
10+
using System.Linq;
11+
using System.Text;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
13+
14+
namespace Z.IO.Test
15+
{
16+
[TestClass]
17+
public class System_IO_FileInfo_CountLines
18+
{
19+
[TestMethod]
20+
public void CountLines()
21+
{
22+
// Type
23+
var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadAllLines.txt"));
24+
25+
// Intialization
26+
using (FileStream stream = @this.Create())
27+
{
28+
byte[] byteToWrites = Encoding.Default.GetBytes("Fizz" + Environment.NewLine + "Buzz" + Environment.NewLine + "Fizz2");
29+
stream.Write(byteToWrites, 0, byteToWrites.Length);
30+
}
31+
32+
// Examples
33+
var result1 = @this.CountLines(); // return 3;
34+
var result2 = @this.CountLines(x => !x.Contains("Buzz")); // return 2;
35+
36+
// Unit Test
37+
Assert.AreEqual(3, result1);
38+
Assert.AreEqual(2, result2);
39+
}
40+
}
41+
}

test/Z.IO.Test/Z.IO.Test.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<Compile Include="System.IO.FileInfo\FileInfo.GetDirectoryFullName.cs" />
8787
<Compile Include="System.IO.FileInfo\FileInfo.GetDirectoryName.cs" />
8888
<Compile Include="System.IO.FileInfo\FileInfo.GetFileNameWithoutExtension.cs" />
89+
<Compile Include="System.IO.FileInfo\FileInfo.CountLines.cs" />
8990
<Compile Include="System.IO.FileInfo\FileInfo.GetPathRoot.cs" />
9091
<Compile Include="System.IO.FileInfo\FileInfo.HasExtension.cs" />
9192
<Compile Include="System.IO.FileInfo\FileInfo.IsPathRooted.cs" />

0 commit comments

Comments
 (0)