예제 #1
0
        public async Task EventSubscriptions()
        {
            var sub1 = new EventSubscriptionDto
            {
                Id                     = 1,
                SubscriberId           = 99,
                CatchAllContractEvents = false,
                ContractId             = 2,
                Disabled               = false,
                EventSignatures        = new System.Collections.Generic.List <string>(new[] { "1", "2" })
            };

            var sub2 = new EventSubscriptionDto
            {
                Id                     = 2,
                SubscriberId           = 99,
                CatchAllContractEvents = false,
                ContractId             = 2,
                Disabled               = false,
                EventSignatures        = new System.Collections.Generic.List <string>(new[] { "", "" })
            };

            var sub3 = new EventSubscriptionDto
            {
                Id                     = 3,
                SubscriberId           = 100,
                CatchAllContractEvents = false,
                ContractId             = 2,
                Disabled               = false,
                EventSignatures        = new System.Collections.Generic.List <string>(new[] { "", "" })
            };

            await Fixture.ConfigRepo.EventSubscriptions.UpsertAsync(sub1);

            await Fixture.ConfigRepo.EventSubscriptions.UpsertAsync(sub2);

            await Fixture.ConfigRepo.EventSubscriptions.UpsertAsync(sub3);

            var sub1Subscriptions = await Fixture.ConfigRepo.EventSubscriptions.GetManyAsync(99);

            var sub2Subscriptions = await Fixture.ConfigRepo.EventSubscriptions.GetManyAsync(100);

            Assert.Equal(2, sub1Subscriptions.Length);
            Assert.Single(sub2Subscriptions);

            var sub1FromRepo = sub1Subscriptions.First();

            Assert.Equal(sub1.CatchAllContractEvents, sub1FromRepo.CatchAllContractEvents);
            Assert.Equal(sub1.ContractId, sub1FromRepo.ContractId);
            Assert.Equal(sub1.Disabled, sub1FromRepo.Disabled);
            Assert.Equal(sub1.EventSignatures, sub1FromRepo.EventSignatures);
        }
예제 #2
0
        public EventMatcherFactoryTest()
        {
            _mockParameterConditionRepository       = new Mock <IParameterConditionRepository>();
            _mockEventSubscriptionAddressRepository = new Mock <IEventSubscriptionAddressRepository>();
            _mockSubscriberContractRepository       = new Mock <ISubscriberContractRepository>();

            _factory = new EventMatcherFactory(
                _mockParameterConditionRepository.Object,
                _mockEventSubscriptionAddressRepository.Object,
                _mockSubscriberContractRepository.Object);

            _subscriberOneConfig = new SubscriberDto {
                Id = 1
            };
            _contractDto = new SubscriberContractDto
            {
                Id           = 1,
                SubscriberId = _subscriberOneConfig.Id,
                Abi          = TestData.Contracts.StandardContract.Abi,
                Name         = "Transfer"
            };
            _eventSubscriptionConfig = new EventSubscriptionDto
            {
                Id              = 1,
                SubscriberId    = _subscriberOneConfig.Id,
                ContractId      = _contractDto.Id,
                EventSignatures = new[] { TestData.Contracts.StandardContract.TransferEventSignature }.ToList()
            };
            _addressesConfig = new EventSubscriptionAddressDto
            {
                Id                  = 1,
                Address             = "",
                EventSubscriptionId = _eventSubscriptionConfig.Id
            };
            _parameterConditionConfig = new ParameterConditionDto
            {
                Id = 1,
                EventSubscriptionId = _eventSubscriptionConfig.Id,
                ParameterOrder      = 1,
                Operator            = ParameterConditionOperator.Equals,
                Value = "xyz"
            };

            _mockSubscriberContractRepository.Setup(d => d.GetAsync(_subscriberOneConfig.Id, _contractDto.Id)).ReturnsAsync(_contractDto);
            _mockEventSubscriptionAddressRepository.Setup(d => d.GetManyAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(new[] { _addressesConfig });
            _mockParameterConditionRepository.Setup(d => d.GetManyAsync(_eventSubscriptionConfig.Id)).ReturnsAsync(new[] { _parameterConditionConfig });
        }
예제 #3
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 EventSubscriptionDto Add(EventSubscriptionDto dto)
 {
     EventSubscriptions.Add(dto);
     return(dto);
 }