public TestApplication(IDbContextFactoryMethod <ModelDbContext> dbContextFactoryMethod, 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, IBus <ICommand> commandBus, IBus <IEvent> eventBus, IService <AccountModel> accountModelService, IService <DepositModel> depositModelService, IService <AtmModel> atmModelService ) : base(observableEventPublisher, busObserverAdapter, createAccountCommandHandler, createDepositCommandHandler, createAccountEventHandler, createDepositEventHandler, addDepositToAccountEventHandler, eventHandlerFactoryMethod, commandHandlerFactoryMethod) { _dbContextFactoryMethod = dbContextFactoryMethod; _dbContextFactoryMethod.Create().Database.Delete(); CommandBus = commandBus; EventBus = eventBus; AccountModelService = accountModelService; DepositModelService = depositModelService; AtmModelService = atmModelService; }
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(); }
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); }
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); }
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); }
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(); }