private static ValueWaiter <Action <object> > mockFeedProvider(out MessagingFeedWithHbProviderBaseMock <int, int, string, object, object, object> feedProvider) { var initRequest = new object(); var messagingEngine = MockRepository.GenerateMock <IMessagingEngine>(); var dummyResponse = new object(); messagingEngine.Expect(e => e.SendRequestAsync <object, object>(null, new Endpoint(), o => { }, exception => { })). IgnoreArguments() .WhenCalled( invocation => { var initSubscriptionCallback = (MulticastDelegate)(invocation.Arguments[2]); initSubscriptionCallback.DynamicInvoke(dummyResponse); } ); var emulateHb = new ValueWaiter <Action <object> >(); messagingEngine.Expect(e => e.Subscribe <int>(new Endpoint(), m => { })).IgnoreArguments().Return(Disposable.Empty).Repeat.Once(); messagingEngine.Expect(e => e.Subscribe <object>(new Endpoint(), m => { })).IgnoreArguments().WhenCalled(invocation => { var callback = (MulticastDelegate)(invocation.Arguments[1]); emulateHb.SetValue(hb => callback.DynamicInvoke(hb)); }).Return(Disposable.Empty).Repeat.Once(); feedProvider = MockRepository.GeneratePartialMock <MessagingFeedWithHbProviderBaseMock <int, int, string, object, object, object> >(messagingEngine, 30000); feedProvider.Expect(p => p.GetHeartbeatIntervalFromResponseImpl(dummyResponse, "Context")).Return(100); feedProvider.Expect(p => p.GetHeartbeatIntervalFromHeartbeatMessageImpl(dummyResponse, "Context")).IgnoreArguments().Return(200).Repeat.Any(); feedProvider.Expect(p => p.ExtractInitialDataImpl(dummyResponse, "Context")).Return(200); feedProvider.Expect(p => p.GetInitRequestImpl()).Return(initRequest); return(emulateHb); }
public void SubscribtionTest() { var initCommand = new object(); var messagingEngine = MockRepository.GenerateMock <IMessagingEngine>(); var dummyResponse = new object(); messagingEngine.Expect(e => e.SendRequestAsync <object, object>(null, new Endpoint(), o => { }, exception => { })).IgnoreArguments() .WhenCalled( invocation => { var initSubscriptionCallback = (MulticastDelegate)(invocation.Arguments[2]); initSubscriptionCallback.DynamicInvoke(dummyResponse); }); messagingEngine.Expect(e => e.Subscribe <int>(new Endpoint(), m => { })).IgnoreArguments().Return(Disposable.Empty).Repeat.Once(); var feedProvider = MockRepository.GeneratePartialMock <MessagingFeedWithInitializationMock <int, string, object, object> >(messagingEngine); feedProvider.Expect(p => p.GetEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummySubj")); feedProvider.Expect(p => p.GetInitEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummyInitSubj")); feedProvider.Expect(p => p.GetInitRequestImpl("feedContext")).Return(initCommand); feedProvider.Expect(p => p.InitializeFeedImpl(null, null, null)).IgnoreArguments().Return(null); feedProvider.Expect(p => p.ExtractInitialDataImpl(dummyResponse, "feedContext")).Return(777); var data = new ValueWaiter <int>(); using (feedProvider.CreateFeed("feedContext").Subscribe(data.SetValue)) { Assert.IsTrue(data.WaitForValue(220), "Subscribed handler was not called for initial data"); Assert.AreEqual(777, data.Value, "Subscribed handler was not called with wrong initial data"); } feedProvider.AssertWasCalled(p => p.InitializeFeedImpl(null, null, null), o => o.IgnoreArguments()); }
public void SubscribtionFinishedCallbackTest() { var initCommand = new object(); var messagingEngine = MockRepository.GenerateMock <IMessagingEngine>(); var dummyResponse = new object(); var initSubscribtionCallback = new ValueWaiter <MulticastDelegate>(); messagingEngine.Expect(e => e.SendRequestAsync <object, object>(null, new Endpoint(), o => { }, exception => { })).IgnoreArguments() .WhenCalled( invocation => initSubscribtionCallback.SetValue((MulticastDelegate)(invocation.Arguments[2])) ); messagingEngine.Expect(e => e.Subscribe <int>(new Endpoint(), m => { })).IgnoreArguments().Return(Disposable.Empty).Repeat.Once(); var feedProvider = MockRepository.GeneratePartialMock <MessagingFeedWithInitializationMock <int, string, object, object> >(messagingEngine); feedProvider.Expect(p => p.GetEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummySubj")); feedProvider.Expect(p => p.GetInitEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummyInitSubj")); feedProvider.Expect(p => p.GetInitRequestImpl("feedContext")).Return(initCommand); feedProvider.Expect(p => p.InitializeFeedImpl(null, null, null)).IgnoreArguments().Return(null); feedProvider.Expect(p => p.ExtractInitialDataImpl(dummyResponse, "feedContext")).Return(777); var observable = feedProvider.CreateFeed("feedContext") as DeferredObservable <int>; Assert.That(observable, Is.Not.Null, "Created observable id not deffered"); var subscribedCallbackExecuted = new ValueWaiter <bool>(); using (observable.Subscribe(Observer.Create <int>(i => { }), () => subscribedCallbackExecuted.SetValue(true))) { initSubscribtionCallback.WaitForValue(1000); Assert.That(subscribedCallbackExecuted.WaitForValue(200), Is.False, "Notify subscribed callback was called before init command response recieved"); initSubscribtionCallback.Value.DynamicInvoke(dummyResponse); Assert.That(subscribedCallbackExecuted.WaitForValue(1000), Is.True, "Notify subscribed callback was not called after init command response recieved"); } }
public void InitFailureTest() { var initCommand = new object(); var messagingEngine = MockRepository.GenerateMock <IMessagingEngine>(); var exception = new Exception("Test Error"); messagingEngine.Expect(e => e.SendRequestAsync <object, object>(null, new Endpoint(), o => { }, ex => { })).IgnoreArguments().Throw(exception); var feedProvider = MockRepository.GeneratePartialMock <MessagingFeedWithInitializationMock <int, string, object, object> >(messagingEngine); feedProvider.Expect(p => p.GetEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummySubj")); feedProvider.Expect(p => p.GetInitEndpointImpl("feedContext")).Return(new Endpoint("dummyTransportId", "dummyInitSubj")); feedProvider.Expect(p => p.GetInitRequestImpl("feedContext")).Return(initCommand); var error = new ValueWaiter <Exception>(); using (feedProvider.CreateFeed("feedContext").Subscribe(_ => { }, error.SetValue)) { Assert.IsTrue(error.WaitForValue(220), "Error was not reported afeter no execption on transport level"); Assert.AreEqual(exception, error.Value, "Wrong exception was generated"); } }