private void TestVerifyReferenceAttributesHelper(string itemSpec, string projectGuid, string package, string name, bool expectedResult, string expectedMissingAttribute) { ITaskItem reference = CreateReferenceItem(itemSpec, projectGuid, package, name); ResolveNonMSBuildProjectOutput rvpo = new ResolveNonMSBuildProjectOutput(); string missingAttr = null; bool result = rvpo.VerifyReferenceAttributes(reference, out missingAttr); string message = string.Format("Reference \"{0}\" [project \"{1}\", package \"{2}\", name \"{3}\"], " + "expected result \"{4}\", actual result \"{5}\", expected missing attr \"{6}\", actual missing attr \"{7}\".", itemSpec, projectGuid, package, name, expectedResult, result, expectedMissingAttribute, missingAttr); Assert.IsTrue(result == expectedResult, message); if (result == false) { Assert.IsTrue(missingAttr == expectedMissingAttribute, message); } else { Assert.IsNull(missingAttr, message); } }
private void TestResolveHelper(string itemSpec, string projectGuid, string package, string name, Hashtable pregenOutputs, bool expectedResult, string expectedPath) { ITaskItem reference = CreateReferenceItem(itemSpec, projectGuid, package, name); string xmlString = CreatePregeneratedPathDoc(pregenOutputs); ITaskItem resolvedPath; ResolveNonMSBuildProjectOutput rvpo = new ResolveNonMSBuildProjectOutput(); rvpo.CacheProjectElementsFromXml(xmlString); bool result = rvpo.ResolveProject(reference, out resolvedPath); string message = string.Format("Reference \"{0}\" [project \"{1}\", package \"{2}\", name \"{3}\"] Pregen Xml string : \"{4}\"" + "expected result \"{5}\", actual result \"{6}\", expected path \"{7}\", actual path \"{8}\".", itemSpec, projectGuid, package, name, xmlString, expectedResult, result, expectedPath, resolvedPath); Assert.IsTrue(result == expectedResult, message); if (result == true) { Assert.IsTrue(resolvedPath.ItemSpec == expectedPath, message); } else { Assert.IsNull(resolvedPath, message); } }
public void TestVerifyProjectReferenceItem() { ResolveNonMSBuildProjectOutput rvpo = new ResolveNonMSBuildProjectOutput(); ITaskItem[] taskItems = new ITaskItem[1]; // bad GUID - this reference is invalid taskItems[0] = new TaskItem("projectReference"); taskItems[0].SetMetadata(attributeProject, "{invalid guid}"); MockEngine engine = new MockEngine(); rvpo.BuildEngine = engine; Assert.AreEqual(true, rvpo.VerifyProjectReferenceItems(taskItems, false /* treat problems as warnings */)); Assert.AreEqual(1, engine.Warnings); Assert.AreEqual(0, engine.Errors); engine.AssertLogContains("MSB3107"); engine = new MockEngine(); rvpo.BuildEngine = engine; Assert.AreEqual(false, rvpo.VerifyProjectReferenceItems(taskItems, true /* treat problems as errors */)); Assert.AreEqual(0, engine.Warnings); Assert.AreEqual(1, engine.Errors); engine.AssertLogContains("MSB3107"); }
private void TestUnresolvedReferencesHelper(ArrayList projectRefs, Hashtable pregenOutputs, Func<string, bool> isManaged, out Hashtable unresolvedOutputs, out Hashtable resolvedOutputs) { ResolveNonMSBuildProjectOutput.GetAssemblyNameDelegate pretendGetAssemblyName = path => { if (isManaged != null && isManaged(path)) { return null; // just don't throw an exception } else { throw new BadImageFormatException(); // the hint that the caller takes for an unmanaged binary. } }; string xmlString = CreatePregeneratedPathDoc(pregenOutputs); MockEngine engine = new MockEngine(); ResolveNonMSBuildProjectOutput rvpo = new ResolveNonMSBuildProjectOutput(); rvpo.GetAssemblyName = pretendGetAssemblyName; rvpo.BuildEngine = engine; rvpo.PreresolvedProjectOutputs = xmlString; rvpo.ProjectReferences = (ITaskItem[])projectRefs.ToArray(typeof(ITaskItem)); bool result = rvpo.Execute(); unresolvedOutputs = new Hashtable(); for (int i = 0; i < rvpo.UnresolvedProjectReferences.Length; i++) { unresolvedOutputs[rvpo.UnresolvedProjectReferences[i].ItemSpec] = rvpo.UnresolvedProjectReferences[i]; } resolvedOutputs = new Hashtable(); for (int i = 0; i < rvpo.ResolvedOutputPaths.Length; i++) { resolvedOutputs[rvpo.ResolvedOutputPaths[i].ItemSpec] = rvpo.ResolvedOutputPaths[i]; } }