Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active December 28, 2015 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/7522819 to your computer and use it in GitHub Desktop.
Save JayBazuzi/7522819 to your computer and use it in GitHub Desktop.
Unit test for running a custom MSBuild task.
[TestMethod]
public void RequiredInputGetsLogged()
{
var buildTarget = CreateBuildTarget();
buildTarget.AddTask<TaskWithRequiredInput>().SetParameter("Foo", "hi");
const string expected = @"Inputs:
Foo = hi
";
AssertTargettOutput(expected, buildTarget);
}
private ProjectTargetElement CreateBuildTarget()
{
var buildTarget = ProjectRootElement.Create().AddTarget("Build");
return buildTarget;
}
private static void AssertTargettOutput(string expected, ProjectTargetElement projectTargetElement)
{
var highImportanceStringLogger = new HighImportanceStringLogger();
var success = new ProjectInstance(projectTargetElement.ContainingProject).Build(new[] { highImportanceStringLogger });
Assert.IsTrue(success);
Assert.AreEqual(expected, highImportanceStringLogger.ToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment