Esempio n. 1
0
        public void TestExceptionIfEventGuidIsSet()
        {
            var itemGuid = Guid.NewGuid();

            var eventMock = new TestEvent {
                EventGuid = Guid.NewGuid(), ItemGuid = itemGuid
            };

            var observerMock = new Mock <IObserver <IEvent> >();

            observerMock.Setup(m => m.OnNext(It.Is <ErrorEvent>(e =>
                                                                e.ItemGuid == itemGuid && e.ErrorMessage == "Event guid is generating by publisher" &&
                                                                e.ErrorDataJson != "")));

            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(m => m.GetByEventGuid(It.IsAny <Guid>())).Returns((Guid guid) => Codes.NotFound);

            var observableEventPublisher = new ObservableEventPublisher(eventRepositoryMock.Object);

            observableEventPublisher.AddObserver(observerMock.Object);

            observableEventPublisher.Publish(eventMock);

            observerMock.VerifyAll();
        }
Esempio n. 2
0
        public Application(ObservableEventPublisher observableEventPublisher,
                           BusObserverAdapter <IEvent> busObserverAdapter,
                           ICommandHandler <CreateAccountCommand> createAccountCommandHandler,
                           ICommandHandler <CreateDepositCommand> createDepositCommandHandler,
                           IEventHandler <CreateAccountEvent> createAccountEventHandler,
                           IEventHandler <CreateDepositEvent> createDepositEventHandler,
                           IEventHandler <AddDepositToAccountEvent> addDepositToAccountEventHandler,
                           IHandlerFactoryMethod <IEvent> eventHandlerFactoryMethod,
                           IHandlerFactoryMethod <ICommand> commandHandlerFactoryMethod)
        {
            eventHandlerFactoryMethod.AddHandler(createAccountEventHandler);
            eventHandlerFactoryMethod.AddHandler(createDepositEventHandler);
            eventHandlerFactoryMethod.AddHandler(addDepositToAccountEventHandler);

            commandHandlerFactoryMethod.AddHandler(createAccountCommandHandler);
            commandHandlerFactoryMethod.AddHandler(createDepositCommandHandler);

            observableEventPublisher.AddObserver(busObserverAdapter);
        }
Esempio n. 3
0
        public void TestExceptionIfItemGuidIsEmpty()
        {
            var observerMock = new Mock <IObserver <IEvent> >();

            observerMock.Setup(m => m.OnNext(It.Is <ErrorEvent>(e =>
                                                                e.ItemGuid == Guid.Empty && e.ErrorMessage == "Item guid is not set" && e.ErrorDataJson != "")));

            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(m => m.GetByEventGuid(It.IsAny <Guid>())).Returns((Guid guid) => Codes.NotFound);

            var observableEventPublisher = new ObservableEventPublisher(eventRepositoryMock.Object);

            observableEventPublisher.AddObserver(observerMock.Object);

            var eventMock = new TestEvent {
                EventGuid = Guid.Empty, ItemGuid = Guid.Empty
            };

            observableEventPublisher.Publish(eventMock);
        }
Esempio n. 4
0
        public void TestEventGuidExist()
        {
            var counter             = 0;
            var eventGuid           = Guid.Empty;
            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(m => m.Save(It.IsAny <IEvent>()));
            eventRepositoryMock.Setup(m => m.GetByEventGuid(It.IsAny <Guid>())).Returns((Guid guid) =>
            {
                if (counter > 3)
                {
                    eventGuid = guid;
                    return(Codes.NotFound);
                }
                counter++;
                return(new TestEvent {
                    EventGuid = guid
                });
            });

            var observerMock = new Mock <IObserver <IEvent> >();

            observerMock.Setup(m => m.OnNext(It.IsAny <IEvent>()));

            var observableEventPublisher = new ObservableEventPublisher(eventRepositoryMock.Object);

            observableEventPublisher.AddObserver(observerMock.Object);

            var eventMock = new TestEvent {
                ItemGuid = Guid.NewGuid(), EventGuid = Guid.Empty
            };

            observableEventPublisher.Publish(eventMock);

            eventRepositoryMock.VerifyAll();
            observerMock.VerifyAll();
            Assert.NotEqual(Guid.Empty, eventGuid);
        }
Esempio n. 5
0
        public void TestObservableEventPublisher()
        {
            var eventRepositoryMock = new Mock <IEventRepository>();

            eventRepositoryMock.Setup(m => m.Save(It.IsAny <IEvent>()));
            eventRepositoryMock.Setup(m => m.GetByEventGuid(It.IsAny <Guid>())).Returns((Guid guid) => Codes.NotFound);

            var observerMock = new Mock <IObserver <IEvent> >();

            observerMock.Setup(m => m.OnNext(It.IsAny <IEvent>()));

            var observableEventPublisher = new ObservableEventPublisher(eventRepositoryMock.Object);

            observableEventPublisher.AddObserver(observerMock.Object);

            var eventMock = new TestEvent {
                ItemGuid = Guid.NewGuid(), EventGuid = Guid.Empty
            };

            observableEventPublisher.Publish(eventMock);

            eventRepositoryMock.VerifyAll();
            observerMock.VerifyAll();
        }