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 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 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); }
private void Process(string connectionId, Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Message message) { dynamic client = Clients.Client(connectionId); if (client != null) { HarmonizeDispatcher.Dispatch(client, registrar, entity, message); } }
public void Observe(string connectionId, Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Identity source, Common.Dto.Identity observable) { string registrationKey = Registration.Key.For(connectionId, registrar, entity); Registration.IInstance registration; if (_registrations.TryGetValue(registrationKey, out registration)) { _messagingEndpoint.Observe(entity.AsComponent(), source.AsComponent(), observable.AsComponent()); } }
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); } }
private void Observation(Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Observation message) { string registrationKey = Registration.Key.For(registrar, entity); System.Diagnostics.Debug.WriteLine(string.Format("Client Received Message For: '{0}'", registrationKey)); Registration.IInstance registration; if (_registrations.TryGetValue(registrationKey, out registration)) { registration.Consumer.OnNext(message.AsMessage()); } }
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 Task Deregister(Common.Dto.Identity registrar, Common.Dto.Entity entity) { return(_hubProxy.Invoke("Deregister", new object[] { registrar, entity })); }
private static void Process(dynamic client, Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Observation message) { client.Observation(registrar, entity, message); }
/// <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); }
public static void Dispatch(dynamic client, Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Message message) { dynamic dynamicMessage = message; Process(client, registrar, entity, dynamicMessage); }
/// <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); }
/// <summary> /// Observes the observable with the specified <see cref="Component.Identity"/> of the entity with the /// specified <see cref="Component.Identity"/> /// </summary> /// <param name="entity">The observer entity</param> /// <param name="source">The observed entity</param> /// <param name="observable">The observable</param> public void Observe(Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Identity source, Common.Dto.Identity observable) { _connector.Observe(Context.ConnectionId, registrar, entity, source, observable); }
public static string For(string connectionId, Common.Dto.Identity registrar, Common.Dto.Identity entity) { return(For(connectionId, registrar.Value, entity.Value)); }
public Task Observe(Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Identity source, Common.Dto.Identity observable) { return(_hubProxy.Invoke("Observe", new object[] { registrar, entity, source, observable })); }
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 static string For(Common.Dto.Identity registrar, Common.Dto.Identity entity) { return(For(registrar.Value, entity.Value)); }
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()))); }