Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A COM type can't make its mock by same procedure as usual. #215

Closed
urasandesu opened this issue Nov 15, 2015 · 5 comments
Closed

A COM type can't make its mock by same procedure as usual. #215

urasandesu opened this issue Nov 15, 2015 · 5 comments

Comments

@urasandesu
Copy link
Contributor

It seems that any COM types can't make its mock by same procedure as usual. In Moq 4.2.1510.2205, it will throw MissingMethodException even if the default implementation is automatically generated against a managed type. For example, the product code is the below:

namespace ClassLibrary1
{
    public class Class1
    {
        private Project m_proj;

        public Class1(Project proj)
        {
            m_proj = proj;
        }

        public string Foo()
        {
            return m_proj.Name;
        }
    }
}

NOTE: Project is a COM type in Microsoft Development Environment.

The test code is the below:

namespace ClassLibrary1Test
{
    [TestFixture]
    public class Class1Test
    {
        [Test]
        public void Foo_should_return_null()
        {
            // Arrange
            var m = new Mock<Project>();
            var class1 = new Class1(m.Object);

            // Act
            var result = class1.Foo();

            // Assert
            Assert.IsNull(result);
        }
    }
}

When running the test, I got the following results:

PM> .\packages\nunit.Runners.2.6.4\tools\nunit-console.exe .\ClassLibrary1Test\bin\Debug\ClassLibrary1Test.dll /framework:v4.5
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment - 
   OS Version: Microsoft Windows NT 6.2.9200.0
  CLR Version: 2.0.50727.8000 ( Net 3.5 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: v4.5
.F
Tests run: 1, Errors: 1, Failures: 0, Inconclusive: 0, Time: 1.0892956 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Errors and Failures:
1) Test Error : ClassLibrary1Test.Class1Test.Foo_should_return_null
   System.MissingMethodException : Error: Missing method 'instance string [ClassLibrary1] EnvDTE.Project::get_Name()' from class 'Castle.Proxies.ProjectProxy'.
   at EnvDTE.Project.get_Name()
   at ClassLibrary1.Class1.Foo() in c:\Users\Akira\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1\Class1.cs:line 16
   at ClassLibrary1Test.Class1Test.Foo_should_return_null() in c:\Users\Akira\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1Test\Class1.cs:line 19

Is this a bug? Or, does Moq manage a COM type by special way?(It is the limitation by the design?)

@kzu
Copy link
Contributor

kzu commented Nov 15, 2015

This looks like a Castle DynamicProxy issue. Mock doesn't have its own
proxy generation. Could you check with them please?

On Sun, Nov 15, 2015, 4:04 AM Akira Sugiura notifications@github.com
wrote:

It seems that any COM types can't make its mock by same procedure as
usual. In Moq 4.2.1510.2205, it will throw MissingMethodException even if
the default implementation is automatically generated against a managed
type. For example, the product code is the below:

namespace ClassLibrary1
{
public class Class1
{
private Project m_proj;

    public Class1(Project proj)
    {
        m_proj = proj;
    }

    public string Foo()
    {
        return m_proj.Name;
    }
}

}

NOTE: Project is a COM type in Microsoft Development Environment
https://msdn.microsoft.com/en-us/library/envdte.project.aspx.

The test code is the below:

namespace ClassLibrary1Test
{
[TestFixture]
public class Class1Test
{
[Test]
public void Foo_should_return_null()
{
// Arrange
var m = new Mock();
var class1 = new Class1(m.Object);

        // Act
        var result = class1.Foo();

        // Assert
        Assert.IsNull(result);
    }
}

}

When running the test, I got the following results:

PM> .\packages\nunit.Runners.2.6.4\tools\nunit-console.exe .\ClassLibrary1Test\bin\Debug\ClassLibrary1Test.dll /framework:v4.5
NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment -
OS Version: Microsoft Windows NT 6.2.9200.0
CLR Version: 2.0.50727.8000 ( Net 3.5 )

ProcessModel: Default DomainUsage: Single
Execution Runtime: v4.5
.F
Tests run: 1, Errors: 1, Failures: 0, Inconclusive: 0, Time: 1.0892956 seconds
Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0

Errors and Failures:1) Test Error : ClassLibrary1Test.Class1Test.Foo_should_return_null
System.MissingMethodException : Error: Missing method 'instance string [ClassLibrary1] EnvDTE.Project::get_Name()' from class 'Castle.Proxies.ProjectProxy'.
at EnvDTE.Project.get_Name()
at ClassLibrary1.Class1.Foo() in c:\Users\Akira\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1\Class1.cs:line 16
at ClassLibrary1Test.Class1Test.Foo_should_return_null() in c:\Users\Akira\Documents\Visual Studio 2013\Projects\ClassLibrary1\ClassLibrary1Test\Class1.cs:line 19

Is this a bug? Or, does Moq manage a COM type by special way?(It is the
limitation by the design?)


Reply to this email directly or view it on GitHub
#215.

@urasandesu
Copy link
Contributor Author

Hmm, I have never used Castle DynamicProxy... Could anyone report that which DynamicProxy API has issue to Castle Project? I believe that there is someone who knows it in Moq team 😙

@urasandesu
Copy link
Contributor Author

Well, it seems that everyone in Moq team member is busy 😞 I investigated this issue and found out which DynamicProxy API has an issue. I will report the issue to Castle Project after this.

@kzu
Copy link
Contributor

kzu commented Nov 16, 2015

"Everyone on the Moq team" is basically me, and I'm awfully busy with
Xamarin, so it's very much appreciated that you took the time to
investigate.

Thanks

On Mon, Nov 16, 2015, 8:33 AM Akira Sugiura notifications@github.com
wrote:

Well, it seems that everyone in Moq team member is busy [image:
😞] I investigated this issue and found out which
DynamicProxy API has an issue. I will report the issue to Castle Project
https://github.com/castleproject/Core/issues after this.


Reply to this email directly or view it on GitHub
#215 (comment).

@urasandesu
Copy link
Contributor Author

This cause was my project setup mistake. I'm very sorry for taking up your time...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants