public async Task BaseDispatcher_DispatchEventAsync_Should_Not_Throw_Exception_If_NoConfiguration_IsDefined_And_LogWarning() { var loggerMock = new Mock <ILogger>(); var loggerFactoryMock = new Mock <ILoggerFactory>(); loggerFactoryMock.Setup(m => m.CreateLogger(It.IsAny <string>())) .Returns(loggerMock.Object); var fakeScopeFactory = new TestScopeFactory(new TestScope(new Dictionary <Type, object> { { typeof(ILoggerFactory), loggerFactoryMock.Object } })); bool coreDispatcherCalledWithoutSecurityCritical = false; var d = new BaseDispatcher(new DispatcherConfiguration(false), fakeScopeFactory); var evt = new TestEvent(); CoreDispatcher.OnEventDispatched += (e) => { coreDispatcherCalledWithoutSecurityCritical = object.ReferenceEquals(e, evt); return(Task.CompletedTask); }; //Shouldn't throw exception await d.PublishEventAsync(evt).ConfigureAwait(false); coreDispatcherCalledWithoutSecurityCritical.Should().BeTrue(); }
public async Task BaseDispatcher_PublishCommandAsync_Should_Not_Throw_Exception_If_NoConfiguration_IsDefined_And_LogWarning() { var loggerMock = new Mock <ILogger>(); var loggerFactoryMock = new Mock <ILoggerFactory>(); loggerFactoryMock.Setup(m => m.CreateLogger(It.IsAny <string>())) .Returns(loggerMock.Object); var fakeScopeFactory = new TestScopeFactory(new TestScope(new Dictionary <Type, object> { { typeof(ILoggerFactory), loggerFactoryMock.Object } })); bool coreDispatcherCalledWithoutSecurityCritical = false; var d = new BaseDispatcher(new CQELight.Dispatcher.Configuration.DispatcherConfiguration(false), fakeScopeFactory); var command = new TestCommand(); CoreDispatcher.OnCommandDispatched += (c) => { coreDispatcherCalledWithoutSecurityCritical = object.ReferenceEquals(c, command); return(Task.FromResult(Result.Ok())); }; //Shouldn't throw exception await d.DispatchCommandAsync(command).ConfigureAwait(false); coreDispatcherCalledWithoutSecurityCritical.Should().BeTrue(); }
/// <summary> /// Gets a test toolbox, with your configured tooling. /// </summary> /// <param name="scopeFactory">Scope factory to use. If not defined, and empty one will be provided.</param> /// <param name="dispatcherMock">Dispatcher mock to use. If not defined, and empty one will be provided.</param> /// <param name="eventStoreMock">EventStore mock to use. If not defined, and empty one will be provided.</param> /// <param name="aggregateEventStoreMock">AggregateEventStore mock to use. If not defined, and empty one will be provided.</param> /// <returns></returns> public static CQELightToolbox GetTestToolbox( TestScopeFactory scopeFactory = null, Mock <IDispatcher> dispatcherMock = null, Mock <IEventStore> eventStoreMock = null, Mock <IAggregateEventStore> aggregateEventStoreMock = null) => new CQELightToolbox( scopeFactory ?? new TestScopeFactory(), dispatcherMock?.Object ?? new Mock <IDispatcher>().Object, eventStoreMock?.Object ?? new Mock <IEventStore>().Object, aggregateEventStoreMock?.Object ?? new Mock <IAggregateEventStore>().Object);
protected BaseUnitTestClass(bool disableIoc) { UnitTestTools.IsInUnitTestMode = true; UnitTestTools.IsInIntegrationTestMode = GetType().Assembly.GetName().Name.Contains(".Integration."); if (!UnitTestTools.IsInIntegrationTestMode && !disableIoc) { _testFactory = new TestScopeFactory(); DIManager.Init(_testFactory); } }
public RabbitSubscriberTests() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddProvider(new DebugLoggerProvider()); CleanQueues(); DeleteData(); scopeFactory = new TestScopeFactory(new TestScope(new Dictionary <Type, object> { { typeof(InMemoryEventBus), eventBus }, { typeof(InMemoryCommandBus), commandBus } } )); }
public async Task InMemoryCommandBus_DispatchAsync_HandlerFromIoC() { var factory = new TestScopeFactory(); factory.Instances.Add(typeof(ICommandHandler <TestCommand>), new TestCommandHandler("tt")); CleanRegistrationInDispatcher(); var bus = new InMemoryCommandBus(null, factory); (await bus.DispatchAsync(new TestCommand { Data = "test_ioc" }).ConfigureAwait(false)).IsSuccess.Should().BeTrue(); TestCommandHandler.HandlerData.Should().Be("test_ioc"); TestCommandHandler.Origin.Should().Be("spec_ctor"); }