public async Task EventSubscriptionState() { //initialising state for a new sub var newState = await Fixture.ConfigRepo.EventSubscriptionStates.GetAsync(100); Assert.Equal((long)100, newState.Id); Assert.Equal((long)100, newState.EventSubscriptionId); Assert.NotNull(newState.Values); //getting state for existing sub var stateDto = new EventSubscriptionStateDto { EventSubscriptionId = 99, Values = new System.Collections.Generic.Dictionary <string, object>() { { "key1", (object)"val1" }, { "key2", (object)1 } } }; await Fixture.ConfigRepo.EventSubscriptionStates.UpsertAsync(new[] { stateDto }); var fromRepo = await Fixture.ConfigRepo.EventSubscriptionStates.GetAsync(99); Assert.Equal(99, fromRepo.EventSubscriptionId); Assert.Equal(99, fromRepo.Id); Assert.Equal("val1", fromRepo.Values["key1"].ToString()); Assert.Equal((long)1, fromRepo.Values["key2"]); }
public ContractQueryBaseTest(ContractQueryConfiguration queryConfig) { this.queryConfig = queryConfig; decodedEvent = DecodedEvent.Empty(); Web3Mock web3Mock = new Web3Mock(); var fakeResults = new List <ParameterOutput>(); fakeResults.Add(new ParameterOutput { Result = FAKE_QUERY_RESULT }); subscriptionState = new EventSubscriptionStateDto(); MockEventSubscription = new Mock <IEventSubscription>(); MockEventSubscription.Setup(s => s.State).Returns(subscriptionState); contractQueryEventHandler = new ContractQueryEventHandler(MockEventSubscription.Object, 1, web3Mock.Eth, queryConfig); contractQueryEventHandler.QueryInterceptor = (abi, address, sig, inputs) => { actualQueryArgs = new QueryArgs { }; actualQueryArgs.Abi = abi; actualQueryArgs.ContractAddress = address; actualQueryArgs.FunctionSignature = sig; actualQueryArgs.FunctionInputValues = inputs; return(Task.FromResult(fakeResults)); }; }
public EventAggregatorTestsBase() { MockEventSubscription = new Mock <IEventSubscription>(); AggregatorConfig = CreateConfiguration(); EventSubscriptionState = new EventSubscriptionStateDto(); MockEventSubscription.Setup(s => s.State).Returns(EventSubscriptionState); Aggregator = new EventAggregator(MockEventSubscription.Object, 1, AggregatorConfig); }
private static Mock <IEventSubscription> CreateMockSubscription() { var mockSubscription = new Mock <IEventSubscription>(); var state = new EventSubscriptionStateDto(); mockSubscription.Setup(s => s.State).Returns(state); return(mockSubscription); }
public ContractQueryBaseTest(ContractQueryConfiguration queryConfig) { this.queryConfig = queryConfig; decodedEvent = DecodedEvent.Empty(); var mockContractQuery = MockContractQuery(FAKE_QUERY_RESULT, (actualArgs) => actualQueryArgs = actualArgs); subscriptionState = new EventSubscriptionStateDto(); MockEventSubscription = new Mock <IEventSubscription>(); MockEventSubscription.Setup(s => s.State).Returns(subscriptionState); contractQueryEventHandler = new ContractQueryEventHandler(MockEventSubscription.Object, 1, mockContractQuery, queryConfig); }
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 EventSubscription( long id = 0, long subscriberId = 0, EventSubscriptionStateDto state = null, string[] contractAddressesToMatch = null, IEventHandlerHistoryRepository eventHandlerHistoryDb = null, IEnumerable <IParameterCondition> parameterConditions = null) : base( id, subscriberId, new EventMatcher <TEvent>( new EventAddressMatcher(contractAddressesToMatch), new EventParameterMatcher(parameterConditions)), new EventHandlerManager(eventHandlerHistoryDb), state ?? new EventSubscriptionStateDto(id)) { }
public void FromEventAbis_SetsDefaultDependencies() { var state = new EventSubscriptionStateDto(); var eventHandlerHistoryDb = new Mock <IEventHandlerHistoryRepository>().Object; var contractAddresses = new[] { "0x243e72b69141f6af525a9a5fd939668ee9f2b354" }; var parameterConditions = new[] { ParameterCondition.Create(1, ParameterConditionOperator.Equals, "x") }; var eventSubscription = new EventSubscription( TestData.Contracts.StandardContract.ContractAbi.Events, contractAddresses, parameterConditions, 1, 2, state, eventHandlerHistoryDb); Assert.Equal(1, eventSubscription.Id); Assert.Equal(2, eventSubscription.SubscriberId); var eventHandlerManager = eventSubscription.HandlerManager as EventHandlerManager; Assert.NotNull(eventHandlerManager); Assert.Same(eventHandlerHistoryDb, eventHandlerManager.History); Assert.IsType <EventHandlerManager>(eventSubscription.HandlerManager); Assert.Same(state, eventSubscription.State); var eventMatcher = eventSubscription.Matcher as EventMatcher; Assert.NotNull(eventMatcher); var eventAddressMatcher = eventMatcher.AddressMatcher as EventAddressMatcher; Assert.NotNull(eventAddressMatcher); Assert.Equal(contractAddresses, eventAddressMatcher.AddressesToMatch); var parameterMatcher = eventMatcher.ParameterMatcher as EventParameterMatcher; Assert.NotNull(eventMatcher.ParameterMatcher); Assert.Equal(parameterConditions, parameterMatcher.ParameterConditions); }
public EventSubscriptionStateDto Add(EventSubscriptionStateDto dto) { EventSubscriptionStates.Add(dto); return(dto); }