public EndToEndTests() { //This path is used to save in memory storage var strTempDataFolderPath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\"; //create temp directory if it doesn't exist new FileInfo(strTempDataFolderPath).Directory?.Create(); var inMemoryEventStorePath = $@"{strTempDataFolderPath}events.stream.dump"; var inMemorySnapshotStorePath = $@"{strTempDataFolderPath}events.snapshot.dump"; File.Delete(inMemoryEventStorePath); File.Delete(inMemorySnapshotStorePath); IEventStorageProvider <Guid> eventStorage = new InMemoryEventStorageProvider(inMemoryEventStorePath); ISnapshotStorageProvider <Guid> snapshotStorage = new InMemorySnapshotStorageProvider(SnapshotFrequency, inMemorySnapshotStorePath); _clock = new MockClock(); _eventPublisher = new MockEventPublisher(); _repository = new Repository <Schedule, ScheduleSnapshot, Guid, Guid, Guid>(_clock, eventStorage, _eventPublisher, snapshotStorage); _eventOnlyRepository = new EventOnlyRepository <Schedule, Guid, Guid>(_clock, eventStorage, _eventPublisher); }
public async void DeleteHandler_Should_Work(string id, bool expected) { // Given IMediator mediator = ServiceProvider.GetService <IMediator>(); MockEventPublisher publisher = new MockEventPublisher(mediator); MockSampleRepository repository = new MockSampleRepository( new Dictionary <string, Domain.Sample.Sample> { { "1", new Domain.Sample.Sample("1", "1") } }); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); Mock <ILogger <DeleteRequest> > logger = new Mock <ILogger <DeleteRequest> >(); DeleteHandler handler = new DeleteHandler(publisher, repository, uow.Object, logger.Object); DeleteRequest command = new DeleteRequest(id); // When Result result = await handler.Handle(command, new CancellationToken()); // Then List <ValidationResult> notValidNotifications = result.Notifications.Where(notification => !notification.IsValid).ToList(); if (expected) { Assert.Empty(notValidNotifications); } else { Assert.NotEmpty(notValidNotifications); } }
public async void FindHandler_Should_Work(string id, string description, int expected, int count) { // Given IMediator mediator = ServiceProvider.GetService <IMediator>(); MockEventPublisher publisher = new MockEventPublisher(mediator); MockSampleRepository repository = new MockSampleRepository( new Dictionary <string, Domain.Sample.Sample> { { "1", new Domain.Sample.Sample("1", "1") }, { "2", new Domain.Sample.Sample("2", "2") }, { "3", new Domain.Sample.Sample("3", "3") }, { "4", new Domain.Sample.Sample("4", "4") } }); Mock <ILogger <FindRequest> > logger = new Mock <ILogger <FindRequest> >(); FindHandler handler = new FindHandler(repository, publisher, logger.Object); FindRequest command = new FindRequest(id, description, 1, 3); // When QueryResult <SampleDto> result = await handler.Handle(command, new CancellationToken()); // Then List <ValidationResult> notValidNotifications = result.Notifications.Where(notification => !notification.IsValid).ToList(); Assert.Empty(notValidNotifications); Assert.Equal(expected, result.Items.Count()); Assert.Equal(count, result.Count); }
public ParseFileTestFixture() { UserId = Guid.NewGuid(); var eventPublisherMock = new MockEventPublisher((e) => { AllEvents.Add(e); }); var handler = new ParseFileCommandHandler(BlobStorage, eventPublisherMock.Object); Bus.RegisterHandler <ParseFile>(handler.Handle); var extractHandler = new ExtractMetaCommandHandler(BlobStorage, eventPublisherMock.Object); Bus.RegisterHandler <ExtractMeta>(extractHandler.Handle); }
public async void InsertHandler_Should_Work(string id, string description, bool expected) { // Given IMediator mediator = ServiceProvider.GetService <IMediator>(); MockEventPublisher publisher = new MockEventPublisher(mediator); MockSampleRepository repository = new MockSampleRepository(new Dictionary <string, Domain.Sample.Sample>()); Mock <IUnitOfWork> uow = new Mock <IUnitOfWork>(); MockSampleService service = new MockSampleService(); Mock <ILogger <InsertRequest> > logger = new Mock <ILogger <InsertRequest> >(); InsertHandler handler = new InsertHandler(publisher, repository, uow.Object, service, logger.Object); SampleDto item = new SampleDto { Id = id, Description = description }; InsertRequest command = new InsertRequest(item); // When EntityResult <SampleDto> result = await handler.Handle(command, new CancellationToken()); // Then List <ValidationResult> notValidNotifications = result.Notifications.Where(notification => !notification.IsValid).ToList(); if (expected) { Assert.Empty(notValidNotifications); Assert.True(ContainsType(publisher.Notifications, typeof(DomainEvent <InsertRequest>))); } else { Assert.NotEmpty(notValidNotifications); Assert.False(ContainsType(publisher.Notifications, typeof(DomainEvent <InsertRequest>))); } }