瀏覽代碼

Added ProcessFileNotExistTest

Piotr Czajkowski 5 月之前
父節點
當前提交
d52e5dcec6
共有 2 個文件被更改,包括 31 次插入1 次删除
  1. 2 1
      ProcessFilesTests/ProcessFilesTests.csproj
  2. 29 0
      ProcessFilesTests/ProcessFiles_UnitTests.cs

+ 2 - 1
ProcessFilesTests/ProcessFilesTests.csproj

@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFramework>net8.0</TargetFramework>
@@ -24,6 +24,7 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
+    <PackageReference Include="NSubstitute" Version="5.1.0" />
     <PackageReference Include="xunit" Version="2.9.2" />
     <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
       <PrivateAssets>all</PrivateAssets>

+ 29 - 0
ProcessFilesTests/ProcessFiles_UnitTests.cs

@@ -0,0 +1,29 @@
+using NSubstitute;
+using ProcessFiles.Interfaces;
+using Xunit;
+
+namespace ProcessFilesTests
+{
+    public class ProcessFiles_UnitTests
+    {
+        [Fact]
+        public void ProcessFileNotExistTest()
+        {
+            var result = string.Empty;
+            void TestAction(string value)
+            {
+                result = value;
+            }
+
+            var fakeFileSystem = Substitute.For<IFileSystem>();
+            fakeFileSystem.File.Exists(Arg.Any<string>()).Returns(false);
+
+            var test = new ProcessFiles.ProcessFiles(fakeFileSystem);
+            var errors = test.Process(["./imaginaryFolder/imaginaryTest.txt"], "txt", TestAction);
+            Assert.NotEmpty(errors);
+            Assert.Empty(result);
+
+            fakeFileSystem.File.Received().Exists(Arg.Any<string>());
+        }
+    }
+}