using ICSharpCode.NAnt; using NUnit.Framework; using System; using System.IO; namespace ICSharpCode.NAnt.Tests { /// /// Tests the class. /// [TestFixture] public class ReadNAntBuildFileTestFixture { NAntBuildFile buildFile; [SetUp] public void Init() { StringReader reader = new StringReader(GetBuildFileXml()); buildFile = new NAntBuildFile(reader); } [Test] public void ProjectName() { Assert.AreEqual("Hello World", buildFile.Name, "Project name is wrong."); } [Test] public void DefaultTarget() { // Check the name. Assert.IsNotNull(buildFile.DefaultTarget, "Should have a default target."); Assert.AreEqual("test", buildFile.DefaultTarget.Name, "Default target read from build file is wrong."); } [Test] public void Targets() { Assert.AreEqual(3, buildFile.Targets.Count, "Should have 3 targets."); NAntBuildTarget target = buildFile.Targets[0]; Assert.AreEqual("clean", target.Name, "Target name should be 'clean'."); Assert.IsFalse(target.IsDefault, "Clean target should not have default target flag set."); Assert.AreEqual(5, target.Line, "Clean target line number is incorrect."); Assert.AreEqual(6, target.Column, "Clean target column number is incorrect."); target = buildFile.Targets[1]; Assert.IsFalse(target.IsDefault, "Build target should not have default target flag set."); Assert.AreEqual("build", target.Name, "Target name should be 'build'."); Assert.AreEqual(14, target.Line, "Build target line number is incorrect."); Assert.AreEqual(6, target.Column, "Build target column number is incorrect."); target = buildFile.Targets[2]; Assert.AreEqual("test", target.Name, "Target name should be 'test'."); Assert.IsTrue(target.IsDefault, "Test target should have default target flag set."); Assert.AreEqual(32, target.Line, "Test target line number is incorrect."); Assert.AreEqual(6, target.Column, "Test target column number is incorrect."); } /// /// Gets the build file xml that will be used in this /// test fixture. /// string GetBuildFileXml() { return "\r\n" + " \r\n" + " \r\n" + "\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + "\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + "\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + ""; } } }