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); }
public async Task Test_AddLead() { // Arrange //var apiFactory = new LeadApiFactory(); await _apiFactory.SeedDatabase(async context => { await context.SaveChangesAsync(); }); var client = _apiFactory.CreateLeadClient(); var lead = new LeadApi.Client.Lead { Name = "Phill", ZipCode = "60640" }; // Act var result = await client.AddLeadAsync(lead); // Assert Assert.IsTrue(result.LeadID > 0); Assert.AreEqual(result.Name, lead.Name); Assert.AreEqual(result.ZipCode, lead.ZipCode); }
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()); }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <exception cref="ApiException">A server side error occurred.</exception> public async System.Threading.Tasks.Task AddLeadFromMessagingAsync(Lead lead, System.Threading.CancellationToken cancellationToken) { if (lead == null) { throw new System.ArgumentNullException("lead"); } var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append("Lead/AddFromMessaging"); var client_ = _httpClient; var disposeClient_ = false; try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(lead, _settings.Value)); content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); var disposeResponse_ = true; try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); if (response_.Content != null && response_.Content.Headers != null) { foreach (var item_ in response_.Content.Headers) { headers_[item_.Key] = item_.Value; } } ProcessResponse(client_, response_); var status_ = (int)response_.StatusCode; if (status_ == 200) { return; } else { var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); } } finally { if (disposeResponse_) { response_.Dispose(); } } } } finally { if (disposeClient_) { client_.Dispose(); } } }
/// <exception cref="ApiException">A server side error occurred.</exception> public System.Threading.Tasks.Task AddLeadFromMessagingAsync(Lead lead) { return(AddLeadFromMessagingAsync(lead, System.Threading.CancellationToken.None)); }
/// <exception cref="ApiException">A server side error occurred.</exception> public System.Threading.Tasks.Task <Lead> AddLeadAsync(Lead lead) { return(AddLeadAsync(lead, System.Threading.CancellationToken.None)); }