How to Mole System.Net.Dns.GetAddrInfo for a wcf client? - moles

I am able to Mole WebRequest.CreateUri so that I can replace the hostname of the request with another. However, I would like to Mole Dns.GetAddrInfo instead so that I can keep the hostname the same, but make it so that the hostname resolves to another IP address.
In this way, I do not have to edit my hosts file for example as this is a less flexible approach.
Any advice?
Thank you.
Edit
I've uploaded a sample Visual Studio 2010 sln to the problem here:
When opening the sln,
Click on the "Create Virtual Directory" button in the Service project properties' Web tab.
Rebuild the solution
Add the following entry to c:\windows\system32\drivers\etc\hosts:
127.0.0.1 www.productionserver.com
Run the TestMethod1 unit test in the Tests project.
The unit tests should succeed.
Remove the entry from the hosts file and re-run the unit test.
It should fail.
I have looked at the implementation of System.ServiceModel.ClientBase<TChannel> using a decompiler and noticed that it eventually calls System.Net.Dns.GetAddrInfo to resolve the hostname to an IP address.
I am hoping this sln is simple enough to update and send back (or just comment what needs to be done and\or changed) so I can simply see what is required to solve the problem.
Thank you.
Edit 2
It seems this is not currently possible with Moles.

The System.Net stack generally can not be moled, as much of he functionality are outside the control of the managed code.
Instead, create an interface and stub in your production code. Use the interface with dependency injection, to pass the stub to the target code. This stub simply calls the System.Net methods you wish to intercept, during testing.
Moles will automatically generate a Stub type, from the interface. Simply instantiate the stub type, detour the desired methods/properties/events of the stub, and then pass the Stub type to the method being tested.
Using stubs and dependency injection works wherever Mole types can not be created.

Related

Include runtime type definitions using VSCode extension

I'm working on a library that lets users run Node processes from inside another application. The library is called "max-api"; functions for sending data to the host application are exposed through a Node module and are loaded in the expected way:
const maxAPI = require("max-api");
However, the user never interacts with this module directly. Rather, when the host application launches the Node process, it intercepts the call to require, checks if the name of the module is "max-api", and provides the module if so.
This works great, the only issue is we have no way to provide type definitions for this modules. So, the user doesn't get any autocomplete or validation for functions in the "max-api" module. I was thinking of writing a VSCode extension to provide these, but I'm not 100% sure how to get started. Thanks in advance for any advice.
You could write a TS typings file (see Definitely Typed). This would be installed in node_modules/#types and vscode will automatically pick it up to provide code completion for your module.

NServicebus MessageHandlers in a different Project don't get hit

My problem:
I have web project which implements NServicebus and should listen to messages.
Trying to keep my solution tidy I set up a different project for all my messagehandlers.
I now find that these messagehandlers do not get "hit" with messages.
To my understanding NServicebus scans all dll's in the debug folder of the web project to find any classes implementing IHandleMessages<>.
I referenced the messagehandlers class library project in my webproject and it appears in my debug folder, however it does not seem to get hit.
What does work
In a console sample project the inclusion of a referenced project which contains messagehandlers works as expected.
In my web app it works when I move my
messaghandlers to the web app project itself.
Reading through the website http://docs.particular.net/nservicebus/hosting/nservicebus-host/ I found that there are overloads for the Configure.With() method.
However:
I do not know if I need them. They text only seem to suggest that
this will limit the places where NServicebus looks for the
implementations of the interface.
these overloads do not exist in the Configure.WithWeb method which I'm using.
I can solve my problem by moving all the messagehandlers to my web project, but this does not seem like the best solution.
Am I missing something here?
When using NServiceBus in a web project, use NServiceBus.Configure.WithWeb() instead of NServiceBus.Configure.With().
Also, in order to load message handlers in a web application, you need to include the .LoadMessageHandlers() line after .UnicastBus() as described in Hosting NServiceBus in your own Process. Otherwise any IHandleMessages<T> implementations are not loaded and your web application operates as a send-only endpoint.

Using GWT + Twitter4j

