public async Task OwnerClient_get_owner_by_id_long_works() { var response = await _client.GetByIdAsync <OwnerHubSpotEntity>(64); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.DeserializeGenericEntity <OwnerHubSpotEntity>("{}")).MustHaveHappened(); }
public async Task CompanyClient_create_contact_work() { var response = await _client.CreateAsync <CompanyHubSpotEntity>(new CompanyHubSpotEntity { Name = "A new Company", Description = "A new description" }); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.SerializeEntity(A <IHubSpotEntity> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.DeserializeEntity <CompanyHubSpotEntity>("{}")).MustHaveHappened(); }
public async Task AssociationClient_create_association_work() { var response = await _client.Create(new AssociationHubSpotEntity { FromObjectId = 10444744, ToObjectId = 259674, DefinitionId = (int)HubSpotAssociationDefinitions.CompanyToContact }); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.SerializeEntity(A <AssociationHubSpotEntity> .Ignored)).MustHaveHappened(); }
public async Task ContactClient_create_contact_work() { var response = await _client.CreateAsync <ContactHubSpotEntity>(new ContactHubSpotEntity { FirstName = "Adrian", Lastname = "Baws", Email = "*****@*****.**" }); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.SerializeEntity(A <IHubSpotEntity> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.DeserializeEntity <ContactHubSpotEntity>("{}")).MustHaveHappened(); }
public async Task DealClient_create_contact_work() { var response = await _client.CreateAsync <DealHubSpotEntity>(new DealHubSpotEntity { Name = "A new deal", Pipeline = "default", Amount = 60000, DealType = "newbusiness" }); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.SerializeEntity(A <IHubSpotEntity> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.DeserializeEntity <DealHubSpotEntity>("{}")).MustHaveHappened(); }
public HubSpotLineItemClientTest(ITestOutputHelper output) : base(output) { _mockHttpClient = A.Fake <IRapidHttpClient>(opts => opts.Strict()); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)) .Returns(Task.FromResult(CreateNewEmptyOkResponse())); _mockSerializer = A.Fake <RequestSerializer>(opts => opts.Strict()); A.CallTo(() => _mockSerializer.SerializeEntity(A <LineItemHubSpotEntity> .Ignored)) .Returns("{}"); A.CallTo(() => _mockSerializer.SerializeEntityToNameValueList <ILineItemHubSpotEntity>(A <LineItemHubSpotEntity> .Ignored)) .Returns("[]"); A.CallTo(() => _mockSerializer.DeserializeEntity <LineItemHubSpotEntity>(A <string> .Ignored)) .Returns(new LineItemHubSpotEntity()); _client = new HubSpotLineItemClient( _mockHttpClient, Logger, _mockSerializer, "https://api.hubapi.com", "HapiKeyFisk" ); }
public HubSpotAssociationClientTest(ITestOutputHelper output) : base(output) { _mockHttpClient = A.Fake <IRapidHttpClient>(opts => opts.Strict()); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)) .Returns(Task.FromResult(CreateNewEmptyOkResponse())); _mockSerializer = A.Fake <RequestSerializer>(opts => opts.Strict()); A.CallTo(() => _mockSerializer.SerializeEntity(A <AssociationHubSpotEntity> .Ignored)) .Returns("{}"); A.CallTo(() => _mockSerializer.DeserializeGenericEntity <AssociationHubSpotEntity>(A <string> .Ignored)) .Returns(new AssociationHubSpotEntity()); A.CallTo(() => _mockSerializer.DeserializeGenericEntity <AssociationListHubSpotEntity <long> >(A <string> .Ignored)) .Returns(new AssociationListHubSpotEntity <long>()); A.CallTo(() => _mockSerializer.SerializeEntities(A <List <AssociationHubSpotEntity> > .Ignored)) .Returns("{}"); _client = new HubSpotAssociationsClient( _mockHttpClient, Logger, _mockSerializer, "https://api.hubapi.com", "HapiKeyFisk" ); }
public async Task LineItemClient_create_lineitem_works() { var response = await _client.CreateAsync <LineItemHubSpotEntity>(new LineItemHubSpotEntity { Name = "A new deal", Price = 12.50M, ProductId = "12345", Quantity = 10, }); A.CallTo(() => _mockHttpClient.SendAsync(A <HttpRequestMessage> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.SerializeEntityToNameValueList <ILineItemHubSpotEntity>(A <LineItemHubSpotEntity> .Ignored)).MustHaveHappened(); A.CallTo(() => _mockSerializer.DeserializeEntity <LineItemHubSpotEntity>("{}")).MustHaveHappened(); }
/// <summary> /// Helper method for dispatching the requet and dealing with response errors /// </summary> /// <typeparam name="T">The type to deserialize as</typeparam> /// <param name="absoluteUriPath">The absolute path and query params to include in the request</param> /// <param name="httpMethod">HTTP method to use for the request</param> /// <param name="json">Optional json to send with the request</param> /// <param name="deserializeFunc">Func to handle deserialization of data when the request goes well</param> /// <returns>A deserialized entity with data when things go well, exceptionns otherwise</returns> private async Task <T> SendRequestAsync <T>(string absoluteUriPath, HttpMethod httpMethod, string json, Func <string, T> deserializeFunc) where T : IHubSpotEntity, new() { var fullUrl = $"{HubSpotBaseUrl}{absoluteUriPath}" .SetQueryParam("hapikey", _apiKey); Logger.LogDebug("Full url: '{0}'", fullUrl); var request = new HttpRequestMessage { Method = httpMethod, RequestUri = new Uri(fullUrl) }; if (!string.IsNullOrWhiteSpace(json)) { request.Content = new JsonContent(json); } var response = await HttpClient.SendAsync(request); var responseData = ""; if (response.Content != null) { responseData = await response.Content.ReadAsStringAsync(); } if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.NotFound) { return(default(T)); } throw new HubSpotException("Error from HubSpot", responseData); } if (string.IsNullOrWhiteSpace(responseData)) { return(default(T)); } return(deserializeFunc(responseData)); }