Ejemplo n.º 1
0
        public void CanRecognizeBooleanOptions(string propertyName, string pattern)
        {
            string[] prototypes = pattern.Split('|');

            PropertyInfo property = GetPropertyInfo(propertyName);
            Assert.AreEqual(typeof(bool), property.PropertyType, "Property '{0}' is wrong type", propertyName);

            foreach (string option in prototypes)
            {
                ConsoleOptions options;

                if (option.Length == 1)
                {
                    options = new ConsoleOptions("-" + option);
                    Assert.AreEqual(true, (bool)property.GetValue(options, null), "Didn't recognize -" + option);

                    options = new ConsoleOptions("-" + option + "+");
                    Assert.AreEqual(true, (bool)property.GetValue(options, null), "Didn't recognize -" + option + "+");

                    options = new ConsoleOptions("-" + option + "-");
                    Assert.AreEqual(false, (bool)property.GetValue(options, null), "Didn't recognize -" + option + "-");
                }
                else
                {
                    options = new ConsoleOptions("--" + option);
                    Assert.AreEqual(true, (bool)property.GetValue(options, null), "Didn't recognize --" + option);
                }

                options = new ConsoleOptions("/" + option);
                Assert.AreEqual(true, (bool)property.GetValue(options, null), "Didn't recognize /" + option);
            }
        }
Ejemplo n.º 2
0
        public void WhenTimeoutIsSpecified_RunSettingsIncludeIt()
        {
            var options = new ConsoleOptions("test.dll", "--timeout=50");
            var settings = TextRunner.MakeRunSettings(options);

            Assert.That(settings.ContainsKey("DefaultTimeout"));
            Assert.AreEqual(50, settings["DefaultTimeout"]);
        }
Ejemplo n.º 3
0
        public void WhenWorkDirectoryIsSpecified_RunSettingsIncludeIt()
        {
            var options = new ConsoleOptions("test.dll", "--work=results");
            var settings = TextRunner.MakeRunSettings(options);

            Assert.That(settings.ContainsKey("WorkDirectory"));
            Assert.AreEqual(Path.GetFullPath("results"), settings["WorkDirectory"]);
        }
Ejemplo n.º 4
0
        public void WhenSeedIsSpecified_RunSettingsIncludeIt()
        {
            var options = new ConsoleOptions("test.dll", "--seed=1234");
            var settings = TextRunner.MakeRunSettings(options);

            Assert.That(settings.ContainsKey("RandomSeed"));
            Assert.AreEqual(1234, settings["RandomSeed"]);
        }
Ejemplo n.º 5
0
        public void SingleAssembly()
        {
            var options = new ConsoleOptions("test.dll");
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.AreEqual(1, package.SubPackages.Count);
            Assert.AreEqual(Path.GetFullPath("test.dll"), package.SubPackages[0].FullName);
        }
Ejemplo n.º 6
0
        public void WhenOptionIsSpecified_PackageIncludesSetting(string option, string key, object val)
        {
            var options = new ConsoleOptions("test.dll", option);
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.That(package.Settings.ContainsKey(key), "Setting not included for {0}", option);
            Assert.AreEqual(val, package.Settings[key], "NumberOfTestWorkers not set correctly for {0}", option);
        }
Ejemplo n.º 7
0
        public void WhenDebugging_NumberOfTestWorkersDefaultsToZero()
        {
            var options = new ConsoleOptions("test.dll", "--debug");
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.That(package.Settings["DebugTests"], Is.EqualTo(true));
            Assert.That(package.Settings["NumberOfTestWorkers"], Is.EqualTo(0));
        }
Ejemplo n.º 8
0
        public void MultipleAssemblies()
        {
            var names = new [] { "test1.dll", "test2.dll", "test3.dll" };
            var options = new ConsoleOptions(names);
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.AreEqual(3, package.SubPackages.Count);
            Assert.AreEqual(Path.GetFullPath("test1.dll"), package.SubPackages[0].FullName);
            Assert.AreEqual(Path.GetFullPath("test2.dll"), package.SubPackages[1].FullName);
            Assert.AreEqual(Path.GetFullPath("test3.dll"), package.SubPackages[2].FullName);
        }
