Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Mocked property still returns actual class
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Anthony Stevens  
View profile  
 More options Dec 1 2008, 11:53 pm
From: Anthony Stevens <anthonyrstev...@gmail.com>
Date: Mon, 1 Dec 2008 20:53:52 -0800 (PST)
Local: Mon, Dec 1 2008 11:53 pm
Subject: Mocked property still returns actual class
Hi - hope someone can help.

I'm creating a custom MSBuild task and want to test the Execute()
method after first mocking out the built-in Log property.  Since Log
isn't virtual, I embedded it in a protected internal virtual property:

protected internal virtual Logger { get { return this.Log; } }

Here's my test:

        [TestMethod]
        public void Execute_1()
        {
            Mock<Microsoft.Build.Utilities.TaskLoggingHelper> log =
new Mock<Microsoft.Build.Utilities.TaskLoggingHelper>(It.IsAny<ITask>
());

            Mock<RestoreDatabase> mock = new Mock<RestoreDatabase>();
            mock.ExpectGet(x => x.Logger).Returns(log.Object);
            mock.CallBase = true;

            mock.Object.Execute();

        }

Execute() calls this.Logger.LogMessage(MessageImportance.Low, "some
message");

I get an exception from the actual TaskLoggingHelper class, indicating
that my mocked log object is not fully mocked out.  When the mocked
log object gets a LogMessage() method call I don't want to pass it
through to the actual TaskLoggingHelper class.

Can anyone advise?

Thanks,

a


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Cazzulino  
View profile  
 More options Dec 3 2008, 5:57 pm
From: "Daniel Cazzulino" <dan...@cazzulino.com>
Date: Wed, 3 Dec 2008 20:57:37 -0200
Local: Wed, Dec 3 2008 5:57 pm
Subject: Re: [Moq] Mocked property still returns actual class

Does your RestoreDatabase use the Logger property?

On Tue, Dec 2, 2008 at 2:53 AM, Anthony Stevens
<anthonyrstev...@gmail.com>wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Anthony Stevens  
View profile  
 More options Dec 4 2008, 10:49 am
From: Anthony Stevens <anthonyrstev...@gmail.com>
Date: Thu, 4 Dec 2008 07:49:17 -0800 (PST)
Local: Thurs, Dec 4 2008 10:49 am
Subject: Re: Mocked property still returns actual class
Of course.  But when called via the test, it runs the actual
TaskLoggingHelper, and not my mocked out version.

a

On Dec 3, 2:57 pm, "Daniel Cazzulino" <dan...@cazzulino.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Cazzulino  
View profile  
 More options Dec 12 2008, 11:21 pm
From: "Daniel Cazzulino" <kzu....@gmail.com>
Date: Sat, 13 Dec 2008 02:21:34 -0200
Local: Fri, Dec 12 2008 11:21 pm
Subject: Re: [Moq] Re: Mocked property still returns actual class

I don't see anywhere that you're setting an expectation on the
Mock<TaskLoggingHelper>
to catch the calls to it...
If LogMessage() is virtual on TaskLoggingHelper, you will be able to mock
it. If it's not, creating a Mock<T> over it won't help.

On Thu, Dec 4, 2008 at 1:49 PM, Anthony Stevens
<anthonyrstev...@gmail.com>wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google