Esempio n. 1
0
        /// <summary>
        /// Check whether the filename of the assembly that caused the failure
        /// is part of the build failure message.
        /// </summary>
        public void Test_AssemblyLoadFailure()
        {
            string tempFile = CreateTempFile("test.dll");

            const string _xml = @"
                <project name='foo'>
                    <loadtasks path='{0}' />
                </project>";

            try {
                RunBuild(string.Format(CultureInfo.InvariantCulture, _xml,
                                       tempFile));
                Assert.Fail("LoadTasks should have failed");
            } catch (TestBuildException e) {
                if (!(e.InnerException is BuildException))
                {
                    Assert.Fail("Incorrect exception type !");
                }
                else
                {
                    BuildException buildError = (BuildException)e.InnerException;
                    Assert.IsTrue(buildError.Message.IndexOf("test.dll") != -1,
                                  "Assembly causing failure is not part of message.");
                }
            }
        }
Esempio n. 2
0
            public void Catch(BuildException be)
            {
                bool   propertyExists        = false;
                string originalPropertyValue = null;

                if (Property != null)
                {
                    propertyExists               = Project.Properties.Contains(Property);
                    originalPropertyValue        = Project.Properties[Property];
                    Project.Properties[Property] = be.RawMessage;
                }

                try {
                    Execute();
                } finally {
                    if (Property != null)
                    {
                        if (!propertyExists)
                        {
                            // if the property did not exist, then remove it again
                            Project.Properties.Remove(Property);
                        }
                        else
                        {
                            // restore original value
                            Project.Properties[Property] = originalPropertyValue;
                        }
                    }
                }
            }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Sets a single environment variable.
        /// </summary>
        /// <param name="variableName">Name of the variable.</param>
        /// <param name="value">The value.</param>
        /// ------------------------------------------------------------------------------------
        private void SetSingleEnvironmentVariable(string variableName, string value)
        {
            Log(Level.Verbose, "Setting environment variable {0} to {1}",
                variableName, value);

            // expand any env vars in value
            string expandedValue = Environment.ExpandEnvironmentVariables(value);

            bool fSuccess = SetEnvironmentVariable(variableName, expandedValue);

            if (fSuccess && m_fGlobal)
            {
                m_VariablesToSet.Add(string.Format("\"{0}={1}\"", variableName, expandedValue));
            }

            if (!fSuccess)
            {
                int    nError = Marshal.GetLastWin32Error();
                string msg    = string.Format("Error {0} setting environment variable {1}",
                                              nError, variableName);
                if (FailOnError)
                {
                    BuildException ex = new BuildException(msg, Location);
                    ex.Data.Add("Name", variableName);
                    throw ex;
                }

                Log(Level.Info, msg);
            }
        }
Esempio n. 4
0
        protected override void ExecuteTask()
        {
            string result = null;

            try {
                this.ExecuteS3Task();
                result = null;                 // No news is good news
            } catch (Exception ex) {
                BuildException buildEx = ex as BuildException;
                if (buildEx != null)
                {
                    this.SetResultProperty(buildEx.Message);
                    throw;
                }
                AmazonS3Exception awsEx = ex as AmazonS3Exception;
                result = awsEx != null ? awsEx.ErrorCode : ex.Message;
                if (string.IsNullOrEmpty(result))
                {
                    result = "Exception thrown: " + ex.GetType().FullName;
                }
            }

            this.SetResultProperty(result);
            if (!string.IsNullOrEmpty(result) && this.FailOnError)
            {
                throw new BuildException(result);
            }
            if (!string.IsNullOrEmpty(result))
            {
                this.Log(Level.Error, result);
            }
        }
        public void CanBeSerializedAndDeserializedTest()
        {
            var message = Guid.NewGuid().ToString();
            var targetType = typeof(Person);
            var referenceName = Guid.NewGuid().ToString();
            var context = new Company();
            var buildLog = Guid.NewGuid().ToString();
            var inner = new TimeoutException();
            var formatter = new BinaryFormatter();

            var target = new BuildException(message, targetType, referenceName, context, buildLog, inner);

            using (var ms = new MemoryStream())
            {
                formatter.Serialize(ms, target);
                ms.Seek(0, SeekOrigin.Begin);

                var outputException = formatter.Deserialize(ms) as BuildException;

                outputException.Message.Should().Be(message);
                outputException.TargetType.Should().Be(targetType);
                outputException.ReferenceName.Should().Be(referenceName);
                outputException.Context.Should().BeNull();
                outputException.BuildLog.Should().Be(buildLog);
                outputException.InnerException.Message.ShouldBeEquivalentTo(inner.Message);
            }
        }
