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 8168109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:24:43+00:00 2026-06-06T20:24:43+00:00

I have a problem with an integration test I am writing. I need to

  • 0

I have a problem with an integration test I am writing. I need to perform cleanup at the end of the test by removing the categories (from the list of available categories) in Outlook that I have added during the test. I do this as follows for the ‘Filed’ category:

using Microsoft.Office.Interop.Outlook;

var outlookApplication = new Application();
outlookApplication.Session.Categories.Remove("Filed");

This fails to remove the category, but not consistently. When I debug the code it works but not when I run the tests.

UPDATE:
Here’s all the test code:

[TestFixture]
public class BootstrapperTest
{
    private bool containsFiled;
    private bool containsPending;
    private Application outlookApplication = new Application();

    [Test]
    public void CanCreateFiledCategory()
    {
        var bootstrapper = new Bootstrapper();
        bootstrapper.LoadCategoriesIntoOutlook(outlookApplication); 
        var filedCategoryFound = outlookApplication.Session.Categories.Cast<Category>().Any(category => category.Name == "Filed");
        Assert.That(filedCategoryFound, Is.EqualTo(true));
    }

    [Test]
    public void CanCreatePendingCategory()
    {
        var bootstrapper = new Bootstrapper();
        bootstrapper.LoadCategoriesIntoOutlook(outlookApplication); 
        var pendingCategoryFound = outlookApplication.Session.Categories.Cast<Category>().Any(category => category.Name == "Pending");
        Assert.That(pendingCategoryFound, Is.EqualTo(true));
    }

    [SetUp]
    public void Setup()
    {
        containsFiled = DoesCategoryNameExist(outlookApplication.Session.Categories, "Filed");
        containsPending = DoesCategoryNameExist(outlookApplication.Session.Categories, "Pending");
    }

    [TearDown]
    public void TearDown()
    {
        RemoveAllCategoriesFromOutlook();
    }

    private bool DoesCategoryNameExist(Categories categoryList, string categoryName)
    {
        return categoryList.Cast<Category>().Any(category => category.Name == categoryName);
    }

    private void RemoveAllCategoriesFromOutlook()
    {
        var containsFiledNow = DoesCategoryNameExist(outlookApplication.Session.Categories, "Filed");
        var containsPendingNow = DoesCategoryNameExist(outlookApplication.Session.Categories, "Pending");
        if (!containsFiled && containsFiledNow) outlookApplication.Session.Categories.Remove("Filed");
        if (!containsPending && containsPendingNow) outlookApplication.Session.Categories.Remove("Pending");
    }
}

And the method it is testing:

public void LoadCategoriesIntoOutlook(Application outlookApplication)
{
    var categories = outlookApplication.Session.Categories;

    var filedCategoryNameExists = DoesCategoryNameAlreadyExist(categories, FiledCategoryName);
    var pendingCategoryNameExists = DoesCategoryNameAlreadyExist(categories, PendingCategoryName);
    var filedCategoryColourIsUsed = IsCategoryColorAlreadyUsed(categories, FiledCategoryColor);
    var pendingCategoryColourIsUsed = IsCategoryColorAlreadyUsed(categories, PendingCategoryColor);

    if (!filedCategoryNameExists)
    {
        if (filedCategoryColourIsUsed)
        {
            var categoryToBeChangedToFiled =
                    categories.Cast<Category>()
                              .Where(category => category.Color == FiledCategoryColor)
                              .FirstOrDefault();
            categoryToBeChangedToFiled.Name = FiledCategoryName;
        }
        else
        {
            categories.Add(FiledCategoryName, FiledCategoryColor);
        }
    }

    if (!pendingCategoryNameExists)
    {
        if (pendingCategoryColourIsUsed)
        {
            var categoryToBeChangedToPending =
                   categories.Cast<Category>()
                             .Where(category => category.Color == PendingCategoryColor)
                             .FirstOrDefault();
            categoryToBeChangedToPending.Name = PendingCategoryName;
        }
        else
        {
            categories.Add(PendingCategoryName, PendingCategoryColor);
        }
    }
}
  • 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-06-06T20:24:44+00:00Added an answer on June 6, 2026 at 8:24 pm

    You should log whether Categories.Remove is even called (via Trace.TraceInformation()) to see if there is an error in your branch condition when run in non-DEBUG mode. Categories.Remove does work reliably, it must be an error in your condition. If so, you won’t see the logging statements.

    private void RemoveAllCategoriesFromOutlook()
    {
            var containsFiledNow = DoesCategoryNameExist(outlookApplication.Session.Categories, "Filed");
            var containsPendingNow = DoesCategoryNameExist(outlookApplication.Session.Categories, "Pending");
            if (!containsFiled && containsFiledNow) 
            {
                outlookApplication.Session.Categories.Remove("Filed");
                Trace.TraceInformation("Deleted Filed Category!")
            }
            if (!containsPending && containsPendingNow) 
            {
                outlookApplication.Session.Categories.Remove("Pending");
                Trace.TraceInformation("Deleted Pending Category!")
            }
    }
    

    Also, since you create Categories based off of color (see filedCategoryColourIsUsed), containsFiled may return FALSE, even though you created it via rename (Category.Name = "Filed"), not via Categories.Add(). Your issue is that DoesCategoryNameExist does not consider category color during your Setup test fixture. The following Setup() code should correct this problem…

    [SetUp]
    public void Setup()
    {
        containsFiled = DoesCategoryNameExist(outlookApplication.Session.Categories, "Filed") || IsCategoryColorAlreadyUsed(categories, FiledCategoryColor);
        containsPending = DoesCategoryNameExist(outlookApplication.Session.Categories, "Pending") || IsCategoryColorAlreadyUsed(categories, PendingCategoryColor);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with UIWebView delay when the load image from url. In my
So i have a small integration test that houses 5 tests in total. Running
We have been using TeamBuild and test for our continuous integration build for about
I have a test case (it is really an integration test) which logs in
I have two separate integration test files, each with their own context configuration files
i'm having a problem running an integration test through Gallio. The test works fine
I have two very annoying issues with Maven-Eclipse integration, from time to time it
We are migrating our test report data (unit, regression, integration, etc..) from an XML
I'm having problems understanding how latest.integration works. I have an example that is not
I have a strange problem with integrating a ViewController into another ViewController . i

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.