Configuring Unity (2.x) to use Moq as implementation via app.config - unit-testing

I am using Unity for IOC. I would like to configure the creation of moq objects using the app.config.
My config looks some like this:
<unity xmlns="schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Namespace1.IFoo, FooInterface"
mapTo="Namespace2.FooImp, FooImplementation">
</register>
</container>
</unity>
I am looking for a technique to specify a configuration some like this:
<unity xmlns="schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Namespace1.IFoo, FooInterface"
mapTo="Moq.Mock<IFoo>, Moq">
</register>
</container>
</unity>
I Know that I have to access .Object property of a Mock but this sample is just meant to explain what I want to do.
In other words: I do not want to use code to configure unity to use moq. An option would of course be to create some helpers that can be used in general.

After no one could help I figured something out.
Use a Factory for moq and add a factory resolution via unity
sample goes here

Related

Changing default base URL of Sitecore ServiceApiController, Is it possible?

when we implement SitecoreApiController, for each action method we make using Sitecore.Services.Core.ServicesController("namespace") attribute, we get a url like this:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
I wonder if we could change this default pattern, somehow in config files. I particularly interested in /sitecore/api/ part, because sometimes in the sense of security concerns, certain clients don't like to reveal that much about CMS platform behind the scene. Sometimes they even ask us to hide anything in HTTP header that tells about Microsoft ASP.NET explicitly.
Is this possible here?
Edit
this link shows a way to customize it using pipelines but I wonder if we could change the base url just through config files without needing a custom pipeline
I had a look at it, and I think I found out how - although I haven't tested it.
It looks for a setting named Sitecore.Services.RouteBase and if it can't find it, it uses sitecore/api/ssc/ as the default value.
You should be able to change it with a config patch like this in the App_Config/Include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Sitecore.Services.RouteBase" value="custom/api/" />
</settings>
</sitecore>
</configuration>

Using <CustomVisualizer> tag with natvis

I am trying to make use of the tag which is defined in natvis.xsd (The natvis schema file) in order to write C# or C++ code to visualize a type. I cannot find any documentation on this, so I'm not sure how it works. In particular I need to specify a GUID for the CustomVisualizer. What does this GUID map to? How do I export the class that is registered with this GUID? What interface do I need to implement? In short, how do I connect the GUID that I specify in the .natvis file to the code that formats the object?
The documentation for natvis does not mention the existence of the CustomVisualizer tag, but it's in the natvis schema file and shows up in autocomplete. I found that PyTools appears to implement natvis Custom Visualizers using this method, but it seems some of the code is hidden, and I'm unable to locate the source for the actual native visualizer using this method.
Here is an example natvis file I would like to make work:
<?xml version="1.0" encoding="utf-8" ?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="MyCustomVisualizer">
<CustomVisualizer VisualizerId="{387446F9-4B29-4EE7-A948-346BF6995603}"/>
</Type>
</AutoVisualizer>
And I'm asking specifically about how to write the C# and/or C++ code to make this work.
https://code.msdn.microsoft.com/Writing-graphical-debugger-a17e3d75
You want to use a UIVisualizer, instead of a CustomVisualizer. Although CustomVisualizer appears in the schema, there appears to be no documentation about it. With the UIVisualizer, you get the inspector window in the watch view, which will launch the visualizer. The usage of the GUIDs related to the UIVisualizer are also discussed in that link.
Figured this out. You can see source at https://github.com/chromium/vs-chromium
TL;DR - There's a ton of work involved, I probably did some things wrong, and it's not easy.
I don't how use CustomVisualizer, but maybe visualizer that use LegacyAddin can solve your problem https://stackoverflow.com/a/11545420/61505

How can I create test-suites to run on VisualPHPUnit?

I am using VisualPHPUnit and I am trying to organize my tests into suites (due to the fact that Selenium IDE does not export PHPUnit test suites).
I am currently implementing the option of the configuration XML file.
Yet,it is very limiting cause I want to run test suites on demand and not uploading each time on the server a new XML file (aka test suite).
I know that I can create an XML file with many test-suites in it but I would like to run them individually.
As you understand i am struggling towards DontRepeatYourself principle and code reuse.You know..just choose login.php , then the testcase and them logout.php and run them.
Is something like this possible???
Moreover...would it be difficult VisualPHPUnit to parse only one XML file and create a dropdown box of testsuites to choose from and run?
This is my XML file
<phpunit>
<!-- This is required for VPU to work correctly -->
<listeners>
<listener class="PHPUnit_Util_Log_JSON"></listener>
</listeners>
<testsuites>
<testsuite name="TestSuite1">
<file>/var/www/VisualPHPUnit/app/unitTests/Login/Login.php</file>
<file>/var/www/VisualPHPUnit/app/unitTests/CreateCourse/CreateCourse1.php</file>
<file>/var/www/VisualPHPUnit/app/unitTests/Logout.php</file>
</testsuite>
</testsuites>
</phpunit>
actually the PHP formaters are once again available for Selenium IDE. You may want to check this out:
https://addons.mozilla.org/en-us/firefox/addon/selenium-ide-php-formatters/
there are 2 php formaters: PHP_unit and PHP_Selenium

