locked
Using Moles in Windows Azure development

    Question

  • I want to use Moles to abstract from Windows Azure in my unittests. To do this I generated a Moles assembly for Microsoft.WindowsAzure.ServiceRuntime. In my OnStart method of the WebRole I print out all the endpoints currently in use by iterating the RoleEnvironment.CurrentRoleInstance.InstanceEndpoints.Values. The plan is to use my generated moles to supply the information.

    The problem I have is that nog Stub is generated for the RoleInstance class, although it is abstract. There is a generated mole however, but that needs an instance of the RoleInstance as a parameter for the constructor. Nomatter what I do, I cannot implement a RoleInstance class. I allways get an error stating I need to implement the set operations or when I do implement them, that I'm not allowed to implement them.

    Using Reflector I disassembled the RoleInstance class and noticed it had internal property set defined for every property. Maybe this is a problem of the dotNET4.0 framework, maybe this is a no no from the Azure team or maybe the Moles assembly is not correct. Maybe I'm not bright enough to understand why this is (not) possible.

    When I tried my mock framework, it gave an exception on creating of the mock / stub object. So that doesn't work either. I'm just stuck with a problem.

    Thursday, September 23, 2010 1:34 PM

All replies

  • I see. All hope is not gone! You can use the properties in the nested type MRoleInstance.AllInstances. Each static method will allow you to replace the instance methods of 'RoleInstance'. That might be good enough for your case. Otherwise, posting a little snippet would probably help corner the problem.
    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Thursday, September 23, 2010 3:57 PM
  • RoleInstanceEndpoint endpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["InternalHttpIn"];
    
    

    I can set RoleEnvironment.CurrentRoleInstance to return null with the use of Moles. As RoleInstance has the internal setter problem, I cannot implement a mock to be returned. MRoleInstance.AllInstances is an empty class. I think Moles does not like the internal setters.

    The code is the first line in my azure project. It gets the InternalHttpIn endpoint from the environment as it is set at runtime.

    • Edited by erictummers Monday, September 27, 2010 9:20 AM typo
    Monday, September 27, 2010 9:20 AM
  • If you could send a repro solution to pexbug _ad_ microsoft dot com (along with instructions), we could take a look. No matter the internal setter, we should emit methods for the public getters.

    Maybe the getter are defined on the base class and do not appear in he MRoleInstance.AllInstances but in its base class.


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Monday, September 27, 2010 11:04 AM
  • Thanks for the repro - and unfortunately, you are right: currently, Moles is not usable for Azure. I've been thinking about this but there does not seem to be easy ways to acheive this without going back to using Reflection for parts of the way.


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Wednesday, September 29, 2010 2:08 PM
  • Any news on this?
    Tuesday, January 11, 2011 12:43 PM