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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:27:02+00:00 2026-06-13T10:27:02+00:00

I am trying out Moq, and I’ve gotten stuck in a very basic example.

  • 0

I am trying out Moq, and I’ve gotten stuck in a very basic example. I want to mock a very simple interface IInput:

namespace Example
{
    public interface IInput
    {
        int SomeProperty { get; set; }
    }
} 

This seems like a very easy job. However, I get a compilation error when I try to mock it in the following test code:

using Moq;
using NUnit.Framework;

namespace FirstEniro._Test
{

    [TestFixture]
    class TestFirstClass
    {
        [Test]
        public void TestConstructionOk()
        {
            var mock = new Mock<IInput>();
            mock.Setup(r => r.SomeProperty).Returns(3);

            var x = new FirstClass(mock);

            Assert.That(x, Is.EqualTo(3));
        }
    }
}

The compiler says “cannot convert from Moq.Mock<Example.IInput> to <Example.IInput>.
I can’t see what I am doing wrong. Please help me

  • 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-13T10:27:04+00:00Added an answer on June 13, 2026 at 10:27 am

    Use Object property of mock to retrieve instance of mocked object.

       var x = new FirstClass(mock.Object);
    

    In Moq framework Mock is not an instance of what you are mocking (like in Rhino Mocks).

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

Sidebar

Related Questions

I'm trying to work out how this Mock (using the Moq framework) stuff all
I am trying to mock out my Repository with Moq. I am trying to
Trying out the example usage of codebrew rails-backbone , everything works fine but the
I am new to mocking and trying out moq for the first time. I
I am trying out the MOQ framework and up now I have hit a
Im trying out an example with EJB Session Beans. I wanna see the differences
Am trying out an example app using UITableView. The upper (nearly) half of the
Am trying out Ruby on Rails in Windows XP using the Hello World example.
I'm trying to mock an method to a third-party library using moq. The problem
Just trying out scrapy and trying to get a basic spider working. I know

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.