Exemple #1
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);
            }
                );
        }
Exemple #2
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);
            }
                );
        }
        public void ShouldBeAbleToMapIdentityToDto()
        {
            With.Component.IIdentity    source = new With.Component.Identity("TEST");
            SignalR.Common.Dto.Identity actual = source.AsDto();

            Assert.AreEqual(actual.Value, "TEST");
        }
        public void ShouldBeAbleToMapIdentityToDto()
        {
            With.Component.IIdentity source = new With.Component.Identity("TEST");
            SignalR.Common.Dto.Identity actual = source.AsDto();

            Assert.AreEqual(actual.Value, "TEST");
        }
Exemple #5
0
        public async Task ShouldRegisterEntity()
        {
            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 registrar = new With.Component.Identity("registrar");
                With.Component.IEntity entity      = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null);

                IObserver <Message.IMessage> observer = A.Fake <IObserver <Message.IMessage> >();

                await subject.Initialize();

                await subject.Register(registrar, entity, observer);

                A.CallTo(() => hub.Register(A <Common.Dto.Identity> .Ignored, A <Common.Dto.Entity> .Ignored)).MustHaveHappened(Repeated.Exactly.Once);
            }
                );
        }
        public async Task ShouldRegisterEntity()
        {
            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 registrar = new With.Component.Identity("registrar");
                    With.Component.IEntity entity = new With.Component.Entity(new With.Component.Identity("entity"), null, null, null);

                    IObserver<Message.IMessage> observer = A.Fake<IObserver<Message.IMessage>>();

                    await subject.Initialize();

                    await subject.Register(registrar, entity, observer);

                    A.CallTo(() => hub.Register(A<Common.Dto.Identity>.Ignored, A<Common.Dto.Entity>.Ignored)).MustHaveHappened(Repeated.Exactly.Once);
                }
            );
        }
Exemple #7
0
        public async Task ShouldPublishRegistrationMessageOnRegister()
        {
            await RunTest(
                async (settings, connectionFactory, endpoint) =>
            {
                RabbitMq.Common.Connection.IInstance connection = A.Fake <RabbitMq.Common.Connection.IInstance>();

                A.CallTo(() => connectionFactory.Create(settings)).Returns(connection);

                await endpoint.Initialize();

                With.Component.IIdentity registrar      = new With.Component.Identity("registrar");
                With.Component.IIdentity entityIdentity = new With.Component.Identity("entity");
                With.Component.IEntity entity           = new With.Component.Entity(entityIdentity, null, null, null);

                IObserver <With.Message.IMessage> consumer = A.Fake <IObserver <With.Message.IMessage> >();

                endpoint.Register(registrar, entity, consumer);

                A.CallTo(() => connection.Publish(ExchangeName, "REGISTRATION.entity", A <With.Message.IMessage> .That.IsInstanceOf(typeof(With.Message.IRegister)))).MustHaveHappened(Repeated.Exactly.Once);
            }
                );
        }
Exemple #8
0
        public async Task ShouldBindConsumerOnRegister()
        {
            await RunTest(
                async (settings, connectionFactory, endpoint) =>
            {
                RabbitMq.Common.Connection.IInstance connection = A.Fake <RabbitMq.Common.Connection.IInstance>();

                A.CallTo(() => connectionFactory.Create(settings)).Returns(connection);

                await endpoint.Initialize();

                With.Component.IIdentity registrar      = new With.Component.Identity("registrar");
                With.Component.IIdentity entityIdentity = new With.Component.Identity("entity");
                With.Component.IEntity entity           = new With.Component.Entity(entityIdentity, null, null, null);

                IObserver <With.Message.IMessage> consumer = A.Fake <IObserver <With.Message.IMessage> >();

                endpoint.Register(registrar, entity, consumer);

                A.CallTo(() => connection.BindConsumer("entity", consumer)).MustHaveHappened(Repeated.Exactly.Once);
            }
                );
        }
Exemple #9
0
        public async Task ShouldBindConsumerOnRegister()
        {
            await RunTest(
                async (settings, connectionFactory, endpoint) =>
                {
                    RabbitMq.Common.Connection.IInstance connection = A.Fake<RabbitMq.Common.Connection.IInstance>();

                    A.CallTo(() => connectionFactory.Create(settings)).Returns(connection);

                    await endpoint.Initialize();

                    With.Component.IIdentity registrar = new With.Component.Identity("registrar");
                    With.Component.IIdentity entityIdentity = new With.Component.Identity("entity");
                    With.Component.IEntity entity = new With.Component.Entity(entityIdentity, null, null, null);

                    IObserver<With.Message.IMessage> consumer = A.Fake<IObserver<With.Message.IMessage>>();

                    endpoint.Register(registrar, entity, consumer);

                    A.CallTo(() => connection.BindConsumer("entity", consumer)).MustHaveHappened(Repeated.Exactly.Once);
                }
            );
        }
Exemple #10
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);
                }
            );
        }
Exemple #11
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);
                }
            );
        }
Exemple #12
0
        public async Task ShouldPublishRegistrationMessageOnRegister()
        {
            await RunTest(
                async (settings, connectionFactory, endpoint) =>
                {
                    RabbitMq.Common.Connection.IInstance connection = A.Fake<RabbitMq.Common.Connection.IInstance>();

                    A.CallTo(() => connectionFactory.Create(settings)).Returns(connection);

                    await endpoint.Initialize();

                    With.Component.IIdentity registrar = new With.Component.Identity("registrar");
                    With.Component.IIdentity entityIdentity = new With.Component.Identity("entity");
                    With.Component.IEntity entity = new With.Component.Entity(entityIdentity, null, null, null);

                    IObserver<With.Message.IMessage> consumer = A.Fake<IObserver<With.Message.IMessage>>();

                    endpoint.Register(registrar, entity, consumer);

                    A.CallTo(() => connection.Publish(ExchangeName, "REGISTRATION.entity", A<With.Message.IMessage>.That.IsInstanceOf(typeof(With.Message.IRegister)))).MustHaveHappened(Repeated.Exactly.Once);
                }
            );
        }