In an automation script you con do engine.FindElement() / engine.FindService() . This returns an element/Service object.
The method I want to test uses an IEngine input and relies on a engine.FindService, then I do a getpropertyvalue of a property of the service.
Based on those values I do an engine.Findelement. On that element I do a getparameter.
I'm unable to mock a service/element as it complaing of not having a default constructor. It only has an internal constructor.
Example of mock code:
Mock<Service> mockService = new Mock<Service>();
mockService.Setup(x => x.GetPropertyValue("UserData")).Returns("test");
However then the error returned is the following:
System.NotSupportedException: Parent does not have a default constructor. The default constructor must be explicitly defined.
The only way I can think of to get around this is by making wrappers for the different classes.
But that seems like a lot of overhead just to mock 4 methods.
engine.FindElement("")
element.GetParameter()
engine.FindServiceByKey("")
service.GetPropertyValue()
What would be the best way to mock/fake the above methods?
Hi Tim,
A default constructor was added on the Element & Service types with release note 30003 (since 10.1.10.0), would it be an option to run your unit tests using the SLManagedAutomation.dll from a version higher than this?
That has done the trick, referenced the newer dll in my test project and now it can use the mock.
Thanks
For completeness, the following types have default constructors since 10.1.10: Element, MailReportOptions, RedundancyGroup, ScriptDummy, ScriptMemory, ScriptParam, Service