Esempio n. 6
0
        public void Test_NonExistingFile()
        {
            const string projectXML = @"<?xml version='1.0'?>
                <project>
                    <zip zipfile='test.zip'>
                        <fileset prefix='bin'>
                            <include name='whatever/test.txt' asis='true' />
                        </fileset>
                    </zip>
                </project>";

            try {
                RunBuild(projectXML);
                Assert.Fail("#1");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex.InnerException, "#2");
                Assert.IsTrue(ex.InnerException is BuildException, "#3");
                Assert.IsNotNull(ex.InnerException.InnerException, "#4");
                Assert.IsTrue(ex.InnerException.InnerException is BuildException, "#5");

                BuildException be = (BuildException)ex.InnerException.InnerException;
                // error message should contain path of file that does not exist
                Assert.IsTrue(be.RawMessage.IndexOf("whatever/test.txt") != -1, "#6");
            }
        }
 /// <summary>
 /// Sets the currently executed task.
 /// </summary>
 /// <param name="value">The currently executed task.</param>
 public static void SetCurrentTask(Task value)
 {
   currentTask = value;
   lock (LastExceptionLock)
   {
     lastException = null;
   }
 }
Esempio n. 8
0
        public void CanCreateWithMessage()
        {
            var message = Guid.NewGuid().ToString();

            var sut = new BuildException(message);

            sut.Message.Should().Be(message);
        }
Esempio n. 9
0
        public void CanCreateWithMessageAndException()
        {
            var message = Guid.NewGuid().ToString();
            var inner   = new TimeoutException();

            var sut = new BuildException(message, inner);

            sut.Message.Should().Be(message);
            sut.InnerException.Should().Be(inner);
        }
Esempio n. 10
0
        public void CanCreatesWithDefaultValues()
        {
            var sut = new BuildException();

            sut.BuildLog.Should().BeNull();
            sut.Message.Should().NotBeNullOrWhiteSpace();
            sut.InnerException.Should().BeNull();
            sut.TargetType.Should().BeNull();
            sut.Context.Should().BeNull();
        }
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var bm = new BuildException(HttpContext.Current, actionExecutedContext.Exception, actionExecutedContext.Request.ToString());

            _mExeption = bm.ModelException();

            WriteLog.Write(_logFolder, _mExeption.ToString());

            base.OnException(actionExecutedContext);
        }
        public void BuildFailureAppendsLogEntryTest()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var target = new DefaultBuildLog();

            target.BuildFailure(ex);

            target.Output.Should().Contain(ex.ToString());
        }
        public void CanCreatesWithDefaultValuesTest()
        {
            var target = new BuildException();

            target.BuildLog.Should().BeNull();
            target.Message.Should().NotBeNullOrWhiteSpace();
            target.InnerException.Should().BeNull();
            target.TargetType.Should().BeNull();
            target.Context.Should().BeNull();
        }
Esempio n. 14
0
        public void BuildFailureDoesNotWriteLogWhenDisabled()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var sut = new DefaultBuildLog();

            sut.BuildFailure(ex);

            sut.Output.Should().BeEmpty();
        }
Esempio n. 15
0
        public void BuildFailureAppendsLogEntry()
        {
            var ex = new BuildException(Guid.NewGuid().ToString());

            var sut = new DefaultBuildLog {
                IsEnabled = true
            };

            sut.BuildFailure(ex);

            sut.Output.Should().Contain(ex.ToString());
        }
Esempio n. 16
0
        public void OneTagWithOnePropertyMissingSecondQuote()
        {
            TagServices tagServices = new TagServices(new BuildHandler());

            //                             11111111112222222222333333333344444444445555555555666666666677777777778888888888999
            //                   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
            string searchText = "some test text <!-- a_tag_name property0=' --> and some more text";
            string tagName    = "a_tag_name";

            BuildException buildException = Assert.Throws <BuildException>(() => { tagServices.ExtractTags(searchText, tagName, false); });

            // Check result
            Assert.AreEqual("Missing second single quote", buildException.Message);
        }
        public void OneTagNotClosed()
        {
            TagServices tagServices = new TagServices(new BuildHandler());

            //                             11111111112222222222333333333344444444445555555555666666666677777777778888888888999
            //                   012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012
            string searchText = "some test text <!-- a_tag_name_START -->some content<!-- a_tag_name_ZEND --> and some more text";
            string tagName    = "a_tag_name";

            BuildException buildException = Assert.Throws <BuildException>(() => { tagServices.ExtractTags(searchText, tagName, true); });

            // Check result
            Assert.AreEqual("Missing end tag", buildException.Message);
        }
