コード例 #1
0
        public async Task When_HttpResponseIsSuccessful_Then_HubspotContactMustEqualTheExpected()
        {
            using (var httpResponse = new HttpResponseMessage())
            {
                // arrange
                var expectedContact = new HubspotContact
                {
                    Id        = "512",
                    CreatedAt = DateTime.Parse("2019-10-30T03:30:17.883Z").ToUniversalTime(),
                    UpdatedAt = DateTime.Parse("2019-12-07T16:50:06.678Z").ToUniversalTime(),
                    Archived  = false,
                };
                expectedContact.Properties.Add("company", "Biglytics");
                expectedContact.Properties.Add("createdate", "2019-10-30T03:30:17.883Z");
                expectedContact.Properties.Add("email", "*****@*****.**");
                expectedContact.Properties.Add("firstname", "Bryan");
                expectedContact.Properties.Add("lastmodifieddate", "2019-12-07T16:50:06.678Z");
                expectedContact.Properties.Add("lastname", "Cooper");
                expectedContact.Properties.Add("phone", "(877) 929-0687");
                expectedContact.Properties.Add("website", "biglytics.net");
                httpResponse.StatusCode = HttpStatusCode.Created;
                httpResponse.Content    = new StreamContent(new FileStream("fixtures/hubspot-contact-create-response.json", FileMode.Open));

                // act
                var response = await httpResponse.MapToCreateContactResponse();

                // assert
                var parsedResponse = Assert.IsType <ContactSuccessResponse>(response);
                Assert.Equal(expectedContact, parsedResponse.Contact, new HubspotContactUnitTestEqualityComparer());
            }
        }
コード例 #2
0
        public async Task <HttpResponseMessage> AddContactAsync(Submission data)
        {
            HubspotContact contact = data.CreateContact(_options.AssignedUser);

            try {
                HttpClient client   = _clientFactory.CreateClient();
                var        response = await client.PostAsJsonAsync(CONTACT_ADD_URL + _options.APIkey, contact);

                return(response);
            }
            catch (Exception ex) {
                _logger.LogError(ex.Message);
                return(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }