Ejemplo n.º 1
0
        public async Task Should_have_the_state_machine()
        {
            Guid correlationId = Guid.NewGuid();

            await InputQueueSendEndpoint.Send(new GirlfriendYelling
            {
                CorrelationId = correlationId
            });

            var saga = await GetSagaRetry(correlationId, TestTimeout);

            Assert.IsNotNull(saga);

            await InputQueueSendEndpoint.Send(new GotHitByACar
            {
                CorrelationId = correlationId
            });

            saga = await GetSagaRetry(correlationId, TestTimeout, x => x.CurrentState == _machine.Dead.Name);

            Assert.IsNotNull(saga);
            Assert.IsTrue(saga.CurrentState == _machine.Dead.Name);

            ShoppingChore instance = await GetSaga(correlationId);

            Assert.IsTrue(instance.Screwed);
        }
Ejemplo n.º 2
0
        async Task <ShoppingChore> GetNoSagaRetry(Guid id, TimeSpan timeout)
        {
            DateTime      giveUpAt = DateTime.Now + timeout;
            ShoppingChore saga     = null;

            while (DateTime.Now < giveUpAt)
            {
                try
                {
                    var document = await _documentClient.ReadDocumentAsync(UriFactory.CreateDocumentUri(_databaseName, _collectionName, id.ToString()));

                    saga = JsonConvert.DeserializeObject <ShoppingChore>(document.Resource.ToString());

                    await Task.Delay(10).ConfigureAwait(false);
                }
                catch (DocumentClientException e) when(e.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    saga = null;
                    break;
                }
            }

            return(saga);
        }