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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:55:28+00:00 2026-05-14T15:55:28+00:00

I have a class API which has full code coverage and uses DI to

  • 0

I have a class API which has full code coverage and uses DI to mock out all the logic in the main class function (Job.Run) which does all the work.

I found a bug in production where we werent doing some validation on one of the data input fields.

So, I added a stub function called ValidateFoo()… Wrote a unit test against this function to Expect a JobFailedException, ran the test – it failed obviously because that function was empty. I added the validation logic, and now the test passes.

Great, now we know the validation works. Problem is – how do I write the test to make sure that ValidateFoo() is actually called inside Job.Run()? ValidateFoo() is a private method of the Job class – so it’s not an interface…

Is there anyway to do this with NMock2.0? I know TypeMock supports fakes of non interface types. But changing mock libs right now is not an option. At this point if NMock can’t support it, I will simply just add the ValidateFoo() call to the Run() method and test things manually – which obviously I’d prefer not to do considering my Job.Run() method has 100% coverage right now. Any Advice? Thanks very much it is appreciated.

EDIT: the other option I have in mind is to just create an integration test for my Job.Run functionality (injecting to it true implementations of the composite objects instead of mocks). I will give it a bad input value for that field and then validate that the job failed. This works and covers my test – but it’s not really a unit test but instead an integration test that tests one unit of functionality…. hmm..

EDIT2: IS there any way to do tihs? Anyone have ideas? Maybe TypeMock – or a better design?

  • 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-14T15:55:28+00:00Added an answer on May 14, 2026 at 3:55 pm

    The current version of NMock2 can mock concrete types (I don’t remember exactly which version they added this, but we’re using version 2.1) using the mostly familiar syntax:

    Job job = mockery.NewMock<Job>(MockStyle.Transparent);
    Stub.On(job).Method("ValidateFoo").Will(Return.Value(true));
    

    MockStyle.Transparent specifies that anything you don’t stub or expect should be handled by the underlying implementation – so you can stub and set expectations for methods on an instance you’re testing.

    However, you can only stub and set expectations on public methods (and properties), which must also be virtual or abstract. So to avoid relying on integration testing, you have two options:

    • Make Job.ValidateFoo() public and virtual.
    • Extract the validation logic into a new class and inject an instance into Job.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a third party api, which has a class that returns an enumerator
I'm working with LastFM api, let's say I have a class called Artist which
I have a UserForm class which has a select list populated from a related
I have an DataMapper class which has some private and public methods. The DataMapper
i have following problem: I have a class Foo which encapsulates a web-api. the
In my class I have an assignment to create a Number class, which has
I'm writing a addin for outlook which has some network code for API calls,
I have a problem when serializing inherited objects in Web API. [DataContract] public class
I have class Building in which i have one class member NSMutableArray *subnode.I have
I have Class which Extends View I'm able To Move one Image Over another

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.