Beispiel #1
0
        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);
            }
                );
        }
Beispiel #2
0
        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);
            }
                );
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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());
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        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());
            }
        }
Beispiel #9
0
        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);
                }
            );
        }
Beispiel #10
0
 public Task Deregister(Common.Dto.Identity registrar, Common.Dto.Entity entity)
 {
     return(_hubProxy.Invoke("Deregister", new object[] { registrar, entity }));
 }
Beispiel #11
0
 private static void Process(dynamic client, Common.Dto.Identity registrar, Common.Dto.Identity entity, Common.Dto.Observation message)
 {
     client.Observation(registrar, entity, message);
 }
Beispiel #12
0
 /// <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);
 }
Beispiel #13
0
        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);
        }
Beispiel #14
0
 /// <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);
 }
Beispiel #15
0
 /// <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);
 }
Beispiel #16
0
 public static string For(string connectionId, Common.Dto.Identity registrar, Common.Dto.Identity entity)
 {
     return(For(connectionId, registrar.Value, entity.Value));
 }
Beispiel #17
0
 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 }));
 }
Beispiel #18
0
        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);
                }
            );
        }
Beispiel #19
0
 public static string For(Common.Dto.Identity registrar, Common.Dto.Identity entity)
 {
     return(For(registrar.Value, entity.Value));
 }
Beispiel #20
0
 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())));
 }