web service pattern that supports lazy loading of all properties

I am trying to design an endpoint template for a web service. My main requirement is that the caller is able to specify which properties should be populated in the returned result set.
My service returns large lists (up to 1M records) of partial objects as well as individual full objects such as (rough example XML, sorry it's a little verbose)
List:
<items>
<item>
<a>aaa</a>
<b>bbb</b>
</item>
<item>
<a>aaaA</a>
<b>bbbB</b>
</item>
</items>
Detail:
<item>
<a>aaa</a>
<b>bbb</b>
<c>ccc</c>
...
<w>
<x>xxx</x>
<y>yyy</y>
</w>
<z>zzz</z>
</item>
I have considered the following ideas:
Returning the full detail items in the list
Creating a 'list' item type that is shorter
passing a string array of property names that the caller wants to be returned
I am leaning towards the 3rd option but I want something different to that it doesn't support sub objects, I have considered passing the xml schema that you want returned instead of an array.
I would like the API to support lazy loading which is why the 3rd way seems viable as well.
Here's an example of what a function for 3. would look like:
public User GetUser(long ID, string[] properties)
And then the caller could just go:
User.Email = GetUser(User.ID, "Email").Email
Through extensive use of default values and hiding nulls, the returned XML for that would be:
<User>
<ID>123</ID>
<Email>example#example.com</Email>
</User>
Now the problem as mentioned above is trying to make it play nice with things like <w> far above, which itself has sub items as well as the possibility for lists to have sub items.
As I have far too many properties, I cannot have just a ws method for each property.
I am considering option 3. but using an xml schema instead of a string[].. But I can't think of an easy way to define this, I would also like to not have to use String names for properties such as "Email".
The final plan is to have a series of pre-defined schemas that are used commonly and only in advanced cases would we need to actually define the requested properties. But I have no idea of all the systems that will be talking to my API, let alone what properties they might each want (it's not going to be feasible for us to tailor the API for every caller).
Or am I over complicating everything too much?
I found the documentation for the Google APIs on Partial Responses and Partial Updates:
http://googlecode.blogspot.com/2011/07/lightning-fast-performance-tips-for.html
This seems to answer my question.

How can I configure AOP in ColdSpring 2.0?

I'd like to implement some before and after method advisors in Coldspring 2.0, and I'd like to use the new schema for AOP and the new autoproxying feature. Unfortunently, the Narwhal documentation for AOP is currently a cliffhanger. Can anyone give me an example of a Coldspring 2.0 configuration file that uses the AOP schema?
I just finished off 1 more section in the AOP documentation, but in the mean time, here are a few examples to get the ball rolling.
This is an example of setting up around advice. It calls the method timeMethod on the object timer, that matches the pointcut of execution(public * *(..)), which translated to: a method execution, that is public, that returns anything, that is named anything, and takes any arguments, of any types. Essentially, it matches everything.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.coldspringframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.coldspringframework.org/schema/aop"
xsi:schemaLocation="http://www.coldspringframework.org/schema/beans http://coldspringframework.org/schema/coldspring-beans-2.0.xsd
http://www.coldspringframework.org/schema/aop http://www.coldspringframework.org/schema/coldspring-aop-2.0.xsd"
>
<!-- AOP configuration -->
<aop:config>
<aop:aspect ref="timer">
<aop:around method="timeMethod"
pointcut="execution(public * *(..))"/>
</aop:aspect>
</aop:config>
<bean name="timer" class="05_AOP.Timer" />
<bean name="longTime" class="05_AOP.LongTime" />
</beans>
The important piece to note, is that while Time.cfc is just a plain ol' CFC, for it to do the around advice, the method that is being used has to take a MethodInvocation as an argument, like so:
public any function timeMethod(required MethodInvocation invocation)
{
...
}
But there you go, there is an example of using AOP in CS2.
You can still use MethodInterceptors and the like as well, but you will be using <aop:advisor> rather than <aop:aspect>.
But overall, I'm working on the CS2 AOP documentation right now, so it should get filled out in the next day or so.
DOC RELEASED! http://sourceforge.net/apps/trac/coldspring/