public async Task verify_that_new_contact_with_no_mortgage_is_stored_correctly() { var updateReviewQ = new Mock <IAsyncCollector <string> >(); var hubspotAdapter = new Mock <IHubSpotAdapter>(); // See note below; I'd rather mock the HttpClient and use a real HubSpotAdapter here. var data = new CanonicalContact("012345") { email = "*****@*****.**", firstName = "aa", lastName = "Postman", phone = "867 5309" }; var desiredResult = new HubSpotContactResult(data); // Set up a retval that the mock HubSpotAdapter might return hubspotAdapter.Setup(p => p.CreateHubspotContactAsync( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <ILogger>(), It.IsAny <bool>())) .ReturnsAsync(desiredResult); // Load in the JSON body of a typical create-crm request var filePath = @".\\TestData\\NewContactNoMortgage.json"; var body = File.ReadAllText(filePath, Encoding.UTF8); var query = new Dictionary <string, StringValues>(); // If we want to test query params, put them here. //query.Add("messageId", "ABC123"); var simulatedHttpRequest = this.HttpRequestSetup(query, body); var contactCreator = new CrmContactCreator(hubspotAdapter.Object); // Create the contact, with a mock error queue var result = await contactCreator.CreateNewContact(simulatedHttpRequest, _errorQueue, updateReviewQ.Object, _installationQueue, _logger); // TODO: Review these tests in the light of the new dependency-injection capabilities. Assert.IsType <OkObjectResult>(result); Assert.Single(_installationQueue.Items); // TODO: more assertions... }
public async Task verify_that_we_handle_some_changes() { var mockAdapter = new Mock <IHubSpotAdapter>(); var desiredResult = new HubSpotContactResult(HttpStatusCode.OK); mockAdapter.Setup(p => p.UpdateContactDetailsAsync( "012345", It.IsAny <HubSpotContactProperties>(), It.IsAny <ILogger>(), It.IsAny <bool>())).ReturnsAsync(desiredResult); var json_no_crmid = "{ \"crmid\": \"012345\", \"changes\": [{\"name\": \"Street Address\", \"value\": \"18 Example Place\"},{\"name\": \"Phone\", \"value\": \"0451443455\"}] }"; var func = new DequeueContactDiffs(mockAdapter.Object); await func.Run(json_no_crmid, _errorQueue, _logger); // We can handle a missing changes object without fuss Assert.Empty(_errorQueue.Items); }
public void HandleContractRejectedNotification() { // Contract Signed, Testy Webhookssen, Id 124 var filePath = @".\\TestData\\EventNotificationContractRejected.json"; var body = File.ReadAllText(filePath, Encoding.UTF8); var evt = JsonConvert.DeserializeObject <EventGridEvent>(body); var mockAdapter = new Mock <IHubSpotAdapter>(); var successResult = new HubSpotContactResult(HttpStatusCode.OK); // Make sure that the call to the adapter is made as expected mockAdapter.Setup(p => p.UpdateContractStatusAsync( "*****@*****.**", "Rejected", It.IsAny <ILogger>(), It.IsAny <bool>())).ReturnsAsync(successResult); var func = new UpdateContractStatusHandler(mockAdapter.Object); func.Run(evt, _errorQueue, _logger); Assert.Empty(_errorQueue.Items); }