Ejemplo n.º 9
0
 public void InvalidOption()
 {
     ConsoleOptions options = new ConsoleOptions("-assembly:nunit.tests.dll");
     Assert.False(options.Validate());
     Assert.AreEqual(1, options.ErrorMessages.Count);
     Assert.AreEqual("Invalid argument: -assembly:nunit.tests.dll", options.ErrorMessages[0]);
 }
Ejemplo n.º 10
0
 public void TimeoutIsMinusOneIfNoOptionIsProvided()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll");
     Assert.True(options.Validate());
     Assert.AreEqual(-1, options.DefaultTimeout);
 }
Ejemplo n.º 11
0
 public void InvalidCommandLineParms()
 {
     ConsoleOptions options = new ConsoleOptions("-garbage:TestFixture", "-assembly:Tests.dll");
     Assert.False(options.Validate());
     Assert.AreEqual(2, options.ErrorMessages.Count);
     Assert.AreEqual("Invalid argument: -garbage:TestFixture", options.ErrorMessages[0]);
     Assert.AreEqual("Invalid argument: -assembly:Tests.dll", options.ErrorMessages[1]);
 }
Ejemplo n.º 12
0
 public void ExploreOptionWithFilePathUsingEqualSign()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "-explore=C:/nunit/tests/bin/Debug/console-test.xml");
     Assert.True(options.Validate());
     Assert.True(options.Explore);
     Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
     Assert.AreEqual("tests.dll", options.InputFiles[0]);
     Assert.AreEqual("C:/nunit/tests/bin/Debug/console-test.xml", options.ExploreOutputSpecifications[0].OutputPath);
 }
Ejemplo n.º 13
0
        public void ShouldSetTeamCityFlagAccordingToArgsAndDefauls(bool hasTeamcityInCmd, bool? defaultTeamcity, bool expectedTeamCity)
        {
            // Given
            List<string> args = new List<string> { "tests.dll" };
            if (hasTeamcityInCmd)
            {
                args.Add("--teamcity");
            }

            ConsoleOptions options;
            if (defaultTeamcity.HasValue)
            {
                options = new ConsoleOptions(new DefaultOptionsProviderStub(defaultTeamcity.Value), args.ToArray());
            }
            else
            {
                options = new ConsoleOptions(args.ToArray());
            }

            // When
            var actualTeamCity = options.TeamCity;

            // Then
            Assert.AreEqual(actualTeamCity, expectedTeamCity);
        }
Ejemplo n.º 14
0
 public void AssemblyName()
 {
     ConsoleOptions options = new ConsoleOptions("nunit.tests.dll");
     Assert.True(options.Validate());
     Assert.AreEqual(1, options.InputFiles.Count);
     Assert.AreEqual("nunit.tests.dll", options.InputFiles[0]);
 }
Ejemplo n.º 15
0
        public void ResultOptionWithFilePathAndFormat()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-result:results.xml;format=nunit2");
            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);

            OutputSpecification spec = options.ResultOutputSpecifications[0];
            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("nunit2", spec.Format);
            Assert.Null(spec.Transform);
        }
Ejemplo n.º 16
0
 public void MissingValuesAreReported(string option)
 {
     ConsoleOptions options = new ConsoleOptions(option + "=");
     Assert.False(options.Validate(), "Missing value should not be valid");
     Assert.AreEqual("Missing required value for option '" + option + "'.", options.ErrorMessages[0]);
 }
Ejemplo n.º 17
0
 public void NoResultSuppressesAllResultSpecifications()
 {
     var options = new ConsoleOptions("test.dll", "-result:results.xml", "-noresult", "-result:nunit2results.xml;format=nunit2");
     Assert.AreEqual(0, options.ResultOutputSpecifications.Count);
 }
Ejemplo n.º 18
0
 public void NoInputFiles()
 {
     ConsoleOptions options = new ConsoleOptions();
     Assert.True(options.Validate());
     Assert.AreEqual(0, options.InputFiles.Count);
 }
Ejemplo n.º 19
0
 public void TimeoutParsesIntValueCorrectly()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "-timeout:5000");
     Assert.True(options.Validate());
     Assert.AreEqual(5000, options.DefaultTimeout);
 }
