using System; using System.Globalization; using System.IO; using NUnit.Framework; using NAnt.Core; using NAnt.Core.Tasks; using Tests.NAnt.Core; namespace Tests.NAnt.SourceControl.Tasks { [TestFixture] public class CvsTaskTest : BuildTestBase { private string destination; private readonly string MODULE = "sharpcvslib"; private readonly string OVERRIDE_DIR = "sharpcvslib-new"; private readonly string CHECK_FILE = "SharpCvsLib.sln"; private readonly string CVSROOT = ":pserver:anonymous@goliath.sporadicism.com:/cvsroot/sharpcvslib"; private readonly string CHECKOUT = @" "; private readonly string CHECKOUT_WITH_COMMAND_OPTIONS = @" "; private readonly string GENERIC_COMMANDLINE = @" "; #region Override implementation of BuildTestBase /// /// Run the checkout command so we have something to update. /// [SetUp] protected override void SetUp () { base.SetUp (); } /// /// Remove the directory created by the checkout/ update. /// [TearDown] protected override void TearDown () { base.TearDown(); } #endregion Override implementation of BuildTestBase /// /// Test that the checkout command executes successfully. /// [Test] [Category("InetAccess")] public void TestCheckout () { this.destination = this.TempDirName; string checkoutPath = Path.Combine(this.destination, this.MODULE); string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE); object[] args = {"co", CVSROOT, MODULE, this.destination, true}; this.RunBuild(FormatBuildFile(CHECKOUT, args), Level.Info); Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there."); } /// /// Test that the checkout command executes successfully with non-sharpcvslib binary. /// [Test] [Category("InetAccess")] public void TestCheckout_NotSharpcvslib () { this.destination = this.TempDirName; string checkoutPath = Path.Combine(this.destination, this.MODULE); string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE); object[] args = {"co", CVSROOT, MODULE, this.destination, false}; this.RunBuild(FormatBuildFile(CHECKOUT, args), Level.Info); Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there."); } /// /// Test that the checkout command executes successfully with non-sharpcvslib binary. /// [Test] [Category("InetAccess")] public void TestCheckout_CommandOptions_NoSharpCvsLib () { this.destination = this.TempDirName; string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR); string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE); object[] args = {"co", CVSROOT, MODULE, this.destination, false, this.OVERRIDE_DIR, "HEAD"}; this.RunBuild(FormatBuildFile(CHECKOUT_WITH_COMMAND_OPTIONS, args), Level.Info); Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there."); } /// /// Test that the checkout command executes successfully with non-sharpcvslib binary. /// // TODO: Get this unit test working /* public void TestCheckout_CommandOptions_SharpCvsLib () { this.destination = this.TempDirName; string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR); string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE); object[] args = {"co", CVSROOT, MODULE, this.destination, true, this.OVERRIDE_DIR, "HEAD"}; string result = this.RunBuild(FormatBuildFile(CHECKOUT_WITH_COMMAND_OPTIONS, args), Level.Debug); System.Console.WriteLine(result); Assertion.Assert("The check file should not be there.", File.Exists(checkFilePath)); } */ [Test] [Category("InetAccess")] public void TestCheckout_CommandLine_Sharpcvslib () { this.destination = this.TempDirName; string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR); string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE); object[] checkoutArgs = {"co", CVSROOT, MODULE, this.destination, true}; string resultCheckout = this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, checkoutArgs), Level.Info); System.Console.WriteLine(resultCheckout); Directory.Delete(Path.Combine(this.destination, "build")); object[] updateArgs = {"update -dP", CVSROOT, MODULE, this.destination, true}; this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, updateArgs), Level.Info); Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there."); } /// /// Test that the time necessary to perform a checkout with both binaries /// is equal. /// [Test] [Category("InetAccess")] public void TestTimeCheckout () { long sharpCvsLibTime = DoCheckout(true); long cvsPathTime = DoCheckout(false); Assert.IsTrue(sharpCvsLibTime < cvsPathTime, "Sharpcvslib time: " + sharpCvsLibTime + "; time for the cvs executable in the path" + " variable: " + cvsPathTime); } #region Private Instance Methods private string FormatBuildFile(string baseFile, object[] args) { return string.Format(CultureInfo.InvariantCulture, baseFile, args); } private long DoCheckout (bool useSharpCvsLib) { DateTime start = DateTime.Now; this.destination = this.TempDirName; object[] checkoutArgs = {"co", CVSROOT, MODULE, this.destination, useSharpCvsLib}; string resultCheckout = this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, checkoutArgs), Level.Info); System.Console.WriteLine(resultCheckout); DateTime end = DateTime.Now; // cleanup for next checkout test Directory.Delete(Path.Combine(this.destination, MODULE), true); return end.Subtract(start).Ticks; } #endregion Private Instance Methods } }