Esempio n. 18
0
        public void OneTagMissingCommentEnd()
        {
            TagServices tagServices = new TagServices(new BuildHandler());

            //                             1111111111222222222233333333334444444444555
            //                   01234567890123456789012345678901234567890123456789012
            string searchText = "some test text <!-- a_tag_name and some more text";
            string tagName    = "a_tag_name";

            BuildException buildException = Assert.Throws <BuildException>(() => { tagServices.ExtractTags(searchText, tagName, false); });

            // Check result
            Assert.AreEqual(tagName + " tag not closed", buildException.Message);
        }
        public void Test_IfUnknownNode2()
        {
            string buildxml = FormatBuildFile(_format3, "${1==1}");

            try {
                RunBuild(buildxml);
                Assert.Fail("Build should have failed.");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex);
                Assert.IsTrue(ex.InnerException is BuildException);
                BuildException be = (BuildException)ex.InnerException;
                Assert.AreEqual(5, be.Location.LineNumber);
                Assert.IsTrue(be.RawMessage.IndexOf("foo") != -1);
            }
        }
Esempio n. 20
0
        public void CanCreateWithBuildInformation()
        {
            var message       = Guid.NewGuid().ToString();
            var targetType    = typeof(Person);
            var referenceName = Guid.NewGuid().ToString();
            var context       = new Company();
            var buildLog      = Guid.NewGuid().ToString();

            var sut = new BuildException(message, targetType, referenceName, context, buildLog);

            sut.Message.Should().Be(message);
            sut.TargetType.Should().Be(targetType);
            sut.ReferenceName.Should().Be(referenceName);
            sut.Context.Should().Be(context);
            sut.BuildLog.Should().Be(buildLog);
            sut.InnerException.Should().BeNull();
        }
        public void CanCreateWithBuildInformationTest()
        {
            var message = Guid.NewGuid().ToString();
            var targetType = typeof(Person);
            var referenceName = Guid.NewGuid().ToString();
            var context = new Company();
            var buildLog = Guid.NewGuid().ToString();

            var target = new BuildException(message, targetType, referenceName, context, buildLog);

            target.Message.Should().Be(message);
            target.TargetType.Should().Be(targetType);
            target.ReferenceName.Should().Be(referenceName);
            target.Context.Should().Be(context);
            target.BuildLog.Should().Be(buildLog);
            target.InnerException.Should().BeNull();
        }
Esempio n. 22
0
        public void GetChecksum_Path_DoesNotExist()
        {
            string buildFragment =
                "<project>" +
                "   <property name=\"checksum\" value=\"${file::get-checksum('doesnotexist','MD5')}\" />" +
                "</project>";

            try {
                RunBuild(buildFragment);
                Assert.Fail("#1");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex.InnerException, "#2");
                BuildException be = ex.InnerException as BuildException;
                Assert.IsNotNull(be, "#3");
                Assert.AreEqual(typeof(BuildException), be.GetType(), "#4");
                Assert.IsNotNull(be.InnerException, "#5");
                Assert.AreEqual(typeof(FileNotFoundException), be.InnerException.GetType(), "#6");
            }
        }
Esempio n. 23
0
        public void GetChecksum_Algorithm_DoesNotExist()
        {
            string buildFragment =
                "<project>" +
                "   <echo file=\"checksum.input\">test input file</echo>" +
                "   <property name=\"checksum\" value=\"${file::get-checksum('checksum.input','ZZZ')}\" />" +
                "</project>";

            try {
                RunBuild(buildFragment);
                Assert.Fail("#1");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex.InnerException, "#2");
                BuildException be = ex.InnerException as BuildException;
                Assert.IsNotNull(be, "#3");
                Assert.AreEqual(typeof(BuildException), be.GetType(), "#4");
                Assert.IsNotNull(be.InnerException, "#5");
                Assert.AreEqual(typeof(ArgumentException), be.InnerException.GetType(), "#6");
            }
        }
