private void ValidateGeneratedProject( string[] itemsToSign, Dictionary <string, SignInfo> strongNameSignInfo, Dictionary <ExplicitCertificateKey, string> fileSignInfo, Dictionary <string, SignInfo> extensionsSignInfo, string[] expectedXmlElementsPerSingingRound, string[] dualCertificates = null) { var buildEngine = new FakeBuildEngine(); var task = new SignToolTask { BuildEngine = buildEngine }; // The path to MSBuild will always be null in these tests, this will force // the signing logic to call our FakeBuildEngine.BuildProjectFile with a path // to the XML that store the content of the would be Microbuild sign request. var signToolArgs = new SignToolArgs(_tmpDir, microBuildCorePath: "MicroBuildCorePath", testSign: true, msBuildPath: null, _tmpDir, enclosingDir: "", ""); var signTool = new FakeSignTool(signToolArgs, task.Log); var signingInput = new Configuration(signToolArgs.TempDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles(); var util = new BatchSignUtil(task.BuildEngine, task.Log, signTool, signingInput, new string[] { }); util.Go(false); Assert.Same(ByteSequenceComparer.Instance, signingInput.ZipDataMap.KeyComparer); // The list of files that would be signed was captured inside the FakeBuildEngine, // here we check if that matches what we expected var actualXmlElementsPerSingingRound = buildEngine.FilesToSign.Select(round => string.Join(Environment.NewLine, round)); AssertEx.Equal(expectedXmlElementsPerSingingRound, actualXmlElementsPerSingingRound, comparer: AssertEx.EqualIgnoringWhitespace, itemInspector: s => s.Replace("\"", "\"\"")); Assert.False(task.Log.HasLoggedErrors); }
private void ValidateFileSignInfos( string[] itemsToSign, Dictionary <string, SignInfo> strongNameSignInfo, Dictionary <ExplicitCertificateKey, string> fileSignInfo, Dictionary <string, SignInfo> extensionsSignInfo, string[] expected, string[] expectedCopyFiles = null, string[] dualCertificates = null, string[] expectedErrors = null, string[] expectedWarnings = null) { var engine = new FakeBuildEngine(); var task = new SignToolTask { BuildEngine = engine }; var signingInput = new Configuration(_tmpDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles(); AssertEx.Equal(expected, signingInput.FilesToSign.Select(f => f.ToString())); AssertEx.Equal(expectedCopyFiles ?? Array.Empty <string>(), signingInput.FilesToCopy.Select(f => $"{f.Key} -> {f.Value}")); AssertEx.Equal(expectedErrors ?? Array.Empty <string>(), engine.LogErrorEvents.Select(w => w.Message)); AssertEx.Equal(expectedWarnings ?? Array.Empty <string>(), engine.LogWarningEvents.Select(w => $"{w.Code}: {w.Message}")); }