I am trying to build a simple gwt project that fetches tweets and displays them.The server passes back the tweets of type twitter4j.Tweet to the client.
Both modules import twitter4j.Tweet.
But when I run I get the following error:
--- ERROR: Line 37: No source code is available for type twitter4j.Tweet; did you forget to inherit a required module?.
I seem to have problems in inheriting twitter4j. All the posts I have seen about inheriting a jar file are not clear about how to do so. I understand I must write an inheritance instruction into gwt.xml file, something like
---
but if I try
---
it does not work. Can anyone please explain?
In a post I found on the Web one person suggested not to inherit it but:
-- Don't put twitter4j to your gwt.xml. Just add it your project class path. and make all functionalities like status updating and all in your serviceImpl. Try
This confuses me even more. I have added the jar file to my project libraries. But it does not work
I suspect I am missing something quite elementary here, but I am totally stuck. Is there something like a GWT path?
Many thanks for any help
Keep in mind that everything in your client package is compiled to JavaScript and executed in the user's browser. Thus, you'll only be able to use twitter4j's classes on the server-side of your application; you'll have to create some sort of light-weight GWT-serializable "proxy object" to pass data back and forth between your client and server tiers.
Since you can't use twitter4j on the client side of your app, you will not need anything in your .gwt.xml file referencing it. Instead, you'll add twitter4j to your classpath and do all your updating on the server side (as mentioned toward the bottom of your question). You do mention that it "does not work," but there's not enough information in your question to try to figure out why.

How do I get my Objects to work in ASP.NET MVC2

I'm rather new to MVC2 (never been in MCV1) though I'm a WebForms developer for some years now...
in my MCV 2 start project I created a App_Code folder that I would put my Business Classes on it, I also add 2 References to 2 DLLs used for the API I'm about to use.
But I don't get Intellisense on the referenced objects
What am I doing wrong?
alt text http://www.balexandre.com/temp/2010-07-28_1343.png
Is this so much different from the WebForms part?
Added
Even if I put the Object in Models instead App_Code (where I normally put all code in WebForms) I still don't get the normal intelisense, so... it just tells me that something is wrong ... dang! MVC is hard! I probably should do this in WebForms...
alt text http://www.balexandre.com/temp/2010-07-28_1509.png
This has nothing to do with MVC2, and everything to do with you're doing it wrong. I can tell that its a possibility, as you're using App_Code (I mean, who does that?). I'd definitely suggest backing up and reading some MVC tutorials, as it IS much different (although not in the way you're asking about).
I'm not exactly sure WHAT you're doing wrong, however. It might bethat PerceptiveMCAPI is internal to the assembly, it might be because there is a bug in VS, it might be that you haven't imported the correct namespace... it could be a number of different things.
I'd do the following: 1) load the assembly in reflector and make sure you have the namespace and type name and that it is public 2) use the fully qualified name of the type 3) compile, check all errors and 4) restart VS.
If all else fails, Connect.
See the Models directory -- that's where your model classes would go, assuming the class is a view model class. Having said that, it should be able to pick up and provide intellisense for whatever references you add. App_Code isn't really intended for a Web Application project (the type used by MVC) where the code is compiled statically, but rather for a WebSite where the code is compiled dynamically at runtime. It could be the "special" nature of the directory that is causing the problem because it doesn't fit the project type. You might try simply creating a different directory (if Models isn't appropriate) and not use the special App_Code directory for your code. A separate class library project with a project reference in the web application would be another alternative and is the one I usually use for non-viewmodel/controller code.

Is there a tool to convert my GWT RemoteServiceServlet into the correct Service and ServiceAsync interfaces?

I'm working on a GWT project and I find it very tedious to have to add a function to my servlet, then copy and paste the function signature into my Service interface, then copy and paste it into my ServiceAsync interface and change the return parameter to be a callback. Is there a tool or a setting where I can just add public methods to my class and they can get copied into the other interfaces? Even if its not automatic it would be nice to be able to select specific methods and have them copied automatically.
I'm using eclipse and ideally it would update my interface each time I save implementation since thats when it checks my code and complains that my changes break the interface.
If you add the method to your *Service interface, then Eclipse can auto-generate the method ("Add unimplemented methods...") in your *ServiceImpl servlet, which you can then just fill in. Also, if you've got the Google Eclipse plugin installed, it will underline the new method in your *Service interface and complain that it's not in the *ServiceAsync. It might have a CTRL + 1 option to generate it in that interface as well.
You don't really need a tool. Just factor out the many RPC methods by just one method that takes a Request/Response. all you need to do is create subclasses of Request/Response and you don't need to think about adding new methods in the 2 interfaces.
You can use Google Guice on the server side to map the incomming request to a class handling the call... or you could use a visitor approach to forward the incoming request to the code handling the request (without resorting on a big instanceof construct).
Instantiations WindowBuilder GWT Designer does exactly what you are looking for.
The RemoteService Wizard will create all three files at the same time as well as keep them in sync as you make changes.
http://www.instantiations.com/windowbuilder/gwtdesigner/index.html
FWIW - I am only a user/purchaser of this product. I am not employed or in any other way related to Instantiations.