public async Task Store()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.Store,
                SubscriberQueueId   = 33
            };

            var storageConfig = new SubscriberStorageDto();
            var repo          = new Mock <IProcessorHandler <FilterLog> >();

            _subscriberStorageRepository
            .Setup(r => r.GetAsync(_mockEventSubscription.Object.SubscriberId, config.SubscriberRepositoryId))
            .ReturnsAsync(storageConfig);

            _subscriberStorageFactory
            .Setup(f => f.GetLogRepositoryHandlerAsync(storageConfig))
            .ReturnsAsync(repo.Object);

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var repositoryHandler = handler as StorageHandler;

            Assert.NotNull(repositoryHandler);
            Assert.Equal(config.Id, repositoryHandler.Id);
            Assert.Same(_mockEventSubscription.Object, repositoryHandler.Subscription);
            Assert.Same(repo.Object, repositoryHandler.LogHandler);
        }
        public async Task Index()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.Index
            };

            var searchIndexConfig = new SubscriberSearchIndexDto();
            var searchIndex       = new Mock <ISubscriberSearchIndex>();

            _subscriberSearchIndexRepository
            .Setup(r => r.GetAsync(_mockEventSubscription.Object.SubscriberId, config.SubscriberSearchIndexId))
            .ReturnsAsync(searchIndexConfig);


            _subscriberSearchIndexFactory
            .Setup(f => f.GetSubscriberSearchIndexAsync(searchIndexConfig))
            .ReturnsAsync(searchIndex.Object);

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var searchIndexHandler = handler as SearchIndexHandler;

            Assert.NotNull(searchIndexHandler);
            Assert.Equal(config.Id, searchIndexHandler.Id);
            Assert.Same(_mockEventSubscription.Object, searchIndexHandler.Subscription);
            Assert.Same(searchIndex.Object, searchIndexHandler.SubscriberSearchIndex);
        }
        public async Task Queue()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.Queue,
                SubscriberQueueId   = 33
            };

            var queueConfig = new SubscriberQueueDto();
            var queue       = new Mock <IQueue>();

            _subscriberQueueRepository
            .Setup(r => r.GetAsync(_mockEventSubscription.Object.Id, config.SubscriberQueueId))
            .ReturnsAsync(queueConfig);

            _subscriberQueueFactory
            .Setup(f => f.GetSubscriberQueueAsync(queueConfig))
            .ReturnsAsync(queue.Object);

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var queueHandler = handler as QueueHandler;

            Assert.NotNull(queueHandler);
            Assert.Equal(config.Id, queueHandler.Id);
            Assert.Same(_mockEventSubscription.Object, queueHandler.Subscription);
            Assert.Same(queue.Object, queueHandler.Queue);
        }
