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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:27:01+00:00 2026-06-11T20:27:01+00:00

I have an abstract class (let’s call it AbstractOutputter ). When I derive from

  • 0

I have an abstract class (let’s call it AbstractOutputter). When I derive from it, I make calls to a protected method in the constructor of the derived class.

AbstractOutputter

public abstract class IOutputter<T>
{
  protected void Write(Func<T, string> output)
  {
   ... 
  }
}

Derived class

public class WotsitOutputter: AbstractOutputter<Wotsit>
{
  public WotsitOutputter()
  {
    Write(x => x.Property1.ToString());
    Write(x => x.Property2.ToString());
  }
}

The pattern is identical to creating validator classes in FluentValidation:

http://fluentvalidation.codeplex.com/

I would like Moq to create me a class deriving from AbstractOutputter, in order to unit test how it responds to various permutations of calls to Write().. I would need to do something like this:

Mock<AbstractOutputter<Wotsit>> mockOutputter = new Mock<AbstractOutputter<Wotsit>>();
// Instruct Moq to make various calls to protected method in constructor of mock class

Is it possible to do this? Can I somehow tell Moq to perform certain actions within the constructor of the proxy it creates? Or will I need to define real classes extending AbstractOutputter just for unit testing?

  • 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-11T20:27:03+00:00Added an answer on June 11, 2026 at 8:27 pm

    I’m going to put this to bed: I conclude that Moq cannot do this.

    In the end I just defined some simple implementations of AbstractOutputter<Wotsit> for the purpose of testing.

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

Sidebar

Related Questions

First suppose that I have an abstract class, let's call it AbstractClass. Suppose public
I have an abstract Base class. Let's call it Animal::Base . module Animal class
I have an abstract class. Let's call it Lifeform. It looks something like: public
I have one abstract class and two implementations. Let's call them ParentAbstract , ParentA
I have a base class and another derived from it. Let's assume, the base
I have one abstract class -let's say myBase. And I want all the classes
Let say I have abstract class called: Tenant and Customer. The tenant in this
Let we have one abstract class: classdef ACalculation < handle methods (Abstract) [result] =
I'm writing some callback implementation in C++. I have an abstract callback class, let's
Let's say I have these class hierarchy : public abstract class Parent { }

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.