Example #1
0
        public async Task Test_AddsLead_StartsFromApi()
        {
            // Arrange
            await _apiFactory.SeedDatabase(DataSeeds);

            var addLead = new LeadApi.Client.Lead {
                Name = "Test Tester 2", ZipCode = "60641"
            };
            var session = _leadServicebusHostFactory.Services.GetService <IMessageSession>();

            // Act
            var result = await EndpointFixture.ExecuteAndWaitForHandled <AddLead>(
                () => _leadClient.AddLeadFromMessagingAsync(addLead));

            // Assert
            var successMessages = result.SentMessages.OfType <LeadAddedSuccessfully>();

            Assert.IsTrue(successMessages.Count() > 0);
            Assert.IsTrue(successMessages.First().LeadID > 0);

            var lead = await _leadClient.GetLeadAsync(successMessages.First().LeadID);

            Assert.AreEqual(successMessages.First().LeadID, lead.LeadID);
            Assert.AreEqual(addLead.Name, lead.Name);
            Assert.AreEqual(addLead.ZipCode, lead.ZipCode);
        }
Example #2
0
        public async Task Test_MatchingSagaNoMatches_StartsFromApi()
        {
            // Arrange
            await _apiFactory.SeedDatabase(DataSeeds);

            var addLead = new LeadApi.Client.Lead {
                Name = "Test Tester 3", ZipCode = "12345"
            };
            var session = _leadServicebusHostFactory.Services.GetService <IMessageSession>();

            // Act
            var result = await EndpointFixture.ExecuteAndWaitForSagaCompletion <LeadMatchingProcessSaga>(
                async() => await _leadClient.AddLeadFromMessagingAsync(addLead));

            // Assert Matching Process Finished
            var finalEvent = result.SentMessages.OfType <MatchingProcessFinished>()
                             .FirstOrDefault();

            Assert.IsNotNull(finalEvent);
            Assert.IsTrue(finalEvent.MatchIDs.Count() == 0);

            // Assert Saga Data Is Correct
            var saga = result.InvokedHandlers.LastOrDefault(x =>
                                                            x.MessageHandler.HandlerType == typeof(LeadMatchingProcessSaga)).GetSagaInstance();
            var sagaData = (LeadMatchingData)saga.Instance.Entity;

            Assert.IsNotNull(sagaData);
            Assert.IsTrue(sagaData.ContractorIDs.Count() == 0);
            Assert.AreEqual(addLead.Name, sagaData.Name);
            Assert.AreEqual(addLead.ZipCode, sagaData.ZipCode);

            // Assert Database is Up To Date
            var matches = await _leadClient.GetMatchesAsync(sagaData.LeadID);

            Assert.AreEqual(0, matches.Count());
        }