Esempio n. 24
0
        private void CheckDims(Texture2D text, KeyValuePair <int, string> elmnt)
        {
            BuildException inner = null;

            if (text.Width > max.Width)
            {
                inner = new BuildException($"Width is {text.Width}, max width = {max.Width}!");
            }
            if (text.Height > max.Height)
            {
                string msg = $"Height is {text.Height}, max height = {max.Height}!";
                if (inner != null)
                {
                    msg += ", " + inner.Message;
                }
                inner = new BuildException(msg);
            }
            if (inner != null)
            {
                throw new BuildException($"Texture {elmnt.Value}({elmnt.Key}) is to large.", inner);
            }
        }
Esempio n. 25
0
        public void CurrentFramework_Invalid()
        {
            FrameworkInfo invalid = null;

            Project p = CreateEmptyProject();

            foreach (FrameworkInfo framework in p.Frameworks)
            {
                if (!framework.IsValid)
                {
                    invalid = framework;
                    break;
                }
            }

            if (invalid == null)
            {
                Assert.Ignore("Test requires at least one invalid framework.");
            }

            string _xml = @"
                    <project name='PropTests'>
                        <property name='nant.settings.currentframework' value='{0}' />
                    </project>";

            try {
                RunBuild(string.Format(_xml, invalid.Name));
                Assert.Fail("#1");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex.InnerException, "#2");

                // either initialization of the framework failed, or validation
                // failed
                BuildException inner = ex.InnerException as BuildException;
                Assert.IsNotNull(inner, "#3");
                Assert.IsNotNull(inner.InnerException, "#4");
                Assert.IsNotNull(inner.RawMessage, "#5");
            }
        }
Esempio n. 26
0
            public void Catch(BuildException be, TargetCallStack callStack, PropertyAccessor accessor)
            {
                bool   propertyExists        = false;
                string originalPropertyValue = null;

                if (Property != null)
                {
                    propertyExists = accessor.Contains(Property);

                    if (accessor.Contains(Property))
                    {
                        originalPropertyValue = accessor[Property];
                    }

                    accessor[Property] = GetExceptionMessage(be);
                }

                try {
                    Execute(callStack);
                } finally {
                    if (Property != null)
                    {
                        if (!propertyExists)
                        {
                            // if the property did not exist, then remove it again
                            accessor.Remove(Property);
                        }
                        else
                        {
                            // restore original value
                            if (!String.IsNullOrWhiteSpace(originalPropertyValue))
                            {
                                accessor[Property] = originalPropertyValue;
                            }
                        }
                    }
                }
            }
Esempio n. 27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Do the job
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void ExecuteTask()
        {
            try
            {
                if (VariableName != null && Value != null)
                {
                    // add single environment variable
                    EnvironmentVariables.Add(new EnvironmentVariable(VariableName, Value));
                }

                foreach (EnvironmentVariable env in EnvironmentVariables)
                {
                    SetSingleEnvironmentVariable(env.VariableName, env.Value);
                }

                if (m_fGlobal)
                {
                    SetGlobalEnvironmentVariables();
                }
            }
            catch (Exception e)
            {
                BuildException buildEx = e as BuildException;
                if (buildEx != null)
                {
                    throw new BuildException(
                              string.Format("Exception setting environment variable {1}: {0}", e.Message,
                                            buildEx.Data["Name"]), Location, e);
                }
                else
                {
                    throw new BuildException(
                              string.Format("Exception setting environment variables: {0}", e.Message),
                              Location, e);
                }
            }
        }
