This is a migrated thread and some comments may be shown as answers.

Winform control container mocking

5 Answers 96 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
KenBobPDX
Top achievements
Rank 2
KenBobPDX asked on 29 Nov 2012, 06:52 PM
I am getting the following exception thrown when I attempt to instantiate a class that is a windows form control: 
Method 'OnFrameWindowActivate' on type 'PortalControlProxy+1d48ab8d01e14d88b1961be6f78a21fb' from assembly 'Telerik.JustMock, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8b221631f7271365' is overriding a method that is not visible from that assembly.

The line of code that is causing the exception is: 
PortalControl mockedPortalControl = Mock.Create<PortalControl>(Constructor.Mocked);

The PortalControl is a Winform control. It appears that during instantiation the exception is being thrown.  Any ideas?

Thank you in advance,
Ken

5 Answers, 1 is accepted

Sort by
0
Kaloyan
Telerik team
answered on 30 Nov 2012, 12:00 PM
Hello Kenneth,

Thank you for reaching Telerik support.

In order to help you further, I will be needing a code sample of the issue you are experiencing. It will be extremely helpful, if you could provide us with the test method and the system under test(in your case this will be the "PortalControl" class itself).

However, from the error log you have send, I can conclude that you are trying to mock a non-private instance or an instance with non-private or protected members in it, which are preventing the mock from being created.

If you are not able to send us a code sample, I would recommend you to check this article for further assistance:
-http://www.telerik.com/help/justmock/advanced-usage-mocking-non-public-members-and-types.html

Thank you for the cooperation in advance.
 
Greetings,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
0
KenBobPDX
Top achievements
Rank 2
answered on 30 Nov 2012, 04:00 PM
[TestMethod]
public void SetupHiddenBrowserTest()
{
    RunningDesktop mockedRunningDesktop = Mock.Create<RunningDesktop>();
    PortalControl mockedPortalControl = Mock.Create<PortalControl>(Constructor.Mocked);
 
    Mock.Arrange(() => mockedPortalControl.GetDesktopByKey(Arg.AnyString)).Returns(mockedRunningDesktop);
    Mock.Arrange(() => mockedPortalControl.ActivatePortal()).DoNothing();
 
    PortalControl portal = new PortalControl("SomeBaseUrl", "SomeRemoteHost", 14, false, 0);
    portal.SetupHiddenBrowser("DesktopKey", "SomeOptionalUrl");
    Assert.True(true);
}

The PortalControl is a rather large legacy class that I inherited. It would be impractical to post the entire class since it is over 11600 lines of code. The OnFrameWindowActive is not a method in the PortalControl class itself.  

In searching Google for this event I found the following information on this link: http://www.2cto.com/shouce/mfclk/class/COleServerDoc_OnFrameWindowActivate.htm  Although the page is in Chinese, Google Translate tells me this is the translation:

COleServerDoc :: OnFrameWindowActivate 

virtual void OnFrameWindowActivate (BOOL bActivate); 

Parameters:
bActivate Indicative frame window to be activated or becomes inactive.

Description: 
When the the container application frame window is activated or becomes inactive, the framework calls this function. The default implementation of this function is to cancel the frame window help in any way possible. When the frame window is active or inactive, the application wants to perform specific processing, you can reload OnFrameWindowActive function. 
If you want to get more information, see the article "Visual C + + Programmer's Guide" activate ". 