示例#4
0
        public EventSubscriptionFactoryTest()
        {
            _mockSubscriberRepo                   = new Mock <ISubscriberRepository>();
            _mockEventSubscriptionRepo            = new Mock <IEventSubscriptionRepository>();
            _mockEventHandlerRepo                 = new Mock <IEventHandlerRepository>();
            _mockEventSubscriptionStateRepository = new Mock <IEventSubscriptionStateRepository>();

            _mockDb = new Mock <IEventProcessingConfigurationRepository>();
            _mockDb.Setup(db => db.Subscribers).Returns(_mockSubscriberRepo.Object);
            _mockDb.Setup(db => db.EventSubscriptions).Returns(_mockEventSubscriptionRepo.Object);
            _mockDb.Setup(db => db.EventHandlers).Returns(_mockEventHandlerRepo.Object);
            _mockDb.Setup(db => db.EventSubscriptionStates).Returns(_mockEventSubscriptionStateRepository.Object);

            _mockEventHandlerFactory = new Mock <IEventHandlerFactory>();
            _mockEventMatcherFactory = new Mock <IEventMatcherFactory>();
            _factory          = new EventSubscriptionFactory(_mockDb.Object, _mockEventMatcherFactory.Object, _mockEventHandlerFactory.Object);
            _mockEventHandler = new Mock <IEventHandler>();
            _mockEventMatcher = new Mock <IEventMatcher>();

            _subscriberOneConfig = new SubscriberDto {
                Id = 1
            };
            _eventSubscriptionConfig = new EventSubscriptionDto
            {
                Id           = 1,
                SubscriberId = _subscriberOneConfig.Id
            };
            _eventHandlerConfig = new EventHandlerDto
            {
                Id = 1,
                EventSubscriptionId = _eventSubscriptionConfig.Id,
                HandlerType         = EventHandlerType.Queue
            };
            _eventSubscriptionStateConfig = new EventSubscriptionStateDto
            {
                Id = 1,
                EventSubscriptionId = _eventSubscriptionConfig.Id
            };

            _mockSubscriberRepo.Setup(d => d.GetManyAsync(PARTITION_ID)).ReturnsAsync(new[] { _subscriberOneConfig });
            _mockEventSubscriptionRepo.Setup(d => d.GetManyAsync(_subscriberOneConfig.Id)).ReturnsAsync(new[] { _eventSubscriptionConfig });
            _mockEventHandlerRepo.Setup(d => d.GetManyAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(new[] { _eventHandlerConfig });
            _mockEventSubscriptionStateRepository.Setup(d => d.GetAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(_eventSubscriptionStateConfig);

            _mockEventHandlerFactory.Setup(f => f.LoadAsync(It.IsAny <IEventSubscription>(), _eventHandlerConfig)).ReturnsAsync(_mockEventHandler.Object);
            _mockEventMatcherFactory.Setup(f => f.LoadAsync(_eventSubscriptionConfig)).ReturnsAsync(_mockEventMatcher.Object);
        }
        public async Task EventRule()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.Rule
            };

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var eventRuleHandler = handler as EventRule;

            Assert.NotNull(eventRuleHandler);
            Assert.Equal(config.Id, eventRuleHandler.Id);
            Assert.Same(_mockEventSubscription.Object, eventRuleHandler.Subscription);
        }
        public async Task GetTransaction()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.GetTransaction
            };

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var getTransactionHandler = handler as GetTransactionEventHandler;

            Assert.NotNull(getTransactionHandler);
            Assert.Equal(config.Id, getTransactionHandler.Id);
            Assert.Same(_mockEventSubscription.Object, getTransactionHandler.Subscription);
            Assert.Same(web3Mock.GetTransactionByHashMock.Object, getTransactionHandler.GetTransactionProxy);
        }
        public async Task Aggregate()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.Aggregate
            };

            var aggregateConfig = new EventAggregatorDto();

            _eventAggregatorConfigurationFactory
            .Setup(f => f.GetAsync(config.Id))
            .ReturnsAsync(aggregateConfig);

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var aggregator = handler as EventAggregator;

            Assert.NotNull(aggregator);
            Assert.Equal(config.Id, aggregator.Id);
            Assert.Same(_mockEventSubscription.Object, aggregator.Subscription);
            Assert.Same(aggregateConfig, aggregator.Configuration);
        }
        public async Task ContractQuery()
        {
            var config = new EventHandlerDto
            {
                Id = 50,
                EventSubscriptionId = 99,
                HandlerType         = EventHandlerType.ContractQuery
            };

            var contractQueryConfig = new ContractQueryConfiguration();

            _contractQueryFactory
            .Setup(f => f.GetAsync(_mockEventSubscription.Object.SubscriberId, config.Id))
            .ReturnsAsync(contractQueryConfig);

            var handler = await _eventHandlerFactory.LoadAsync(_mockEventSubscription.Object, config);

            var contractQueryEventHandler = handler as ContractQueryEventHandler;

            Assert.NotNull(contractQueryEventHandler);
            Assert.Equal(config.Id, contractQueryEventHandler.Id);
            Assert.Same(_mockEventSubscription.Object, contractQueryEventHandler.Subscription);
            Assert.Same(contractQueryConfig, contractQueryEventHandler.Configuration);
        }
 public EventHandlerDto Add(EventHandlerDto dto)
 {
     DecodedEventHandlers.Add(dto);
     return(dto);
 }
 public void SupplyMaterials(EventHandlerDto eventHandler)
 {
     _microserviceProxy.Put($"http://{UriInfo.ServiceName}/{UriInfo.Routes.Warehouse}", "snow");
     _eventRaiser.RaiseEvent(eventHandler, EventTypes.Structure_SnowmanProduction_SupplyMaterials_Success_1);
 }
示例#11
0
        public async Task EventHandlers()
        {
            var handler1 = new EventHandlerDto {
                Id = 1,
                EventSubscriptionId = 99,
                Disabled            = false,
                HandlerType         =
                    EventHandlerType.Queue,
                Order             = 1,
                SubscriberQueueId = 5
            };

            var handler2 = new EventHandlerDto
            {
                Id = 2,
                EventSubscriptionId = 99,
                Disabled            = false,
                HandlerType         =
                    EventHandlerType.Index,
                Order = 2,
                SubscriberSearchIndexId = 5
            };

            var handler3 = new EventHandlerDto
            {
                Id = 3,
                EventSubscriptionId = 100,
                Disabled            = false,
                HandlerType         =
                    EventHandlerType.Store,
                Order = 1,
                SubscriberRepositoryId = 7
            };

            await Fixture.ConfigRepo.EventHandlers.UpsertAsync(handler1);

            await Fixture.ConfigRepo.EventHandlers.UpsertAsync(handler2);

            await Fixture.ConfigRepo.EventHandlers.UpsertAsync(handler3);

            var sub1Handlers = await Fixture.ConfigRepo.EventHandlers.GetManyAsync(99);

            var sub2Handlers = await Fixture.ConfigRepo.EventHandlers.GetManyAsync(100);

            Assert.Equal(2, sub1Handlers.Length);
            Assert.Single(sub2Handlers);

            var queueHandler = sub1Handlers[0];

            Assert.Equal(handler1.Disabled, queueHandler.Disabled);
            Assert.Equal(handler1.HandlerType, queueHandler.HandlerType);
            Assert.Equal(handler1.Order, queueHandler.Order);
            Assert.Equal(handler1.SubscriberQueueId, queueHandler.SubscriberQueueId);

            var searchIndexHandler = sub1Handlers[1];

            Assert.Equal(handler2.SubscriberSearchIndexId, searchIndexHandler.SubscriberSearchIndexId);

            var storageHandler = sub2Handlers[0];

            Assert.Equal(handler3.SubscriberRepositoryId, storageHandler.SubscriberRepositoryId);
        }
示例#12
0
 public void Post([FromBody] EventHandlerDto eventHandler) => _cactusMaterialSupplier.SupplyMaterials(eventHandler);