Exemple #1
0
        public async Task QueueEvent_Queue()
        {
            // Arrange
            var compassEvent = new CompassEvent
            {
                EventName = "test"
            };

            var queuedEvents = new QueuedEvents()
            {
                Events = new List <CompassEvent>()
                {
                    compassEvent
                }
            };

            A.CallTo(() => _dataStore.GetQueuedEventsAsync())
            .Returns(Task.FromResult(queuedEvents));

            // Act
            await _sut.QueueEventAsync(compassEvent);

            // Assert
            A.CallTo(() => _dataStore.UpsertAsync(queuedEvents)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => _dataStore.UpsertAsync(A <QueuedEvents> .That.Matches(arg => arg.Events.Contains(compassEvent))))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
        public Policy GetPolicy(CompassEvent compassEvent)
        {
            var fallback = Policy
                           .Handle <NoValidSubscriptionsException>()
                           .FallbackAsync(
                (context, cancellationToken) => _queueEventService.QueueEventAsync(compassEvent),
                (exception, context) => throw exception
                );

            var retry = Policy
                        .Handle <NoValidSubscriptionsException>()
                        .WaitAndRetryAsync(GetTimeSpans());

            return(Policy
                   .WrapAsync(fallback, retry));
        }