public void AddSubscriber_WhenCalledWithSameEventHandlerMultipleTimes_EventHandlerHasOnlyBeenAddedOnce() { IEventPublisher sut = CreateSut(); using TestEventHandler testEventHandler = new TestEventHandler(); sut.AddSubscriber(testEventHandler); sut.AddSubscriber(testEventHandler); sut.AddSubscriber(testEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).Count, Is.EqualTo(1)); }
public void AddSubscriber_WhenCalledMultipleNonAddedEventHandler_AddsNonAddedEventHandlers() { IEventPublisher sut = CreateSut(); using TestEventHandler firstTestEventHandler = new TestEventHandler(); using TestEventHandler secondTestEventHandler = new TestEventHandler(); using TestEventHandler thirdTestEventHandler = new TestEventHandler(); sut.AddSubscriber(firstTestEventHandler); sut.AddSubscriber(secondTestEventHandler); sut.AddSubscriber(thirdTestEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).Count, Is.EqualTo(3)); }
public async Task PublishAsync_WhenCalled_AssertHandleAsyncWasCalledOnEachEventHandlerWhichHandlesEvent() { IEventPublisher sut = CreateSut(); using TestEventHandler firstTestEventHandler = new TestEventHandler(); using TestEventHandler secondTestEventHandler = new TestEventHandler(); using TestEventHandler thirdTestEventHandler = new TestEventHandler(); sut.AddSubscriber(firstTestEventHandler); sut.AddSubscriber(secondTestEventHandler); sut.AddSubscriber(thirdTestEventHandler); await sut.PublishAsync(new TestEvent()); Assert.That(firstTestEventHandler.HandleAsyncWasCalled, Is.True); Assert.That(secondTestEventHandler.HandleAsyncWasCalled, Is.True); Assert.That(thirdTestEventHandler.HandleAsyncWasCalled, Is.True); }
public void AddSubscriber_WhenCalledWithNonAddedEventHandler_AddsEventHandler() { IEventPublisher sut = CreateSut(); using TestEventHandler testEventHandler = new TestEventHandler(); sut.AddSubscriber(testEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).ContainsKey(testEventHandler)); }
public BudgetInfoModelHandler(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime statusDate) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _eventPublisher = eventPublisher; _statusDate = statusDate.Date; _budgetAccountModelHandler = new BudgetAccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, false, false); _eventPublisher.AddSubscriber(this); }
public void RemoveSubscriber_WhenCalledWithNonAddedEventHandler_ExpectNoRemovedEventHandlers() { IEventPublisher sut = CreateSut(); using TestEventHandler firstTestEventHandler = new TestEventHandler(); using TestEventHandler secondTestEventHandler = new TestEventHandler(); sut.AddSubscriber(firstTestEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).Count, Is.EqualTo(1)); }
public async Task PublishAsync__WhenCalled_AssertHandleAsyncWasCalledWithEvent() { IEventPublisher sut = CreateSut(); using TestEventHandler testEventHandler = new TestEventHandler(); sut.AddSubscriber(testEventHandler); TestEvent testEvent = new TestEvent(); await sut.PublishAsync(testEvent); Assert.That(testEventHandler.HandleAsyncWasCalledWithEvent, Is.EqualTo(testEvent)); }
public void RemoveSubscriber_WhenCalledWithAddedEventHandler_ExpectEventHandlerHasBeenRemoved() { IEventPublisher sut = CreateSut(); using TestEventHandler testEventHandler = new TestEventHandler(); sut.AddSubscriber(testEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).ContainsKey(testEventHandler), Is.True); sut.RemoveSubscriber(testEventHandler); Assert.That(((ConcurrentDictionary <IEventHandler, int>)sut).ContainsKey(testEventHandler), Is.False); }
protected AccountModelHandlerBase(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime statusDate, bool includePostingLines, PostingLineModelHandler postingLineModelHandler, bool fromPostingLineModelHandler) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _includePostingLines = includePostingLines; EventPublisher = eventPublisher; StatusDate = statusDate.Date; AccountingModelHandler = new AccountingModelHandler(dbContext, modelConverter, EventPublisher, StatusDate, false, false); PostingLineModelHandler = postingLineModelHandler; FromPostingLineModelHandler = fromPostingLineModelHandler; SyncRoot = new object(); EventPublisher.AddSubscriber(this); }
public PostingLineModelHandler(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime fromDate, DateTime toDate, bool includeCreditInformation, bool includeBudgetInformation, int?numberOfPostingLines = null, bool applyingPostingLines = false) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _eventPublisher = eventPublisher; _fromDate = fromDate.Date; _toDate = toDate.Date; _includeCreditInformation = includeCreditInformation; _includeBudgetInformation = includeBudgetInformation; _numberOfPostingLines = numberOfPostingLines; _applyingPostingLines = applyingPostingLines; _accountingModelHandler = new AccountingModelHandler(dbContext, ModelConverter, _eventPublisher, _toDate, false, false); _accountModelHandler = new AccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, _includeCreditInformation, false, true); _budgetAccountModelHandler = new BudgetAccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, _includeBudgetInformation, false, true); _contactAccountModelHandler = new ContactAccountModelHandler(dbContext, modelConverter, _eventPublisher, _toDate, false, true); _eventPublisher.AddSubscriber(this); }
public AccountingModelHandler(RepositoryContext dbContext, IConverter modelConverter, IEventPublisher eventPublisher, DateTime statusDate, bool includeAccounts, bool includePostingLines) : base(dbContext, modelConverter) { NullGuard.NotNull(eventPublisher, nameof(eventPublisher)); _eventPublisher = eventPublisher; _statusDate = statusDate.Date; _includeAccounts = includeAccounts; _includePostingLines = includePostingLines; if (_includeAccounts) { _accountModelHandler = new AccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, true, false); _budgetAccountModelHandler = new BudgetAccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, true, false); _contactAccountModelHandler = new ContactAccountModelHandler(dbContext, modelConverter, _eventPublisher, _statusDate, false); } if (_includePostingLines) { _postingLineModelHandler = new PostingLineModelHandler(dbContext, modelConverter, _eventPublisher, DateTime.MinValue, _statusDate, false, false); } _eventPublisher.AddSubscriber(this); }
public void AddSubscriber_WhenEventHandlerIsNull_ThrowsArgumentNullException() { IEventPublisher sut = CreateSut(); ArgumentNullException result = Assert.Throws <ArgumentNullException>(() => sut.AddSubscriber(null)); // ReSharper disable PossibleNullReferenceException Assert.That(result.ParamName, Is.EqualTo("eventHandler")); // ReSharper restore PossibleNullReferenceException }