Ejemplo n.º 20
0
        public void ResultOptionMayBeRepeated()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-result:results.xml", "-result:nunit2results.xml;format=nunit2", "-result:myresult.xml;transform=mytransform.xslt");
            Assert.True(options.Validate(), "Should be valid");

            var specs = options.ResultOutputSpecifications;
            Assert.AreEqual(3, specs.Count);

            var spec1 = specs[0];
            Assert.AreEqual("results.xml", spec1.OutputPath);
            Assert.AreEqual("nunit3", spec1.Format);
            Assert.Null(spec1.Transform);

            var spec2 = specs[1];
            Assert.AreEqual("nunit2results.xml", spec2.OutputPath);
            Assert.AreEqual("nunit2", spec2.Format);
            Assert.Null(spec2.Transform);

            var spec3 = specs[2];
            Assert.AreEqual("myresult.xml", spec3.OutputPath);
            Assert.AreEqual("user", spec3.Format);
            Assert.AreEqual("mytransform.xslt", spec3.Transform);
        }
Ejemplo n.º 21
0
 public void ResultOptionWithoutFileNameIsInvalid()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "-result:");
     Assert.False(options.Validate(), "Should not be valid");
     Assert.AreEqual(1, options.ErrorMessages.Count, "An error was expected");
 }
Ejemplo n.º 22
0
 public void FileNameWithoutResultOptionLooksLikeParameter()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "results.xml");
     Assert.True(options.Validate());
     Assert.AreEqual(0, options.ErrorMessages.Count);
     Assert.AreEqual(2, options.InputFiles.Count);
 }
Ejemplo n.º 23
0
 public void AssemblyAloneIsValid()
 {
     ConsoleOptions options = new ConsoleOptions("nunit.tests.dll");
     Assert.True(options.Validate());
     Assert.AreEqual(0, options.ErrorMessages.Count, "command line should be valid");
 }
Ejemplo n.º 24
0
 public void ExploreOptionWithoutPath()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "-explore");
     Assert.True(options.Validate());
     Assert.True(options.Explore);
 }
Ejemplo n.º 25
0
        public void WhenNoOptionsAreSpecified_PackageContainsWorkDirectorySettingOnly()
        {
            var options = new ConsoleOptions("test.dll");
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.AreEqual(1, package.Settings.Count);
            Assert.That(package.Settings.Keys, Contains.Item("WorkDirectory"));
        }
Ejemplo n.º 26
0
        public void ExploreOptionWithFilePathAndTransform()
        {
            ConsoleOptions options = new ConsoleOptions("tests.dll", "-explore:results.xml;transform=myreport.xslt");
            Assert.True(options.Validate());
            Assert.AreEqual(1, options.InputFiles.Count, "assembly should be set");
            Assert.AreEqual("tests.dll", options.InputFiles[0]);
            Assert.True(options.Explore);

            OutputSpecification spec = options.ExploreOutputSpecifications[0];
            Assert.AreEqual("results.xml", spec.OutputPath);
            Assert.AreEqual("user", spec.Format);
            Assert.AreEqual("myreport.xslt", spec.Transform);
        }
Ejemplo n.º 27
0
        public void DefaultResultSpecification()
        {
            var options = new ConsoleOptions("test.dll");
            Assert.AreEqual(1, options.ResultOutputSpecifications.Count);

            var spec = options.ResultOutputSpecifications[0];
            Assert.AreEqual("TestResult.xml", spec.OutputPath);
            Assert.AreEqual("nunit3", spec.Format);
            Assert.Null(spec.Transform);
        }
Ejemplo n.º 28
0
 public void TimeoutCausesErrorIfValueIsNotInteger()
 {
     ConsoleOptions options = new ConsoleOptions("tests.dll", "-timeout:abc");
     Assert.False(options.Validate());
     Assert.AreEqual(-1, options.DefaultTimeout);
 }
Ejemplo n.º 29
0
        public void WhenDebugging_NumberOfTestWorkersMayBeOverridden()
        {
            var options = new ConsoleOptions("test.dll", "--debug", "--workers=3");
            var package = ConsoleRunner.MakeTestPackage(options);

            Assert.That(package.Settings["DebugTests"], Is.EqualTo(true));
            Assert.That(package.Settings["NumberOfTestWorkers"], Is.EqualTo(3));
        }
Ejemplo n.º 30
0
 public void NoResultSuppressesDefaultResultSpecification()
 {
     var options = new ConsoleOptions("test.dll", "-noresult");
     Assert.AreEqual(0, options.ResultOutputSpecifications.Count);
 }