Skip to content

Commit

Permalink
Add unit test for FileInfo.CountLines()
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMagnan committed Jan 12, 2019
1 parent d4c4653 commit 88be53d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/Z.IO.Test/System.IO.FileInfo/FileInfo.CountLines.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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
// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods
// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues
// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE
// More projects: http://www.zzzprojects.com/
// Copyright © ZZZ Projects Inc. 2014 - 2016. All rights reserved.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Z.IO.Test
{
[TestClass]
public class System_IO_FileInfo_CountLines
{
[TestMethod]
public void CountLines()
{
// Type
var @this = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Examples_System_IO_FileInfo_ReadAllLines.txt"));

// Intialization
using (FileStream stream = @this.Create())
{
byte[] byteToWrites = Encoding.Default.GetBytes("Fizz" + Environment.NewLine + "Buzz" + Environment.NewLine + "Fizz2");
stream.Write(byteToWrites, 0, byteToWrites.Length);
}

// Examples
var result1 = @this.CountLines(); // return 3;
var result2 = @this.CountLines(x => !x.Contains("Buzz")); // return 2;

// Unit Test
Assert.AreEqual(3, result1);
Assert.AreEqual(2, result2);
}
}
}
1 change: 1 addition & 0 deletions test/Z.IO.Test/Z.IO.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<Compile Include="System.IO.FileInfo\FileInfo.GetDirectoryFullName.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.GetDirectoryName.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.GetFileNameWithoutExtension.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.CountLines.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.GetPathRoot.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.HasExtension.cs" />
<Compile Include="System.IO.FileInfo\FileInfo.IsPathRooted.cs" />
Expand Down

0 comments on commit 88be53d

Please sign in to comment.