public async Task Handle(SpfRecordExpired message)
        {
            string id = message.Id.ToLower();

            SpfEntityState state = await LoadState(id, nameof(message));

            Message evnt = state.UpdatePollPending();

            state.Version++;

            await _dao.Save(state);

            _dispatcher.Dispatch(evnt, _spfEntityConfig.SnsTopicArn);
        }
예제 #2
0
        public async Task ItShouldRaiseARecordMessageAndSaveStateForNewlyCreatedEntities()
        {
            await PurgeAmazonSqsQueue(OutputQueueUrl);
            await TruncateDatabase(ConnectionString);

            SpfEntityCreated entityCreated = new SpfEntityCreated("ncsc.gov.uk", 1);

            InvokeLambda(entityCreated);

            List <Message> messages = await ReadAmazonSqsEvent(OutputQueueUrl, ReadTimeoutSecond);

            Assert.That(messages.Count, Is.EqualTo(1));
            Assert.That(messages[0], Is.TypeOf <SpfRecordExpired>());

            SpfRecordExpired expiredMessage = (SpfRecordExpired)messages[0];

            Assert.That(expiredMessage.Id, Is.EqualTo(entityCreated.Id));

            List <SpfSchedulerState> states = await GetStates(ConnectionString);

            Assert.That(states.Count, Is.EqualTo(1));
            Assert.That(states[0].Id, Is.EqualTo(expiredMessage.Id));
        }
        public async Task ItShouldRaiseEventsWhenThereAreExpiredRecords()
        {
            await PurgeAmazonSqsQueue(OutputQueueUrl);
            await TruncateDatabase(ConnectionString);

            DateTime expiredDate = DateTime.UtcNow.Subtract(TimeSpan.FromHours(25));

            await Insert("ncsc.gov.uk", expiredDate);

            await TriggerLambda(LambdaFunctionName);

            DateTime updatedLastChecked = await GetLastChecked("ncsc.gov.uk");

            Assert.That(updatedLastChecked, Is.GreaterThan(expiredDate));

            List <Message> messages = await ReadAmazonSqsEvent(OutputQueueUrl, ReadTimeoutSecond);

            Assert.That(messages.Count, Is.EqualTo(1));
            Assert.That(messages[0], Is.TypeOf <SpfRecordExpired>());

            SpfRecordExpired expiredMessage = (SpfRecordExpired)messages[0];

            Assert.That(expiredMessage.Id, Is.EqualTo("ncsc.gov.uk"));
        }