public async Task ShouldDispatchMessageToRegistrationWhenReceived() { await RunTest( async (hubFactory, hub, registrationFactory, subject) => { Subject <Tuple <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Observation> > observable = new Subject <Tuple <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Observation> >(); A.CallTo(() => hub.GetEvent <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Observation>("Observation")).ReturnsLazily(() => observable); With.Component.IIdentity componentRegistrar = new With.Component.Identity("registrar"); With.Component.IEntity componentEntity = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null); Common.Dto.Identity commonRegistrar = new Common.Dto.Identity { Value = "registrar" }; Common.Dto.Identity commonEntityIdentity = new Common.Dto.Identity { Value = "entity" }; Common.Dto.Entity commonEntity = new Common.Dto.Entity { Identity = commonEntityIdentity }; List <Message.IMessage> messages = new List <Message.IMessage>(); IObserver <Message.IMessage> observer = Observer.Create <Message.IMessage>(messages.Add); A.CallTo(() => registrationFactory.For(componentRegistrar, componentEntity, observer)).Returns(new Registration.Instance(commonRegistrar, commonEntity, observer)); await subject.Initialize(); await subject.Register(componentRegistrar, componentEntity, observer); observable.OnNext(Tuple.Create <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Observation>(commonRegistrar, commonEntityIdentity, new Common.Dto.Observation())); Assert.AreEqual <int>(1, messages.Count); } ); }
public async Task ShouldDeregisterEntity() { await RunTest( async (hubFactory, hub, registrationFactory, subject) => { IObservable <Tuple <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message> > observable = A.Fake <IObservable <Tuple <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message> > >(); A.CallTo(() => hub.GetEvent <Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>("Process")).Returns(observable); With.Component.IIdentity componentRegistrar = new With.Component.Identity("registrar"); With.Component.IEntity componentEntity = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null); Common.Dto.Identity commonRegistrar = new Common.Dto.Identity { Value = "registrar" }; Common.Dto.Identity commonEntityIdentity = new Common.Dto.Identity { Value = "entity" }; Common.Dto.Entity commonEntity = new Common.Dto.Entity { Identity = commonEntityIdentity }; IObserver <Message.IMessage> process = A.Fake <IObserver <Message.IMessage> >(); A.CallTo(() => registrationFactory.For(componentRegistrar, componentEntity, process)).Returns(new Registration.Instance(commonRegistrar, commonEntity, process)); await subject.Initialize(); await subject.Register(componentRegistrar, componentEntity, process); await subject.Deregister(componentRegistrar, componentEntity); A.CallTo(() => hub.Deregister(A <Common.Dto.Identity> .Ignored, A <Common.Dto.Entity> .Ignored)).MustHaveHappened(Repeated.Exactly.Once); } ); }
public void Register(string connectionId, Common.Dto.Identity registrar, Common.Dto.Entity entity, Action <string, Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message> process) { Registration.IInstance registration = _registrationFactory.For(connectionId, registrar, entity, process); _registrations.Add(registration); _messagingEndpoint.Register(registration.Registrar, registration.Entity, registration.Consumer); }
public Instance(Common.Dto.Identity client, Common.Dto.Entity entity, IObserver <Message.IMessage> consumer) { Client = client; Entity = entity; Consumer = consumer; Key = Registration.Key.For(client, entity.Identity); }
public void Deregister(string connectionId, Common.Dto.Identity registrar, Common.Dto.Entity entity) { string registrationKey = Registration.Key.For(connectionId, registrar, entity.Identity); Registration.IInstance registration; if (_registrations.TryGetValue(registrationKey, out registration)) { _messagingEndpoint.Deregister(registration.Registrar, registration.Entity); _registrations.Remove(registration); } }
/// <summary> /// Deregisters the specified <see cref="Component.IEntity"/> and ensures that messages are no longer /// received for the entity /// </summary> /// <param name="registrar">The host deregistering the entity</param> /// <param name="entity"></param> public void Deregister(Common.Dto.Identity registrar, Common.Dto.Entity entity) { _connector.Deregister(Context.ConnectionId, registrar, entity); }
/// <summary> /// Registers the specified <see cref="Component.IEntity"/> and ensures messages destined for the entity /// are routed to the specified consumer /// </summary> /// <param name="registrar">The host registering the entity</param> /// <param name="entity">The entity to register</param> public void Register(Common.Dto.Identity registrar, Common.Dto.Entity entity) { _connector.Register(Context.ConnectionId, registrar, entity, Process); }
public async Task ShouldDeregisterEntity() { await RunTest( async (hubFactory, hub, registrationFactory, subject) => { IObservable<Tuple<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>> observable = A.Fake<IObservable<Tuple<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>>>(); A.CallTo(() => hub.GetEvent<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>("Process")).Returns(observable); With.Component.IIdentity componentRegistrar = new With.Component.Identity("registrar"); With.Component.IEntity componentEntity = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null); Common.Dto.Identity commonRegistrar = new Common.Dto.Identity { Value = "registrar" }; Common.Dto.Identity commonEntityIdentity = new Common.Dto.Identity { Value = "entity" }; Common.Dto.Entity commonEntity = new Common.Dto.Entity { Identity = commonEntityIdentity }; IObserver<Message.IMessage> process = A.Fake<IObserver<Message.IMessage>>(); A.CallTo(() => registrationFactory.For(componentRegistrar, componentEntity, process)).Returns(new Registration.Instance(commonRegistrar, commonEntity, process)); await subject.Initialize(); await subject.Register(componentRegistrar, componentEntity, process); await subject.Deregister(componentRegistrar, componentEntity); A.CallTo(() => hub.Deregister(A<Common.Dto.Identity>.Ignored, A<Common.Dto.Entity>.Ignored)).MustHaveHappened(Repeated.Exactly.Once); } ); }
public async Task ShouldDispatchMessageToCorrectRegistrationWhenReceived() { await RunTest( async (hubFactory, hub, registrationFactory, subject) => { Subject<Tuple<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>> observable = new Subject<Tuple<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>>(); A.CallTo(() => hub.GetEvent<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>("Process")).Returns(observable); With.Component.IIdentity componentRegistrar = new With.Component.Identity("registrar"); With.Component.IEntity componentEntity = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null); Common.Dto.Identity commonRegistrar = new Common.Dto.Identity { Value = "registrar" }; Common.Dto.Identity commonEntityIdentity = new Common.Dto.Identity { Value = "entity" }; Common.Dto.Entity commonEntity = new Common.Dto.Entity { Identity = commonEntityIdentity }; List<Message.IMessage> messages = new List<Message.IMessage>(); IObserver<Message.IMessage> observer = Observer.Create<Message.IMessage>(messages.Add); A.CallTo(() => registrationFactory.For(componentRegistrar, componentEntity, observer)).Returns(new Registration.Instance(commonRegistrar, commonEntity, observer)); await subject.Initialize(); await subject.Register(componentRegistrar, componentEntity, observer); observable.OnNext(Tuple.Create<Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message>(new Common.Dto.Identity { Value = "registrar2" }, new Common.Dto.Identity { Value = "entity2" }, new Common.Dto.Message())); Assert.AreEqual<int>(0, messages.Count); } ); }
public IInstance For(string connectionId, Common.Dto.Identity registrar, Common.Dto.Entity entity, Action <string, Common.Dto.Identity, Common.Dto.Identity, Common.Dto.Message> processor) { return(new Instance(connectionId, registrar.AsComponent(), entity.AsComponent(), message => processor(connectionId, registrar, entity.Identity, message.AsDynamicDto()))); }
public Task Deregister(Common.Dto.Identity registrar, Common.Dto.Entity entity) { return(_hubProxy.Invoke("Deregister", new object[] { registrar, entity })); }