Пример #1
0
        private async Task <CrmObject> UpdateCompanyAsync(Company updatedCompany, Company existingCompany, CancellationToken cancellationToken)
        {
            if (DomainModelMapper.GetPropertiesForUpdate(updatedCompany, existingCompany, out string propertiesJson))
            {
                using var content = new StringContent(propertiesJson, Encoding.UTF8, "application/json");
                var response = await RequestWithRetriesAsync(
                    async cancellationToken => await m_client.PatchAsync($"/crm/v3/objects/companies/{existingCompany.Id}", content, cancellationToken),
                    cancellationToken);

                await response.EnsureSuccessStatusCodeWithResponseBodyInException();

                return(JsonConvert.DeserializeObject <CrmObject>(await response.Content.ReadAsStringAsync()));
            }
            else
            {
                return(existingCompany);
            }
        }
        public void TestGetPropertiesForUpdate()
        {
            var existing = new Company
            {
                DenariAccountId = "12345",
            };

            var updated = new Company
            {
                DenariAccountId = "54321",
            };

            DomainModelMapper.GetPropertiesForUpdate(updated, existing, out string properties);
            Assert.NotNull(properties);

            // new property should be present, not old one
            Assert.True(properties.Contains($"\"account_id\": \"{updated.DenariAccountId}\"", StringComparison.InvariantCulture));
            Assert.False(properties.Contains($"\"account_id\": \"{existing.DenariAccountId}\"", StringComparison.InvariantCulture));
        }