From 88be53d1be0955d68729fe1e3827d35320bb8b80 Mon Sep 17 00:00:00 2001 From: Jonathan Magnan Date: Sat, 12 Jan 2019 13:07:04 -0500 Subject: [PATCH] Add unit test for FileInfo.CountLines() --- .../System.IO.FileInfo/FileInfo.CountLines.cs | 41 +++++++++++++++++++ test/Z.IO.Test/Z.IO.Test.csproj | 1 + 2 files changed, 42 insertions(+) create mode 100644 test/Z.IO.Test/System.IO.FileInfo/FileInfo.CountLines.cs diff --git a/test/Z.IO.Test/System.IO.FileInfo/FileInfo.CountLines.cs b/test/Z.IO.Test/System.IO.FileInfo/FileInfo.CountLines.cs new file mode 100644 index 00000000..510eaa8d --- /dev/null +++ b/test/Z.IO.Test/System.IO.FileInfo/FileInfo.CountLines.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/test/Z.IO.Test/Z.IO.Test.csproj b/test/Z.IO.Test/Z.IO.Test.csproj index 32275632..da4e1a8f 100644 --- a/test/Z.IO.Test/Z.IO.Test.csproj +++ b/test/Z.IO.Test/Z.IO.Test.csproj @@ -86,6 +86,7 @@ +