commit cbf3b0c6f3564e7edf3e23519fe6732187a9179e
Author: Pultak <pultak5@gmail.com>
Date:   Mon Apr 25 23:55:54 2022 +0200

    re #9443 Added implementation of InfoFetcher tests

diff --git a/ld_client/LDClientTests/LDClientTests.csproj b/ld_client/LDClientTests/LDClientTests.csproj
index 5085235..6ba14ca 100644
--- a/ld_client/LDClientTests/LDClientTests.csproj
+++ b/ld_client/LDClientTests/LDClientTests.csproj
@@ -9,9 +9,14 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
+    <PackageReference Include="Moq" Version="4.17.2" />
     <PackageReference Include="NUnit" Version="3.13.2" />
     <PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
     <PackageReference Include="coverlet.collector" Version="3.1.0" />
   </ItemGroup>
 
+  <ItemGroup>
+    <ProjectReference Include="..\LDClient\LDClient.csproj" />
+  </ItemGroup>
+
 </Project>
diff --git a/ld_client/LDClientTests/UnitTest1.cs b/ld_client/LDClientTests/UnitTest1.cs
deleted file mode 100644
index 03cf433..0000000
--- a/ld_client/LDClientTests/UnitTest1.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using NUnit.Framework;
-
-namespace LDClientTests {
-    public class Tests {
-        [SetUp]
-        public void Setup() {
-
-        }
-
-        [Test]
-        public void Test1() {
-            Assert.Pass();
-        }
-    }
-}
\ No newline at end of file
diff --git a/ld_client/LDClientTests/detection/DebuggerInfoParserTests.cs b/ld_client/LDClientTests/detection/DebuggerInfoParserTests.cs
index 6f6fa52..e6fa016 100644
--- a/ld_client/LDClientTests/detection/DebuggerInfoParserTests.cs
+++ b/ld_client/LDClientTests/detection/DebuggerInfoParserTests.cs
@@ -2,65 +2,65 @@
 using LDClient.detection;
 using NUnit.Framework;
 
