Is there a Rhinomock version of AutoConfiguredMoqCustomization? - rhino-mocks

I am bound to use Rhinomocks in my current project. Is there a way of setting up using Autofixture with Rhinomocks to achieve the same behaviour as when combining AutoFixture with Moq using the AutoConfiguredMoqCustomization customization?
Currently I have to do a lot of dummy mock setups in my test code as seen below. In the code i dont really care about the locations that I create. I just want the GetAllLocations method to return a random list of locations instead of null:
var f = new Fixture();
var masterDataProvider = MockRepository.GenerateStub<IMasterDataProvider>();
masterDataProvider.Stub(x => x.GetAllLocations()).Return(f.CreateMany<Location>());
f.Inject(masterDataProvider);

The various Glue Libraries for AutoFixture don't have full feature parity. AutoConfiguredMoqCustomization is one of the features that are only partially ported to other Glue Libraries. IIRC, it's only available for Moq and one other dynamic mock library.
So the short answer is that no, this feature isn't available for Rhino Mocks.
Original answer:
Yes, you can use AutoFixture.AutoRhinoMocks instead of AutoFixture.AutoMoq. It works the same way, but some of the type names are different - for example, the ICustomization you should use is called AutoRhinoMockCustomization.

Related

How to list the exposed members of a package/dir-like method in Elm?

I have been searching the official docs and existing questions and could not find any information on this - in Elm, how it would be possible to see the members/methods/variables that belong to or are exposed by a package in Elm, (such as the dir method in python), without having to dive into the source code each time?
What I want to do is get a simple list of what methods are exposed by an imported package. (So for a package like List, it should output reverse , all, any, map, etc.) I have attempted tab completion in elm repl and the elm extension available in VS code editor, and elm repl does not offer any methods such as help, doc, ?, dir, man, etc., so I have no idea where to even start. I'm wondering how everyone else does this other than pulling up the source code for each and every package they use.
I apologize for the newbie question and if I misread or have been missing anything, but I couldn't even find anything in the https://elmprogramming.com tutorial. Thanks in advance.
Nothing like this exists in Elm to do reflection over modules, unfortunately (as of 0.19.1, at least).
However, if you aren't looking to actually do this kind of thing at runtime, but rather as a convenient way of finding out for development, the elm packaging system enforces the requirement that all public functions are documented, so if you visit the package page, every public function and type will be documented there (obviously it can't enforce the content of the documentation, but at the very least it will be listed).

Is there a way to find where the internal classes are moved

We are migrating our application from Eclipse Indigo to Photon and I need help find a solution or alternate for a particular class which is present in Indigo but not in Photon.
The class we are trying to figure out is org.eclipse.ui.internal.navigator.AdaptabilityUtility.
Since it is an Internal class it is not available. But we had no luck finding an alternate.
Only one function of the class is used :
IAdaptable openable = (IAdaptable) AdaptabilityUtility.getAdapter(
selection.getFirstElement(), IResource.class);
If someone knows an alternative method which can be used here, it will be a great help.
Eclipse internals were completely rewritten for Eclipse 4 so in general there may not be exact alternatives for internal classes which were never part of the official API.
However for AdaptabilityUtility it looks like the current org.eclipse.core.runtime.Adapters class should work:
IResource resource = Adapters.adapt(selection.getFirstElement(), IResource.class);
Adapters.adapt uses generics so casts are not needed. Adapters is not internal so it is an official API.

Projecting an instance from a A4Solution

I'm trying to make a new UI to visualize my Alloy instances. I've got an A4Solution and have been successful in extracting atoms, relations, checking atom signatures BUT I can't seem to understand how to project the instance on some sig.
I've noticed that I can try to use the edu.mit.csail.sdg.alloy4viz.AlloyInstance, I've got options to project there, but that'd imply in starting over, from a different angle.
Would that be the way to go? I'd prefer to extract that from the A4Solution object.
Thanks
You might want to look at the edu.mit.csail.sdg.alloy4viz.StaticProjector class and its project methods---that's how the Alloy Visualizer implements projections. If your visualization uses the edu.mit.csail.sdg.alloy4viz.AlloyModel class, you should be able to reuse the existing code in StaticProjector; from your post it seems, however, that you'd prefer not use any of the alloy4viz classes, in which case it should not be too difficult to understand how StaticProjector works and reapply the same ideas to your project. Or you could convert an A4Solution object to an AlloyInstance[1] and build your visualizer around the alloy4viz classes, which, in my opinion, would be a good way to go about your project.
[1] something like:
a4sol.writeXML("instance.xml")
AlloyInstance inst = StaticInstanceReader.parseInstance(new File("instance.xml"));

