Click here to Skip to main content
15,892,965 members
Articles / Programming Languages / C#

How to quickly debug a NUnit test in Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.67/5 (6 votes)
30 Sep 2009CPOL5 min read 46.1K   445   21  
An article on quickly debugging NUnit tests.
//-------------------------------------------------------------------------------------
// <copyright file='CompositeCodeElement.cs' company='Jonno'>
//     Copyright (c) Paul Johnson 2009 (email:paulmichael.johnson@gmail.com)
//     Code is released under The Code Project Open License (CPOL).
// </copyright>
//-------------------------------------------------------------------------------------

namespace Jonno.AddIns.Entities
{
    using System.Collections.Generic;
    using Jonno.Extensions;

    public enum ElementType
    {
        Namespace,
        Import,
        Class,
        Interface,
        Event,
        Constructor,
        Field,
        Property,
        Delegate,
        Enum,
        Method,
        Structure,
        Attribute,
        Parameter,
        Unknown
    }

    public enum AccessType
    {
        Public,
        Protected,
        Private,
        Internal,
        NotApplicable
    }

    public class CompositeCodeElement
    {
        public CompositeCodeElement()
        {
            this.Attributes = new List<string>();
        }

        public string Id { get; set; }

        public AccessType Access { get; set; }

        public ElementType Kind { get; set; }

        public string ParentId { get; set; }

        public int StartAbsoluteCharacterOffset { get; set; }

        public int EndAbsoluteCharacterOffset { get; set; }

        public bool IsShared { get; set; }

        public bool IsConstant { get; set; }

        public string Comment { get; set; }

        public string DocComment { get; set; }

        public string Text { get; set; }

        public string FullName { get; set; }

        public string Name { get; set; }

        public string FullText
        {
            get
            {
                return this.GetFullText();
            }
        }

        private List<string> Attributes { get; set; }

        public void AddAttribute(string attributeText)
        {
            this.Attributes.Add(attributeText);
        }

        public bool HasAttribute(string attributeText)
        {
            return this.Attributes.Contains(attributeText);	
        }

        private string GetFullText()
        {
            if (!string.IsNullOrEmpty(this.DocComment))
            {
                return this.ConvertDocCommentToDisplayString() + this.Text;
            }

            if (!string.IsNullOrEmpty(this.Comment))
            {
                return this.Comment + this.Text;
            }

            return this.Text;
        }

        private string ConvertDocCommentToDisplayString()
        {
            // replace the doc attribute with empty string
            var replaced = this.DocComment.Replace("<doc>", string.Empty);

            replaced = replaced.Left(replaced.IndexOf("\r\n</doc>"));

            // replace all new lines with newline and the "/// " chars
            replaced = replaced.Replace("\r\n", "\r\n/// ");
            
            replaced = replaced + "\r\n";    
            
            return replaced;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
I have over 15 years of development experience, in many different languages, programming styles and platforms. Currently working as a C# coder, and residing in north Herts in the UK. I love lean software development and anything that reduces a grind to leave more time for useful coding!

Comments and Discussions