See also: 
COleServerDoc :: OnDocWindowActivate
0
KenBobPDX
Top achievements
Rank 2
answered on 30 Nov 2012, 06:51 PM
The exception info indicates the error is coming from mscorlib.  Here's the stack trace:

   at System.Reflection.Emit.TypeBuilder.TermCreateClass(RuntimeModule module, Int32 tk, ObjectHandleOnStack type)
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateType()
   at Telerik.JustMock.DynamicProxy.TypeEmitter.CreateType()
   at Telerik.JustMock.DynamicProxy.Proxy.CreateType()
   at Telerik.JustMock.DynamicProxy.ProxyFactory.Create()
   at Telerik.JustMock.DynamicProxy.Fluent.FluentProxy.NewInstance()
   at Telerik.JustMock.DynamicProxy.Proxy.Create(Type target, Action`1 action)
   at Telerik.JustMock.MockManager.CreateProxy(Type targetType, Container container)
   at Telerik.JustMock.MockManager.CreateInstance(Container container)
   at Telerik.JustMock.MockManager.SetupMock(Behavior behavior, Boolean static)
   at Telerik.JustMock.MockManager.CreateInstance()
   at Telerik.JustMock.FluentMock.Create()
   at Telerik.JustMock.Mock.Create(Type target, Action`1 settings)
   at Telerik.JustMock.Mock.Create(Type targetType, Constructor constructor, Behavior behavior)
   at Telerik.JustMock.Mock.Create[T](Constructor constructor)
   at wiPortal2.nunit.PortalControlTests.SetupHiddenBrowserTest() in C:\Users\hayneskr\Documents\OF014_SnapView\web2000\of_app\VisualStudioProjects\wiPortal2\wiPortal2\wiPortal2.nunit\PortalControlTests.cs:line 30
0
KenBobPDX
Top achievements
Rank 2
answered on 01 Dec 2012, 12:32 AM
I don't know if this information is helpful or not.  I ran the test in JustTest through the debugger. I set the debugger to stop on all exceptions thrown.  This is what I got:

c:\B10\Manticore\ProductionTrial_Release\Sources\source\UnitTesting.TestRunner.Interface\Common\AssemblyLoader.cs

c:\B10\Manticore\ProductionTrial_Release\Sources\source\UnitTesting.TestExecutor\Executor.cs

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.NUnit.Runner' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Extensions/UnitTestRunnerProviders/Telerik.JustCode.UnitTesting.NUnit.Runner.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

c:\B10\Manticore\ProductionTrial_Release\Sources\source\UnitTesting.TestExecutor\IsolatedAppDomainHost.cs

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.TestRunner.Interface' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Telerik.JustCode.UnitTesting.TestRunner.Interface.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'JustCodeTestExecutor' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/JustCodeTestExecutor.Any.NET4.exe' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.TestRunner.Interface' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Telerik.JustCode.UnitTesting.TestRunner.Interface.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

c:\B10\Manticore\ProductionTrial_Release\Sources\source\UnitTesting.TestExecutor\CurrentAppDomainHost.cs

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.Logging' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Telerik.JustCode.Logging.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.TestRunner.Interface' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Telerik.JustCode.UnitTesting.TestRunner.Interface.DLL' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.NUnit.Runner' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Extensions/UnitTestRunnerProviders/Telerik.JustCode.UnitTesting.NUnit.Runner.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'Telerik.JustCode.UnitTesting.NUnit.Runner' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Extensions/UnitTestRunnerProviders/Telerik.JustCode.UnitTesting.NUnit.Runner.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'nunit.core.interfaces' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Extensions/UnitTestRunnerProviders/NUnit/nunit.core.interfaces.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

LoadFromContext was detected
Message: The assembly named 'nunit.core' was loaded from 'file:///C:/Program Files (x86)/Telerik/JustCode/Libraries/Extensions/UnitTestRunnerProviders/NUnit/nunit.core.dll' using the LoadFrom context. The use of this context can result in unexpected behavior for serialization, casting and dependency resolution. In almost all cases, it is recommended that the LoadFrom context be avoided. This can be done by installing assemblies in the Global Assembly Cache or in the ApplicationBase directory and using Assembly.Load when explicitly loading assemblies.

0
Kaloyan
Telerik team
answered on 05 Dec 2012, 02:28 PM
Hi Kenneth,

Sorry for the late reply.

I assume this issue is concerning the same bug as in Ticket: 636733. 

Thank you for showing us one more situation in which our product is failing because of that bug. 

However, our dev team is doing its best in providing a proper fix to the matter. We have it scheduled for one of the future JustMock releases.

Thank you for the patience.
 
All the best,
Kaloyan
the Telerik team
Share what you think about JustTrace & JustMock with us, so we can become even better! You can use the built-in feedback tool inside JustTrace, our forums, or our JustTrace or JustMock portals.
Tags
General Discussions
Asked by
KenBobPDX
Top achievements
Rank 2
Answers by
Kaloyan
Telerik team
KenBobPDX
Top achievements
Rank 2
Share this question
or