Any alternative to shim feature provided in Microsoft fake framework?

I am wondering is there any alternative lib to the shim feature provided in Microsoft fake framework since it is only supported in ultimate version?
There are three frameworks to my knowledge that allow you to mock non virtual methods and sealed classes like Fakes' Shims. There are
Microsofts' Moles or Fakes
Teleriks JustMock
TypeMocks
They are all commercial because they use the Profiling API, which is very hairy and poorly documented, so coding them is a real pain.
And for the record I'm all for fakes. Most code that people are working on is legacy code. One of the Pragmatic Programmer's rules of refactoring is make sure that you have unit test coverage before any refactorings to avoid regression. This makes Fakes and similar frameworks super useful, especially when the legacy code was not written for test-ability.
Prig hasn't been updated to work with VS 2017, but Pose does, and works really well for what I needed it for (basic shimming of Environment.UserName, and DateTime.Now and similar), and has a really nice interface:
// Create shims. They only apply within this isolate block.
var dateTimeShim = Shim.Replace(() => DateTime.Now)
.With(() => new DateTime(2010, 1, 1));
var usernameShim = Shim.Replace(() => Environment.UserName)
.With(() => "john.wick");
// Shims are only active within an Isolate block - and you
// have to pass all shims you want to be active.
PoseContext.Isolate(() =>
{
// Run your test - shims are active at this point.
RunTest();
}, dateTimeShim, usernameShim);
EDIT
I should note that I get lots of errors when doing fairly basic tests - really scary errors like "Common Language Runtime detected an invalid program.", and "JIT Compiler encountered an internal limitation." so caveat emptor.
An open source alternative is Prig. MIT licenced and still active - but slightly behind with VS IDE

how to get knowing more about a class behaviour without looking at its manual?(a fundamental question about how to dive more into OOP)

I'm practicing OOP for 2 years (for real) and I know how to consume objects and packages and I'm developing stuffs mostly using C# .
but I have a problem with consuming unknown objects and packages as an instance :
for now I am working on an enterprise like website and for part of our job we need to consume RSS. I decided to use "System.Xml.Xpath"
and my real problem is:
for using system.xml.xpath I should look at manual and read it carefully and I don't want to do that every time.A plain example of that is like following code :
XPathDocument xp = new XPathDocument(sites[2]);
XPathNavigator nav = xp.CreateNavigator();
XPathNodeIterator it = nav.Select(xpath3);
foreach (XPathNavigator n in it)
{
//get elements here
}
//another way of iterating elements is
while(it.movenext())
{
//it.current.Value;
}
for the "foreeach" part I got it from MSDN manual and I guess I could get this simple fact by looking at class structure.
but I don't know which structure I should look.
I know how to read tooltips and I'm familiar with things like : [] / collection / enum /generic / Ienumerable / Idisposable etc...
but I think there is something about reading class behaviors and I'm missing that part.
for make it more lucid :
I know whenever we have a class that inherited from IEnumerable so we can use foreach statement against that class to iterate it through
my real problem is I think classes are self described enough to not to look at manuals all the time but I don't know how/where to read those descriptions of classes so I need your advice to get more familiar with how to reading classes without looking at manuals.
best regards.
Classes can (and should) be documented with source code comments, and in many languages you can generate API documentation from these comments (in HTML, XML or other format). In Java it is called Javadoc; I don't know the C# term. If this is what you call "manual", then this is your primary source of information. Other than reading the source code comments and the code itself (which you often don't have access to, especially in the MS universe). If you don't find enough information in the API documentation, you can always try googling for more explanation, tutorials or usage examples.
Hope this helps; I am not entirely sure I understood your question though. If this is not the answer you are looking for, please clarify.