public void TestGetPropertiesForCreate() { var company = new Company { DenariAccountId = "12345", DenariIntroDate = DateTime.Parse("1980-10-02", DateTimeFormatInfo.InvariantInfo), BigGiftAmount = 12345m, }; string properties = DomainModelMapper.GetPropertiesForCreate(company); Assert.NotNull(properties); // strings should be quoted Assert.True(properties.Contains($"\"account_id\": \"{company.DenariAccountId}\"", StringComparison.InvariantCulture)); // dates should be milliseconds since unix epoch string dateAsUnixOffset = new DateTimeOffset((DateTime)company.DenariIntroDate).ToUnixTimeMilliseconds().ToString(DateTimeFormatInfo.InvariantInfo); Assert.True(properties.Contains($"\"denari_intro_date\": \"{dateAsUnixOffset}\"", StringComparison.InvariantCulture)); // numbers should be quoted string stringGiftAmount = $"{company.BigGiftAmount:N}".Replace(",", string.Empty, StringComparison.InvariantCulture); Assert.True(properties.Contains($"\"big_gift_amount\": \"{stringGiftAmount}\"", StringComparison.InvariantCulture)); }
private async Task <CrmObject> CreateCompanyAsync(Company company, CancellationToken cancellationToken) { using var content = new StringContent(DomainModelMapper.GetPropertiesForCreate(company), Encoding.UTF8, "application/json"); var response = await RequestWithRetriesAsync( async cancellationToken => await m_client.PostAsync("/crm/v3/objects/companies", content, cancellationToken), cancellationToken); await response.EnsureSuccessStatusCodeWithResponseBodyInException(); return(JsonConvert.DeserializeObject <CrmObject>(await response.Content.ReadAsStringAsync())); }