Search Results

Search found 9 results on 1 pages for 'joblot'.

Page 1/1 | 1 

  • RhinoMocks Testing callback method

    - by joblot
    Hi All I have a service proxy class that makes asyn call to service operation. I use a callback method to pass results back to my view model. Doing functional testing of view model, I can mock service proxy to ensure methods are called on the proxy, but how can I ensure that callback method is called as well? With RhinoMocks I can test that events are handled and event raise events on the mocked object, but how can I test callbacks? ViewModel: public class MyViewModel { public void GetDataAsync() { // Use DI framework to get the object IMyServiceClient myServiceClient = IoC.Resolve<IMyServiceClient>(); myServiceClient.GetData(GetDataAsyncCallback); } private void GetDataAsyncCallback(Entity entity, ServiceError error) { // do something here... } } ServiceProxy: public class MyService : ClientBase, IMyServiceClient { // Constructor public NertiAdminServiceClient(string endpointConfigurationName, string remoteAddress) : base(endpointConfigurationName, remoteAddress) { } // IMyServiceClient member. public void GetData(Action<Entity, ServiceError> callback) { Channel.BeginGetData(EndGetData, callback); } private void EndGetData(IAsyncResult result) { Action<Entity, ServiceError> callback = result.AsyncState as Action<Entity, ServiceError>; ServiceError error; Entity results = Channel.EndGetData(out error, result); if (callback != null) callback(results, error); } } Thanks

    Read the article

  • Issue intercepting property in Silverlight application

    - by joblot
    I am using Ninject as DI container in a Silverlight application. Now I am extending the application to support interception and started integrating DynamicProxy2 extension for Ninject. I am trying to intercept call to properties on a ViewModel and ending up getting following exception: “Attempt to access the method failed: System.Reflection.Emit.DynamicMethod..ctor(System.String, System.Type, System.Type[], System.Reflection.Module, Boolean)” This exception is thrown when invocation.Proceed() method is called. I tried two implementations of the interceptor and they both fail public class NotifyPropertyChangedInterceptor: SimpleInterceptor { protected override void AfterInvoke(IInvocation invocation) { var model = (IAutoNotifyPropertyChanged)invocation.Request.Proxy; model.OnPropertyChanged(invocation.Request.Method.Name.Substring("set_".Length)); } } public class NotifyPropertyChangedInterceptor: IInterceptor { public void Intercept(IInvocation invocation) { invocation.Proceed(); var model = (IAutoNotifyPropertyChanged)invocation.Request.Proxy; model.OnPropertyChanged(invocation.Request.Method.Name.Substring("set_".Length)); } } I want to call OnPropertyChanged method on the ViewModel when property value is set. I am using Attribute based interception. [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class NotifyPropertyChangedAttribute : InterceptAttribute { public override IInterceptor CreateInterceptor(IProxyRequest request) { if(request.Method.Name.StartsWith("set_")) return request.Context.Kernel.Get<NotifyPropertyChangedInterceptor>(); return null; } } I tested the implementation with a Console Application and it works alright. I also noted in Console Application as long as I had Ninject.Extensions.Interception.DynamicProxy2.dll in same folder as Ninject.dll I did not have to explicitly load DynamicProxy2Module into the Kernel, where as I had to explicitly load it for Silverlight application as follows: IKernel kernel = new StandardKernel(new DIModules(), new DynamicProxy2Module()); Could someone please help? Thanks

    Read the article

  • Ninject: Dynamically loading modules in Silverlight

    - by joblot
    The reason I want to load modules dynamically is to avoid circular dependency issue. I have following layers View -- ViewModel -- DataProvider -- ServiceClient (wcf proxies). Now I want a static IoC container that can be shared across these layers. I want to make my View testable and to do that I’ll have to inject the various dependencies in various layers and mock out those dependencies as well. Now issue I am facing is where to declare and load ninject modules. i also realised in Silverlight version of Ninject there is no version of Load which take string arugment, which can be used to load the modules dynamically Load("*.dll"). How can I achieve dynamic loading in Silverlight Thanks

    Read the article

  • Verify an event was raised by mocked object

    - by joblot
    In my unit test how can I verify that an event is raised by the mocked object. I have a View(UI) -- ViewModel -- DataProvider -- ServiceProxy. ServiceProxy makes async call to serivce operation. When async operation is complete a method on DataProvider is called (callback method is passed as a method parameter). The callback method then raise and event which ViewModel is listening to. For ViewModel test I mock DataProvider and verify that handler exists for event raised by DataProvider. When testing DataProvider I mock ServiceProxy, but how can I test that callback method is called and event is raised. I am using RhinoMock 3.5 and AAA syntax Thanks -- DataProvider -- public partial class DataProvider { public event EventHandler<EntityEventArgs<ProductDefinition>> GetProductDefinitionCompleted; public void GetProductDefinition() { var service = IoC.Resolve<IServiceProxy>(); service.GetProductDefinitionAsync(GetProductDefinitionAsyncCallback); } private void GetProductDefinitionAsyncCallback(ProductDefinition productDefinition, ServiceError error) { OnGetProductDefinitionCompleted(this, new EntityEventArgs<ProductDefinition>(productDefinition, error)); } protected void OnGetProductDefinitionCompleted(object sender, EntityEventArgs<ProductDefinition> e) { if (GetProductDefinitionCompleted != null) GetProductDefinitionCompleted(sender, e); } } -- ServiceProxy -- public class ServiceProxy : ClientBase<IService>, IServiceProxy { public void GetProductDefinitionAsync(Action<ProductDefinition, ServiceError> callback) { Channel.BeginGetProductDefinition(EndGetProductDefinition, callback); } private void EndGetProductDefinition(IAsyncResult result) { Action<ProductDefinition, ServiceError> callback = result.AsyncState as Action<ProductDefinition, ServiceError>; ServiceError error; ProductDefinition results = Channel.EndGetProductDefinition(out error, result); if (callback != null) callback(results, error); } }

    Read the article

  • Ninject: Shared DI/IoC container

    - by joblot
    Hi I want to share the container across various layers in my application. I started creating a static class which initialises the container and register types in the container. public class GeneralDIModule : NinjectModule { public override void Load() { Bind().To().InSingletonScope(); } } public abstract class IoC { private static IKernel _container; public static void Initialize() { _container = new StandardKernel(new GeneralDIModule(), new ViewModelDIModule()); } public static T Get<T>() { return _container.Get<T>(); } } I noticed there is a Resolve method as well. What is the difference between Resolve and Get? In my unit tests I don’t always want every registered type in my container. Is there a way of initializing an empty container and then register types I need. I’ll be mocking types as well in unit test so I’ll have to register them as well. There is an Inject method, but it says lifecycle of instance is not managed? Could someone please set me in right way? How can I register, unregister objects and reset the container. Thanks

    Read the article

1