Esempio n. 28
0
        public void CurrentFramework_NonExisting()
        {
            string _xml = @"
                    <project name='PropTests'>
                        <property name='nant.settings.currentframework' value='doesnotexist' />
                    </project>";

            try {
                RunBuild(_xml);
                Assert.Fail("#1");
            } catch (TestBuildException ex) {
                Assert.IsNotNull(ex.InnerException, "#2");

                string expectedError = "Target framework could not be changed. " +
                                       "\"doesnotexist\" is not a valid framework identifier.";

                BuildException inner = ex.InnerException as BuildException;
                Assert.IsNotNull(inner, "#3");
                Assert.IsNull(inner.InnerException, "#4");
                Assert.IsNotNull(inner.RawMessage, "#5");
                Assert.IsTrue(inner.RawMessage.StartsWith(expectedError),
                              "#6:" + inner.RawMessage);
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Initializes the task and verifies parameters.
        /// </summary>
        protected override void Initialize()
        {
            XmlElement taskXml = (XmlElement)XmlNode.Clone();

            // Expand all properties in the task and its child elements
            if (taskXml.ChildNodes != null)
            {
                ExpandPropertiesInNodes(taskXml.ChildNodes);
                if (taskXml.Attributes != null)
                {
                    foreach (XmlAttribute attr in taskXml.Attributes)
                    {
                        attr.Value = this.PropertyAccessor.ExpandProperties(attr.Value, Location);
                    }
                }
            }

            // Get the [SchemaValidator(type)] attribute
            SchemaValidatorAttribute[] taskValidators =
                (SchemaValidatorAttribute[])GetType().GetCustomAttributes(
                    typeof(SchemaValidatorAttribute), true);

            if (taskValidators.Length > 0)
            {
                SchemaValidatorAttribute taskValidator  = taskValidators[0];
                XmlSerializer            taskSerializer = new XmlSerializer(taskValidator.ValidatorType);

                // get embedded schema resource stream
                Stream schemaStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
                    taskValidator.ValidatorType.Namespace);

                // ensure schema resource was embedded
                if (schemaStream == null)
                {
                    throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                                           "Schema resource '{0}' could not be found.",
                                                           taskValidator.ValidatorType.Namespace), Location);
                }

                // load schema resource
                XmlTextReader tr = new XmlTextReader(
                    schemaStream, XmlNodeType.Element, null);

                // Add the schema to a schema collection
                XmlSchema           schema  = XmlSchema.Read(tr, null);
                XmlSchemaCollection schemas = new XmlSchemaCollection();
                schemas.Add(schema);

                string xmlNamespace = (taskValidator.XmlNamespace != null ? taskValidator.XmlNamespace : GetType().FullName);

                // Create a namespace manager with the schema's namespace
                NameTable           nt    = new NameTable();
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
                nsmgr.AddNamespace(string.Empty, xmlNamespace);

                // Create a textreader containing just the Task's Node
                XmlParserContext ctx = new XmlParserContext(
                    null, nsmgr, null, XmlSpace.None);
                taskXml.SetAttribute("xmlns", xmlNamespace);
                XmlTextReader textReader = new XmlTextReader(taskXml.OuterXml,
                                                             XmlNodeType.Element, ctx);

                // Copy the node from the TextReader and indent it (for error
                // reporting, since NAnt does not retain formatting during a load)
                StringWriter  stringWriter = new StringWriter();
                XmlTextWriter textWriter   = new XmlTextWriter(stringWriter);
                textWriter.Formatting = Formatting.Indented;

                textWriter.WriteNode(textReader, true);

                //textWriter.Close();
                XmlTextReader formattedTextReader = new XmlTextReader(
                    stringWriter.ToString(), XmlNodeType.Document, ctx);

                // Validate the Task's XML against its schema
                XmlValidatingReader validatingReader = new XmlValidatingReader(
                    formattedTextReader);
                validatingReader.ValidationType = ValidationType.Schema;
                validatingReader.Schemas.Add(schemas);
                validatingReader.ValidationEventHandler +=
                    new ValidationEventHandler(Task_OnSchemaValidate);

                while (validatingReader.Read())
                {
                    // Read strictly for validation purposes
                }
                validatingReader.Close();

                if (!_validated)
                {
                    // Log any validation errors that have ocurred
                    for (int i = 0; i < _validationExceptions.Count; i++)
                    {
                        BuildException ve = (BuildException)_validationExceptions[i];
                        if (i == _validationExceptions.Count - 1)
                        {
                            // If this is the last validation error, throw it
                            throw ve;
                        }
                        Log(Level.Info, ve.Message);
                    }
                }

                NameTable           taskNameTable = new NameTable();
                XmlNamespaceManager taskNSMgr     = new XmlNamespaceManager(taskNameTable);
                taskNSMgr.AddNamespace(string.Empty, xmlNamespace);

                XmlParserContext context = new XmlParserContext(
                    null, taskNSMgr, null, XmlSpace.None);

                XmlTextReader taskSchemaReader = new XmlTextReader(
                    taskXml.OuterXml, XmlNodeType.Element, context);

                // Deserialize from the Task's XML to the schema wrapper object
                _schemaObject = taskSerializer.Deserialize(taskSchemaReader);
            }
        }
