Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6679471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:47+00:00 2026-05-26T04:21:47+00:00

I am writing a custom language colorizer as a Visual Studio extension using MEF.

  • 0

I am writing a custom language colorizer as a Visual Studio extension using MEF. Most of my code comes from the Ook Language Integration sample that is available here. My colorizer is pretty much ready, but now I need to provide an appropriate unit test suite for my implementation.

Given the MEF nature of this stuff, I wonder which is the appropriate approach to unit testing. Should I just directly reference my Tagger from my unit test and test the GetTags method? Should I involve MEF in my unit tests? Are there any examples out there about testing MEF based colorizers and custom Intellisense implementations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:21:48+00:00Added an answer on May 26, 2026 at 4:21 am

    OK, so I think I got an approach to do this. Don’t know if it is the ideal approach, but allows me to test my core logic. The credits go to the guys behind the HQL Language Service for Visual Studio who showed me how to create stubs for ITextSnapshots and to Noah Richards whose Spell Checker extension has as set of unit tests that set the scenario for my ones.

    Here the code for my TestFixture:

    [TestFixture]
    public class TokenTaggerTests
    {
      [Test]
      public void CanGetTagsForSimpleSelect()
      {
        TestQuery("SELECT * FROM Books", new List<string>() { "SELECT", "*", "FROM", "Books"});      
      }
    
      private void TestQuery(string query, List<string> expected)
      {
        ITextSnapshot snapshot = SnapshotUtil.CreateSnapshot(query);
        NormalizedSnapshotSpanCollection spans = new NormalizedSnapshotSpanCollection(snapshot.CreateSpanFromLineNumber(0));
    
        MyTokenTagProvider provider = new MyTokenTagProvider();
        ITagger<ITag> tagger = provider.CreateTagger<ITag>(new Mock<ITextBuffer>().Object);
    
        List<string> words = tagger.GetTags(spans).Select(s => query.Substring(s.Span.Start, s.Span.Length)).ToList();
    
        string errorMessage = string.Format("Got list: [{0}].  Expected: [{1}]", string.Join(", ", words), string.Join(", ", expected));
    
        CollectionAssert.AreEqual(expected, words, errorMessage);
      }
    }
    

    In the TestQuery method I start by calling CreateSnapshot on SnapshotUtil. That is a useful class, found in the HQL Language Service test project that would create ITextSnapshot objects based on some input text, which simulates what VS would provide to my extension. Then I go and use MyTokenTagProvider to create a tagger for me. Here I use this powerful thing called Moq to create a Mock of an ITextBuffer object, which is the expected input parameter for CreateTagger.

    Now that we have a tagger, the rest is just playing around with it to check if it is doing the job. GetTags is the core method I want to test here, as it is the one that will take my input query and output the series of tags it was able to identify. To get the actual words, we examine each tag’s span and use it to extract the word from the original query. The CollectionAssert method of NUnit will make sure the output list of words matches the expected list.

    Hopefully this is useful for anybody else out there creating and testing VS editor extensions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When it comes to writing custom MySQL database-driven PHP session management for a VERY
I'm considering writing my own delivery code using PowerShell and/or C#, maybe shelling to
I am writing custom code to create a blog. I need the archives page
I'm writing custom security attribute and got strange compiler behaviour... When I'm using the
I am implementing Code Generation for WindowsForm control at Design-Time, using a Custom CodeDomSerializer.
I'm writing a linux shell for a custom scripting language, and I want to
I'm currently writing an Eclipse text editor plugin for a custom language. The problem
I am using NSPasteboardWriting protocol for writing custom object on NSPasteboard. How to create
I am writing custom code in my report and in it I need a
When writing a custom server, what are the best practices or techniques to determine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.