|
1 | 1 | using LCT.Common;
|
| 2 | +using LCT.Common.Interface; |
2 | 3 | using LCT.Common.Model;
|
| 4 | +using log4net; |
| 5 | +using log4net.Appender; |
| 6 | +using log4net.Config; |
3 | 7 | using NUnit.Framework;
|
| 8 | +using System; |
4 | 9 | using System.Collections.Generic;
|
| 10 | +using System.IO; |
5 | 11 |
|
6 |
| -namespace LCT.PackageIdentifier.Tests |
| 12 | +namespace LCT.PackageIdentifier.UTest |
7 | 13 | {
|
8 | 14 | [TestFixture]
|
9 | 15 | public class DisplayInformationTests
|
10 | 16 | {
|
11 | 17 | private CommonAppSettings appSettings;
|
| 18 | + private CatoolInfo caToolInformation; |
| 19 | + private MemoryAppender memoryAppender; |
12 | 20 |
|
13 | 21 | [SetUp]
|
14 | 22 | public void Setup()
|
15 | 23 | {
|
16 | 24 | appSettings = new CommonAppSettings();
|
17 | 25 | }
|
| 26 | + |
| 27 | + [Test] |
| 28 | + public void LogInputParameters_ShouldLogCorrectMessage_WhenBasicSBOMIsFalse() |
| 29 | + { |
| 30 | + // Arrange |
| 31 | + string listOfInternalRepoList = "repo1,repo2"; |
| 32 | + string listOfInclude = "include1,include2"; |
| 33 | + string listOfExclude = "exclude1,exclude2"; |
| 34 | + string listOfExcludeComponents = "component1,component2"; |
| 35 | + string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; |
| 36 | + string OutFolder = Path.GetDirectoryName(exePath); |
| 37 | + IFolderAction folderAction = new FolderAction(); |
| 38 | + IFileOperations fileOperations = new FileOperations(); |
| 39 | + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) |
| 40 | + { |
| 41 | + ProjectType = "NPM", |
| 42 | + BasicSBOM = false, |
| 43 | + SW360 = new SW360() |
| 44 | + { |
| 45 | + URL = "http://sw360.url", |
| 46 | + AuthTokenType = "Bearer", |
| 47 | + ProjectName = "ProjectName", |
| 48 | + ProjectID = "ProjectID", |
| 49 | + ExcludeComponents = new List<string> { "component1", "component2" } |
| 50 | + }, |
18 | 51 |
|
| 52 | + Directory = new LCT.Common.Directory(folderAction, fileOperations) |
| 53 | + { |
| 54 | + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", |
| 55 | + OutputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" |
| 56 | + } |
| 57 | + }; |
| 58 | + caToolInformation = new CatoolInfo |
| 59 | + { |
| 60 | + CatoolVersion = "1.0.0", |
| 61 | + CatoolRunningLocation = "runningLocation" |
| 62 | + }; |
| 63 | + |
| 64 | + memoryAppender = new MemoryAppender(); |
| 65 | + BasicConfigurator.Configure(memoryAppender); |
| 66 | + // Act |
| 67 | + DisplayInformation.LogInputParameters(caToolInformation, appSettings, listOfInternalRepoList, listOfInclude, listOfExclude, listOfExcludeComponents); |
| 68 | + |
| 69 | + // Assert |
| 70 | + string expectedLogMessage = $"Input Parameters used in Package Identifier:\n\t" + |
| 71 | + $"CaToolVersion\t\t --> {caToolInformation.CatoolVersion}\n\t" + |
| 72 | + $"CaToolRunningPath\t --> {caToolInformation.CatoolRunningLocation}\n\t" + |
| 73 | + $"PackageFilePath\t\t --> {appSettings.Directory.InputFolder}\n\t" + |
| 74 | + $"BomFolderPath\t\t --> {appSettings.Directory.OutputFolder}\n\t" + |
| 75 | + $"SW360Url\t\t --> {appSettings.SW360.URL}\n\t" + |
| 76 | + $"SW360AuthTokenType\t --> {appSettings.SW360.AuthTokenType}\n\t" + |
| 77 | + $"SW360ProjectName\t --> {appSettings.SW360.ProjectName}\n\t" + |
| 78 | + $"SW360ProjectID\t\t --> {appSettings.SW360.ProjectID}\n\t" + |
| 79 | + $"InternalRepoList\t --> {listOfInternalRepoList}\n\t" + |
| 80 | + $"ProjectType\t\t --> {appSettings.ProjectType}\n\t" + |
| 81 | + $"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" + |
| 82 | + $"Include\t\t\t --> {listOfInclude}\n\t" + |
| 83 | + $"Exclude\t\t\t --> {listOfExclude}\n\t" + |
| 84 | + $"ExcludeComponents\t --> {listOfExcludeComponents}\n"; |
| 85 | + |
| 86 | + var logEvents = memoryAppender.GetEvents(); |
| 87 | + Assert.IsNotEmpty(logEvents); |
| 88 | + var actualLogMessage = logEvents[0].RenderedMessage; |
| 89 | + Assert.AreEqual(expectedLogMessage, actualLogMessage); |
| 90 | + } |
| 91 | + [Test] |
| 92 | + public void LogInputParameters_ShouldLogCorrectMessage_WhenBasicSBOMIsTrue() |
| 93 | + { |
| 94 | + // Arrange |
| 95 | + string listOfInternalRepoList = "repo1,repo2"; |
| 96 | + string listOfInclude = "include1,include2"; |
| 97 | + string listOfExclude = "exclude1,exclude2"; |
| 98 | + string listOfExcludeComponents = "component1,component2"; |
| 99 | + string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; |
| 100 | + string OutFolder = Path.GetDirectoryName(exePath); |
| 101 | + IFolderAction folderAction = new FolderAction(); |
| 102 | + IFileOperations fileOperations = new FileOperations(); |
| 103 | + CommonAppSettings appSettings = new CommonAppSettings(folderAction, fileOperations) |
| 104 | + { |
| 105 | + ProjectType = "NPM", |
| 106 | + BasicSBOM = true, |
| 107 | + SW360 = new SW360() |
| 108 | + { |
| 109 | + URL = "http://sw360.url", |
| 110 | + AuthTokenType = "Bearer", |
| 111 | + ProjectName = "ProjectName", |
| 112 | + ProjectID = "ProjectID", |
| 113 | + ExcludeComponents = new List<string> { "component1", "component2" } |
| 114 | + }, |
| 115 | + |
| 116 | + Directory = new LCT.Common.Directory(folderAction, fileOperations) |
| 117 | + { |
| 118 | + InputFolder = OutFolder + @"\PackageIdentifierUTTestFiles", |
| 119 | + OutputFolder = OutFolder + @"\PackageIdentifierUTTestFiles" |
| 120 | + } |
| 121 | + }; |
| 122 | + caToolInformation = new CatoolInfo |
| 123 | + { |
| 124 | + CatoolVersion = "1.0.0", |
| 125 | + CatoolRunningLocation = "runningLocation" |
| 126 | + }; |
| 127 | + |
| 128 | + memoryAppender = new MemoryAppender(); |
| 129 | + BasicConfigurator.Configure(memoryAppender); |
| 130 | + // Act |
| 131 | + DisplayInformation.LogInputParameters(caToolInformation, appSettings, listOfInternalRepoList, listOfInclude, listOfExclude, listOfExcludeComponents); |
| 132 | + |
| 133 | + // Assert |
| 134 | + string expectedLogMessage = $"Input Parameters used in Package Identifier:\n\t" + |
| 135 | + $"CaToolVersion\t\t --> {caToolInformation.CatoolVersion}\n\t" + |
| 136 | + $"CaToolRunningPath\t --> {caToolInformation.CatoolRunningLocation}\n\t" + |
| 137 | + $"PackageFilePath\t\t --> {appSettings.Directory.InputFolder}\n\t" + |
| 138 | + $"BomFolderPath\t\t --> {appSettings.Directory.OutputFolder}\n\t" + |
| 139 | + $"ProjectType\t\t --> {appSettings.ProjectType}\n\t" + |
| 140 | + $"LogFolderPath\t\t --> {Log4Net.CatoolLogPath}\n\t" + |
| 141 | + $"Include\t\t\t --> {listOfInclude}\n\t" + |
| 142 | + $"Exclude\t\t\t --> {listOfExclude}\n\t" + |
| 143 | + $"ExcludeComponents\t --> {listOfExcludeComponents}\n"; |
| 144 | + |
| 145 | + var logEvents = memoryAppender.GetEvents(); |
| 146 | + Assert.IsNotEmpty(logEvents); |
| 147 | + var actualLogMessage = logEvents[0].RenderedMessage; |
| 148 | + Assert.AreEqual(expectedLogMessage, actualLogMessage); |
| 149 | + } |
19 | 150 | [TestCase("NPM", "p*-lock.json,*.cdx.json", "node_modules,Test", "Npm-Test")]
|
20 | 151 | [TestCase("NUGET", "p*-lock.json,*.cdx.json", "package,Test", "Nuget-Test")]
|
21 | 152 | [TestCase("MAVEN", "*.cdx.json", "package,Test", "Maven-Test")]
|
|
0 commit comments