Esempio n. 30
0
    /// <summary>
    /// Formats the error message and writes it to the build log.
    /// If the build threads aren't executed at the moment, a <see cref="BuildException" /> will be thrown.
    /// </summary>
    /// <param name="currentInstance">The current Task instance which is performing the log.</param>
    /// <param name="innerException">The inner exception.</param>
    /// <param name="format">The format string.</param>
    /// <param name="arguments">The format string arguments.</param>
    public static void LogError(Element currentInstance, Exception innerException, string format, params object[] arguments)
    {
      string logMessage = string.Format(CultureInfo.CurrentCulture, format, arguments);
      currentInstance.Log(Level.Error, logMessage);
      lock (LastExceptionLock)
      {
        BuildException buildException = new BuildException(logMessage, innerException);
        if (buildThreadsActive == false)
        {
          throw buildException;
        }

        if (lastException == null)
        {
          lastException = buildException;
        }
      }
    }
Esempio n. 31
0
            public void Catch(BuildException be)
            {
                bool propertyExists = false;
                string originalPropertyValue = null;

                if (Property != null) {
                    propertyExists = Project.Properties.Contains(Property);
                    originalPropertyValue = Project.Properties[Property];
                    Project.Properties[Property] = be.RawMessage;
                }

                try {
                    Execute();
                } finally {
                    if (Property != null) {
                        if (!propertyExists) {
                            // if the property did not exist, then remove it again
                            Project.Properties.Remove(Property);
                        } else {
                            // restore original value
                            Project.Properties[Property] = originalPropertyValue;
                        }
                    }
                }
            }
Esempio n. 32
0
        public void TestUnexpectedExitCode()
        {
            this.PrepareTestEnvironment();
            // Dictonary with test data. Key: produced exit code, value: expected exit code
            Dictionary <int, int> exitCodes = new Dictionary <int, int>();

            exitCodes.Add(byte.MaxValue, byte.MinValue);

            // Bash supports only exit codes from 0  to 255
            if (PlatformHelper.IsWindows)
            {
                exitCodes.Add(sbyte.MaxValue, sbyte.MinValue);
                exitCodes.Add(short.MaxValue, short.MinValue);
                exitCodes.Add(ushort.MaxValue, ushort.MinValue);
                exitCodes.Add(int.MaxValue, int.MinValue);
            }

            foreach (KeyValuePair <int, int> exitCode in exitCodes)
            {
                ExecTask task = this.CreateTaskWithProject();
                if (PlatformHelper.IsUnix)
                {
                    task.FileName = "bash";
                    task.Arguments.Add(new Argument("-c"));
                    task.Arguments.Add(new Argument("\"exit " + exitCode.Key.ToString(CultureInfo.InvariantCulture) + "\""));
                }
                else
                {
                    task.FileName = @"cmd.exe";
                    task.Arguments.Add(new Argument("/c"));
                    task.Arguments.Add(new Argument("exit"));
                    task.Arguments.Add(new Argument(exitCode.Key.ToString(CultureInfo.InvariantCulture)));
                }

                task.ExpectedExitCode = exitCode.Value;
                BuildException currentBuildException = null;
                try
                {
                    task.Execute();
                }
                catch (BuildException ex)
                {
                    currentBuildException = ex;
                }

                Assert.IsNotNull(currentBuildException);
            }

            foreach (KeyValuePair <int, int> exitCode in exitCodes)
            {
                ExecTask task = this.CreateTaskWithProject();
                if (PlatformHelper.IsUnix)
                {
                    task.FileName = "bash";
                    task.Arguments.Add(new Argument("-c"));
                }
                else
                {
                    task.FileName = @"cmd.exe";
                    task.Arguments.Add(new Argument("/c"));
                }
                task.Arguments.Add(new Argument("exit"));
                task.Arguments.Add(new Argument(exitCode.Value.ToString(CultureInfo.InvariantCulture)));
                task.ExpectedExitCode = exitCode.Key;
                BuildException currentBuildException = null;
                try
                {
                    task.Execute();
                }
                catch (BuildException ex)
                {
                    currentBuildException = ex;
                }

                Assert.IsNotNull(currentBuildException);
            }
        }
        public void CanCreateWithMessageAndExceptionTest()
        {
            var message = Guid.NewGuid().ToString();
            var inner = new TimeoutException();

            var target = new BuildException(message, inner);

            target.Message.Should().Be(message);
            target.InnerException.Should().Be(inner);
        }
        public void GetObjectDataThrowsExceptionWithNullInfoTest()
        {
            var streamingContext = new StreamingContext();

            var target = new BuildException();

            Action action = () => { target.GetObjectData(null, streamingContext); };

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CanCreateWithMessageTest()
        {
            var message = Guid.NewGuid().ToString();

            var target = new BuildException(message);

            target.Message.Should().Be(message);
        }