Archives

Archives / 2003 / April
  • Who Needs VB.NET Macros?

    Prototyping addins can be frustrating. If you don't fancy learning VB.NET just to write macros, you're forced to work with a full blown addin. This is anoying if all you want is a quick spelunk inside the VS automation model. This is why I've added another test target. If you select 'Run With... VS.NET', your tests will run inside the current VS.NET process. I've made the DTE object accessable using AppDomain.Current.GetData("DTE").

     

    The following code will list all documents open inside the current  instance of VS.  Just make sure you select 'Run With... VS.NET'.  Have fun...

    using System;

    using System.Diagnostics;

    using EnvDTE;

     

    public class TestDTE

    {

    public void TestDocuments()

    {

    _DTE dte = (_DTE)AppDomain.CurrentDomain.GetData("DTE");

    Documents documents = dte.Documents;

    for(int count = 0 ; count < documents.Count ; count++)

    {

    Document document = documents.Item(count + 1);

    Debug.WriteLine(document.FullName);

    }

    }

    }

    You can download the latest version here. There's now a new releases rss feed!

    Read more...

  • Code 2 Html

    Nauman Leghari writes "I am looking for an addin which can convert code to html from the VS.NET IDE".  I've been thinking about this recently too.  It would be easy to adapt the NUnitAddin code to do this.  Look for AddControl("Code Window", 3) in the source.  You could use the SgmlReader to filter the code (after copying it to the clipboard).  It does copy as a kind of HTML, but with lots of horrible Office and style tags (look the the HTML of any if the snippets I have posted).

    BTW version 0.5 of NUnitAddin is out.

    Read more...

  • Good News / Bad News

    The good news is the the first major release of NUnitAddin for quite some time is out (version 0.5 build 105).  The bad news is that it only works if the .NET Framework 1.1 is installed.  It works with VS.NET 2002 and 2003, but only if 1.1 is there.  So far the issue has defeated me.  It looks like a NullReferenceException is being thrown deep in the bowels of .NET Remoting.  The exception is being thrown by the NUnitAddin.TestRunner.Server program.  If anyone can find the problem I would be hugely grateful.  You can set a breakpoint in the source and use the new 'Run With... Debugger' feature to step into the offending code.  Good luck... ;)

    Here are some quick notes on Ad Hoc ASP.NET testing...

    After you’ve installed the addin, the assembly that defines the attributes can be found here...

    Program Files\NUnit Addin\NUnitAddin.TestRunner.Web\NUnitAddin.TestRunner.Web.dll

    Once you’ve linked to that, define an .aspx file with a code behind that looks something like following.  You should then be able to right click and ‘Run Test(s)’ anywhere in the white space inside the 'test()' method.

    using NUnitAddin.TestRunner.Web;

    [Page("Test.aspx")]
    public class Test : System.Web.UI.Page
    {
       
    private void Page_Load(object sender, System.EventArgs e)
        {
            Debug.WriteLine("Page_Load");
        }

        [Query("name=value"), Event("PreRender")]
       
    private void test()
        {
            Debug.WriteLine("debug output...");
            Debug.Assert(Request.QueryString["name"] == "value");
        }

        #region Web Form Designer generated code
    }

    Each code behind class you want to test must have a Page attribute on the class.  The Query and Event attributes are optional and can appear on either the class or the test methods.  Once you’ve done this you can right click and run methods.  You can also right click and run inside the class but outside of any methods.  This will render the page, sending any exceptions to the test window.

    You’ll find the test runner modifies the ‘Web.config’ file when the test is run.  This is to add a custom IHttpModule (to do the interception).  This is what the VS.NET warning about a file changing is about.  I need to find a fix for this.

    Let me (and the rest of the world ;) know how you get on.

    PS. A lot has changed in the 0.5 release.  Don't be surprised if there is the odd issue (but please tell me about it).  The latest 0.4 build is pretty stable, but doesn’t have any of the ASP.NET testing features.

    Read more...

  • Blogmarks & .NETWeblog Future

    Scott made a post about the future of .NETWeblogs and a possible moderated feed.  I agree the main feed is too noisy.  There's just too much stuff.  If I read every single post I wouldn't get any work done.  I don't know if you saw, but I posted about a possible way to tackle the problem...  Blogmarks

    This feature would have a dual purpose.  It would allow me to mark posts for future reference.  It would also be a way to catagorize and signal what I think is of interest.  It could work in much the same way as Edit Links/Categories works at the moment.  Each post would have a blogmark link which would take you strait there.

    With all of this information, the TiVo like possibilities are endless (people who blogmarked this also blogmarked that).  But even the simple case of being able to subscribe to someone's blogmarks would be great!  With that you've got your moderated feed.  You could be more democratic and have a feed of the most blogmarked.

    Why should Scott have all the fun?  ;)  The good thing about blogging is that it's nonhierarchical and reputation based.  I think blogmarks would be a logical extension to this.

    Read more...

  • Command Line Parsing with XmlSerializer

    Duncan Mackenzie commented about a command line switch parser he found. Has anyone thought of doing command line parsing using (my current favorite class) the XmlSerializer? The code that follows can handle strings, ints, uints, bools, enums and arrays. Best of all it's only a page of code!  The code you are about to see was designed using Ad Hoc tests.  The '_verbose' category is a hint to dump the object's fields and properties.  You can find more information about point and click testing here.

    
    

    using System;

    using System.IO;

    using System.Xml;

    using System.Xml.Serialization;

    using System.Diagnostics;

    using System.Text.RegularExpressions;

    public class ComandLineParser

    {

    public static void TestParse()

    {

    string[] args = {"/one:111", "/two:xxx", "/two:yyy",

    "T H R E E", "/choice:Yes"};

    StringWriter writer = new StringWriter();

    XmlWriter xmlWriter = new XmlTextWriter(writer);

    xmlWriter.WriteStartElement("Parsed");

    foreach(string arg in args)

    {

    Match match = Regex.Match(arg, @"/(?<name>.+):(?<val>.+)");

    if(match.Success)

    {

    string name = match.Groups["name"].Value;

    string val = match.Groups["val"].Value;

    xmlWriter.WriteElementString(name, val);

    }

    else { xmlWriter.WriteString(arg); }

    }

    xmlWriter.WriteEndElement();

    StringReader reader = new StringReader(writer.ToString());

    XmlSerializer ser = new XmlSerializer(typeof(Parsed));

    Parsed parsed = (Parsed)ser.Deserialize(reader);

     

    Debug.WriteLine(parsed, "_verbose");

    Debug.Assert(parsed.one == 111);

    Debug.Assert(parsed.two[0] == "xxx");

    Debug.Assert(parsed.two[1] == "yyy");

    Debug.Assert(parsed.three == "T H R E E");

    Debug.Assert(parsed.choice == Choice.Yes);

    }

     

    public class Parsed

    {

    [XmlElement] public int one;

    [XmlElement] public string[] two;

    [XmlText] public string three;

    public Choice choice;

    }

    public enum Choice { No, Yes }

    }

    I've written a similar utility class that handles urls and query strings. This basically means you can reference pages in your site using custom url classes. It seems to work really well.

    Read more...

  • Testing ASP.NET Pages

    I've been working on getting ad hoc tests working with ASP.NET.  In order to work, the code behind class must be annotated with several attributes.  They let the test runner know which page to render, what query string to use and when to run the test.  The test can be run during any page event (Init, Load, DataBinding, PreRender etc.).  For example, say you right click on and run the following 'test()' method....

    [Page("Test.aspx")]

    public class Test : System.Web.UI.Page

    {

    private void Page_Load(object sender, System.EventArgs e)

    {

    Debug.WriteLine("Page_Load");

    }

     

    [Query("name=value"), Event("PreRender")]

    private void test()

    {

    Debug.WriteLine("debug output...");

    Debug.Assert(Request.QueryString["name"] == "value");

    }

     

    #region Web Form Designer generated code

    }

    The following would appear in the test output window...

    ------ Test started: Assembly: TestWebProject.dll ------

    Page_Load
    debug output...
    file:///C:/CVSHOME/NUnitAddin/TestWebProject/Test.aspx.htm

    1 succeeded, 0 failed, 0 skipped, took 0.00 seconds.

    ---------------------- Done ----------------------

    I would be interested to know how people are testing their ASP.NET pages today. I'm also open to suggestions as to how this feature should work. At the moment it's just for individual ad hoc tests. I'm wondering how to enable it for whole test suites. Drop me a line if you have any suggestions or would like to play with the latest revision (I'm afraid a build still isn't up).

    P.S.  I'm still looking for someone to help test the Mono & Rotor support.  I need someone to go though the configuration procedure to flush out any issues.  Does anyone fancy a play with Mono?  ;o)

    Read more...

  • Mono & Rotor

    My internet connection has been down for going on a week.  On the plus side I've managed to get loads of work done on NUnitAddin. Here is a screen grab I took a number of days ago. As you can see I have finally got support for Mono working! It was an up hill battle, but it's finally done. Unfortunately it isn't checked into CVS yet and there isn't a build up on SourceForge. So much has changed it is going to take me a while to check everything back in. If you're impatient, drop me a line and I'll send you the latest revision. If fact, I’d appreciate anyone willing to do some alpha testing.

    Read more...

  • Blogmarks

    As blog entries fly past, I often find myself wanting to mark them for future reference.  When I first started blogging I used to copy them verbatum into my blog.  I used my blog as a kind of online scrap book.  There is so much activity here, I feel it would be a bit antisocial to do that.  I'm left loosing all of the interesting entries I don't have time to comment on.

    What I think would be useful is an option to blogmark any entry on dotnetweblogs.  These entries would be associated with my blog, for me (or anyone else) to look back on.  It would also be interesting to see a list of the most blogmarked entries.  It would be a collection of all the stuff people think is worth remembering.

    What do you reckon?  If you're watching Scott, any chance of getting this feature in?

    Read more...