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

  • Home
  • SEARCH
  • 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 73925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:16:40+00:00 2026-05-10T20:16:40+00:00

I have been working on a wrapper for a COM object that can only

  • 0

I have been working on a wrapper for a COM object that can only take and return strings. The interface for the COM object looks like this:

    interface IMapinfo     {         void Do(string cmd);         string Eval(string cmd);     } 

Now I have made classes that wrap up basic functions like so:

    public class Table      {         IMapinfo MI;         public string Name         {             //pass the command to the COM object and get back the name.             get{return MI.Eval('TableInfo(1,1')');}         }      } 

Now I would like to do unit testing on these classes without having to create the real COM object every time,set up the world then run the tests. So I have been looking into using mock objects but I am a little bit confused on how I would use mocking in this situation.

I am planning on using Moq, so I have written this test like this:

        [Test]         public void MockMapinfo()         {             Moq.Mock<Table> MockTable = new Moq.Mock<Table>();             MockTable.ExpectGet(n => n.Name)                 .Returns('Water_Mains');              Table table = MockTable.Object;             var tablename = table.Name;              Assert.AreEqual('Water_Mains', tablename,string.Format('tablename is {0}',tablename));             Table d = new Table();          } 

Is this the correct way to mock my COM object? How does this verity that the string getting sent to the eval function is correct? or am I doing it all wrong?

  • 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. 2026-05-10T20:16:41+00:00Added an answer on May 10, 2026 at 8:16 pm

    Is this a duplicate? How would I do TDD with a COM OLE object

    EDIT: Looks like you’re asking the same question, but to validate your mocking code (OOPS).

    You’re not quite there for your mocking scenario. You’re in the right that you want to isolate external dependencies, and your COM object certainly meets that criteria. Though I’m not a moq guy (I prefer RhinoMocks) the idea behind mocks is interaction testing…

    Interaction testing is about how cohesive sets of objects work together. A valid test in this scenario would be to write a test for the component that is dependent on your COM object’s behavior.

    In this case, your ‘Table’ which acts like a wrapper for your COM object, is also dependent on the COM object’s behavior. For argument sake, let’s say your Table object performs custom logic against the values that are returned from your COM object.

    Now you can write isolated tests for your Table object while simulating your COM object’s behavior using Mocks.

    public class Table {    public Table(IMapInfo map)    {       _map = map;    }     public string Name    {       get        {         string value = _map.Eval('myexpression');         if (String.IsNullOrEmpty(value))         {             value = 'none';         }         return value;       }    }     private IMapInfo _map; }  [TestFixture] public class TableFixture // is this a pun? {    [Test]    public void CanHandleNullsFromCOM()    {        MockRepository mocks = new MockRepository(); // rhino mocks, btw        IMapInfo map = mocks.CreateMock<IMapInfo>();         using (mocks.Record())        {           Expect.Call(map.Eval('myexpression').Return(null);        }         using (mocks.PlayBack())        {           Table table = new Table(map);           Assert.AreEqual('none', table.Name, 'We didn't handle nulls correctly.');        }         mocks.verify();    } } 

    Maybe your COM object throws exceptions when it’s called, or maybe it doesn’t handle string expressions very well. We’re actually testing how our Table object interacts with the IMapInfo without being tied to the COM object’s implementation. We’re also enforcing a relationship between Table and IMapInfo in that the IMapInfo object must be called during the test.

    Hope this helps.

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

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think that you are deleting your array elements by… May 12, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer No, without optimization ... int main() { int i; int… May 12, 2026 at 5:31 pm
  • Editorial Team
    Editorial Team added an answer You want to look at the Adorner Framework of WPF.… May 12, 2026 at 5:31 pm

Related Questions

I have been trying to figure out how to retrieve (quickly) the number of
I've been working on a code generater for my projects and, while all has
I have been working a year now as a software developer for a at
Hej there, I am currently working on a PHP-based Tool to monitor a rather

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.