-namespace LDClientTests.detection {
-    public class DebuggerInfoParserTests {
+namespace LDClientTests.detection; 
 
-        public static readonly string CorrectFileContent =
-            "B::version.hardware \r\n\r\n" +
-            "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
-            "   Serial Number: C12345678912 \r\n\r\n" +
-            "   Firmware R.2021.02 (136263) \r\n\r\n" +
-            "   Instance: 1. \r\n\r\n" +
-            "   Automotive Debug Cable \r\n\r\n" +
-            "      Serial Number: C98765432198 ";
+public class DebuggerInfoParserTests {
 
-        public static readonly string HeadSerialNumber = "C98765432198";
-        public static readonly string BodySerialNumber = "C12345678912";
+    public static readonly string CorrectFileContent =
+        "B::version.hardware \r\n\r\n" +
+        "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
+        "   Serial Number: C12345678912 \r\n\r\n" +
+        "   Firmware R.2021.02 (136263) \r\n\r\n" +
+        "   Instance: 1. \r\n\r\n" +
+        "   Automotive Debug Cable \r\n\r\n" +
+        "      Serial Number: C98765432198 ";
 
+    public static readonly string HeadSerialNumber = "C98765432198";
+    public static readonly string BodySerialNumber = "C12345678912";
 
-        [Test]
-        [TestCase("B::version.hardware \r\n\r\n" +
-                  "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
-                  "   Serial Number: C12345678912 \r\n\r\n" +
-                  "   Firmware R.2021.02 (136263) \r\n\r\n" +
-                  "   Instance: 1. \r\n\r\n" +
-                  "   Automotive Debug Cable \r\n\r\n" +
-                  "      Serial Number: C12345678912 ", "C12345678912", "C12345678912")]
-        [TestCase("B::version.hardware \r\n\r\n" +
-                  "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
-                  "   Serial Number: C1awfaw484 \r\n\r\n" +
-                  "   Firmware R.2021.02 (136263) \r\n\r\n" +
-                  "   Instance: 1. \r\n\r\n" +
-                  "   Automotive Debug Cable \r\n\r\n" +
-                  "      Serial Number: C16468551", "C16468551", "C1awfaw484")]
-        public void Parse_CorrectValues_ReturnSerials(string file, string expectedHead, string expectedBody) {
-            var (headResult, bodyResult) = DebuggerInfoParser.Parse(file);
 
-            Assert.AreEqual(expectedHead, headResult);
-            Assert.AreEqual(expectedBody, bodyResult);
-        }
+    [Test]
+    [TestCase("B::version.hardware \r\n\r\n" +
+              "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
+              "   Serial Number: C12345678912 \r\n\r\n" +
+              "   Firmware R.2021.02 (136263) \r\n\r\n" +
+              "   Instance: 1. \r\n\r\n" +
+              "   Automotive Debug Cable \r\n\r\n" +
+              "      Serial Number: C12345678912 ", "C12345678912", "C12345678912")]
+    [TestCase("B::version.hardware \r\n\r\n" +
+              "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
+              "   Serial Number: C1awfaw484 \r\n\r\n" +
+              "   Firmware R.2021.02 (136263) \r\n\r\n" +
+              "   Instance: 1. \r\n\r\n" +
+              "   Automotive Debug Cable \r\n\r\n" +
+              "      Serial Number: C16468551", "C16468551", "C1awfaw484")]
+    public void Parse_CorrectValues_ReturnSerials(string file, string expectedHead, string expectedBody) {
+        var (headResult, bodyResult) = DebuggerInfoParser.Parse(file);
 
-
-        [Test]
-        [TestCase("B::version.hardware \r\n\r\n" +
-                  "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
-                  "   Serial Number: C12345678912 \r\n\r\n" +
-                  "   Firmware R.2021.02 (136263) \r\n\r\n" +
-                  "   Instance: 1. \r\n\r\n" +
-                  "   Automotive Debug Cable \r\n\r\n" +
-                  "      Serial Number: C12345678912 \n" +
-                  "      Serial Number: C12345678912 ")]
-        [TestCase("B::version.hardware \r\n\r\n" +
-                  "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
-                  "   Serial Number: C1awfaw484 \r\n\r\n" +
-                  "   Firmware R.2021.02 (136263) \r\n\r\n" +
-                  "   Instance: 1. \r\n\r\n" +
-                  "   Automotive Debug Cable \r\n\r\n" +
-                  "      Serial Numbeeeer: C16468551")]
-        public void Parse_IncorrectValues_ThrowException(string file) {
-            Assert.Throws<ArgumentException>(() => DebuggerInfoParser.Parse(file));
-        }
+        Assert.AreEqual(expectedHead, headResult);
+        Assert.AreEqual(expectedBody, bodyResult);
+    }
 
 
+    [Test]
+    [TestCase("B::version.hardware \r\n\r\n" +
+              "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
+              "   Serial Number: C12345678912 \r\n\r\n" +
+              "   Firmware R.2021.02 (136263) \r\n\r\n" +
+              "   Instance: 1. \r\n\r\n" +
+              "   Automotive Debug Cable \r\n\r\n" +
+              "      Serial Number: C12345678912 \n" +
+              "      Serial Number: C12345678912 ")]
+    [TestCase("B::version.hardware \r\n\r\n" +
+              "PowerDebug USB 3.0 via USB 3.0 \r\n\r\n" +
+              "   Serial Number: C1awfaw484 \r\n\r\n" +
+              "   Firmware R.2021.02 (136263) \r\n\r\n" +
+              "   Instance: 1. \r\n\r\n" +
+              "   Automotive Debug Cable \r\n\r\n" +
+              "      Serial Numbeeeer: C16468551")]
+    public void Parse_IncorrectValues_ThrowException(string file) {
+        Assert.Throws<ArgumentException>(() => DebuggerInfoParser.Parse(file));
     }
-}
+
+
+}
\ No newline at end of file
diff --git a/ld_client/LDClientTests/detection/InfoFetcherTests.cs b/ld_client/LDClientTests/detection/InfoFetcherTests.cs
new file mode 100644
index 0000000..03c62a9
--- /dev/null
+++ b/ld_client/LDClientTests/detection/InfoFetcherTests.cs
@@ -0,0 +1,117 @@
+﻿using System.IO;
+using System.Threading.Tasks;
+using LDClient.detection;
+using LDClient.utils;
+using Moq;
+using NUnit.Framework;
+
+namespace LDClientTests.detection; 
+
+internal class InfoFetcherTests {
+    private InfoFetcher _defaultFetcher;
+    private InfoFetcher _fetcherWithoutPars;
+        
+
+    private readonly string[] _defaultArguments = new[] { "argument 1", "argument 2" , "argument 3"};
+    private const uint DefaultMaxAttempts = 5;
+
+    private Mock<IProcessUtils> _mockProcessUtils;
+    private Mock<IFileUtils> _mockFileUtils;
+
+    [SetUp]
+    public void Setup() {
+        _mockProcessUtils = new Mock<IProcessUtils>(MockBehavior.Strict);
+
+        _mockFileUtils = new Mock<IFileUtils>(MockBehavior.Strict);
+    
+
+        _defaultFetcher = new InfoFetcher(DefaultMaxAttempts, 50, "info.txt", "executable.exe",
+            _defaultArguments, 0, 50) {
+            FileUtils = _mockFileUtils.Object,
+            ProcessUtils = _mockProcessUtils.Object
+        };
+
+
+        _fetcherWithoutPars = new InfoFetcher(DefaultMaxAttempts, 50, "info.txt", "executable.exe",
+            null, 0, 50) {
+            FileUtils = _mockFileUtils.Object,
+            ProcessUtils = _mockProcessUtils.Object
+        };
+    }
+
+    [Test]
+    public async Task FetchDataAsync_ExecuteAll_ExecutedAndFetched() {
+
+        _mockProcessUtils.Setup(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>())).Returns(true);
+        _mockFileUtils.Setup(x => x.ReadFileAllLines(It.IsAny<string>())).
+            Returns(DebuggerInfoParserTests.CorrectFileContent.Split("\n"));
+
+
+        var result = await _defaultFetcher.FetchDataAsync();
+
+        Assert.IsTrue(result);
+        _mockProcessUtils.Verify(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>()), Times.Exactly(_defaultArguments.Length));
+
+        Assert.AreEqual(DebuggerInfoParserTests.BodySerialNumber, _defaultFetcher.BodySerialNumber);
+        Assert.AreEqual(DebuggerInfoParserTests.HeadSerialNumber, _defaultFetcher.HeadSerialNumber);
+
+    }
+
+
+
+    [Test]
+    public async Task FetchDataAsync_ExecuteNonExistentProgram_ExecutionFailed() {
+
+        _mockProcessUtils.Setup(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>())).Returns(false);
+        _mockFileUtils.Setup(x => x.ReadFileAllLines(It.IsAny<string>())).
+            Returns(new []{""});
+
+
+        var result = await _defaultFetcher.FetchDataAsync();
+
+
+        Assert.IsFalse(result);
+        _mockProcessUtils.Verify(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>()), Times.Exactly(1));
+        _mockFileUtils.Verify(x => x.ReadFileAllLines(It.IsAny<string>()), Times.Never);
+    }
+
+    [Test]
+    public async Task FetchDataAsync_ExecuteWithoutParameters_NotExecuted() {
+        _mockProcessUtils.Setup(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>())).Returns(false);
+        _mockFileUtils.Setup(x => x.ReadFileAllLines(It.IsAny<string>())).
+            Returns(new[] { "" });
+
+        var result = await _fetcherWithoutPars.FetchDataAsync();
+            
+        Assert.IsFalse(result);
+        _mockProcessUtils.Verify(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>()), Times.Never);
+        _mockFileUtils.Verify(x => x.ReadFileAllLines(It.IsAny<string>()), Times.Never);
+
+    }
+
+
+    [Test]
+    public async Task FetchDataAsync_ExecuteInfoNotCreated_FetchFailed() {
+        _mockProcessUtils.Setup(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>())).Returns(true);
+        _mockFileUtils.Setup(x => x.ReadFileAllLines(It.IsAny<string>())).Throws(new FileNotFoundException());
+
+        var result = await _defaultFetcher.FetchDataAsync();
+        Assert.IsFalse(result);
+
+        _mockProcessUtils.Verify(x => x.ExecuteNewProcess(It.IsAny<string>(), It.IsAny<string>(),
+            It.IsAny<int>(), It.IsAny<int>()), Times.Exactly(_defaultArguments.Length));
+        _mockFileUtils.Verify(x => x.ReadFileAllLines(It.IsAny<string>()), Times.Exactly((int)DefaultMaxAttempts));
+
+    }
+
+
+
+
+}
\ No newline at end of file
