示例#1
0
        public async Task GetAsync_forwards_to_selector(HubSpotContact contact, TestContact expected, CustomPropertyInfo[] properties)
        {
            mockTypeManager.Setup(p => p.ConvertTo <TestContact>(contact))
            .Returns(expected)
            .Verifiable();

            mockTypeManager.Setup(p => p.GetCustomProperties <TestContact>(TypeManager.AllProperties))
            .Returns(properties);

            var mockSelector = new Mock <IContactSelector>(MockBehavior.Strict);

            mockSelector.Setup(p => p.GetContact(It.IsAny <IHubSpotClient>(), It.IsAny <IReadOnlyList <IProperty> >()))
            .ReturnsAsync(contact)
            .Verifiable();

            var sut = CreateSystemUnderTest();

            var result = await sut.GetAsync <TestContact>(mockSelector.Object);

            Assert.That(result, Is.SameAs(expected));

            mockTypeManager.Verify();

            mockSelector.Verify();
        }
        public async Task Basic_contacts_can_be_updated(TestContact input, string newFirstName)
        {
            Assume.That(newFirstName, Is.Not.EqualTo(input.FirstName));

            var fromApi = CreateFromContact(input);

            mockClient.Setup(p => p.GetByIdAsync(
                                 input.Id,
                                 It.IsAny <IReadOnlyList <IProperty> >(),
                                 PropertyMode.ValueOnly,
                                 FormSubmissionMode.None,
                                 false)
                             )
            .ReturnsAsync(fromApi);

            mockClient.Setup(p => p.UpdateByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <ValuedProperty> >())).CompletesAsync();

            var sut = CreateSystemUnderTest();

            var contact = await sut.GetByIdAsync(input.Id);

            contact.FirstName = newFirstName;

            var updatedContact = await sut.SaveAsync(contact);

            Assert.That(updatedContact.Id, Is.EqualTo(input.Id));
        }
示例#3
0
        private static HubSpotContact CreateFromContact(TestContact contact)
        {
            var hubspot = new HubSpotContact
            {
                Id         = contact.Id,
                Properties = new Dictionary <string, VersionedProperty>
                {
                    ["firstname"] = new VersionedProperty {
                        Value = contact.FirstName
                    },
                    ["lastname"] = new VersionedProperty {
                        Value = contact.LastName
                    },
                    ["email"] = new VersionedProperty {
                        Value = contact.Email
                    },
                    ["createdate"] = new VersionedProperty {
                        Value = contact.Created.ToUnixTimeMilliseconds().ToString("D")
                    },
                    ["associatedcompanyid"] = new VersionedProperty()
                    {
                        Value = contact.AssociatedCompanyId.ToString("D")
                    },
                    ["customProperty"] = new VersionedProperty {
                        Value = contact.CustomProperty
                    }
                }
            };

            return(hubspot);
        }
        public async Task Unmodified_contact_should_not_be_persisted(TestContact contact)
        {
            SetPropertyDictionary(contact);

            var sut = CreateSystemUnderTest();

            var newContact = await sut.SaveAsync(contact);

            mockClient.Verify(p => p.CreateAsync(It.IsAny <IReadOnlyList <ValuedProperty> >()), Times.Never);

            mockClient.Verify(p => p.UpdateByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <ValuedProperty> >()), Times.Never);

            Assert.That(newContact, Is.SameAs(contact));
        }
 private static void SetPropertyDictionary(TestContact testContact)
 {
     ((IHubSpotEntity)testContact).Properties = new Dictionary <string, object>
     {
         ["firstname"]                   = testContact.FirstName,
         ["lastname"]                    = testContact.LastName,
         ["email"]                       = testContact.Email,
         ["createdate"]                  = testContact.Created,
         ["associatedcompanyid"]         = testContact.AssociatedCompanyId,
         ["customProperty"]              = testContact.CustomProperty,
         ["stringListProperty"]          = testContact.StringListProperty,
         ["stringArrayProperty"]         = testContact.StringArrayProperty,
         ["stringIListProperty"]         = testContact.StringIListProperty,
         ["stringIEnumerableProperty"]   = testContact.StringIEnumerableProperty,
         ["stringIReadOnlyListProperty"] = testContact.StringIReadOnlyListProperty
     };
 }
        public async Task Basic_contacts_can_be_created(TestContact contact)
        {
            var toCreate = CreateFromContact(contact);

            contact.Id      = 0;
            contact.Created = default;

            mockClient.Setup(p => p.CreateAsync(It.IsAny <IReadOnlyList <ValuedProperty> >()))
            .ReturnsAsync(toCreate);

            var sut = CreateSystemUnderTest();

            var newContact = await sut.SaveAsync(contact);

            Assert.That(newContact.FirstName, Is.EqualTo(contact.FirstName));
            Assert.That(newContact.Id, Is.EqualTo(toCreate.Id));
        }
        public async Task Value_property_reset_to_default_value_should_be_persisted(TestContact contact)
        {
            SetPropertyDictionary(contact);

            contact.AssociatedCompanyId = 0;

            mockClient.Setup(p => p.UpdateByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <ValuedProperty> >())).CompletesAsync();

            mockClient.Setup(p => p.GetByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <IProperty> >(), It.IsAny <PropertyMode>(), It.IsAny <FormSubmissionMode>(), It.IsAny <bool>())).ReturnsAsync(CreateFromContact(contact));

            var sut = CreateSystemUnderTest();

            var newContact = await sut.SaveAsync(contact);

            mockClient.Verify(p => p.UpdateByIdAsync(contact.Id, It.Is <IReadOnlyList <ValuedProperty> >(c => c.Single().Property == "associatedcompanyid")), Times.Once);

            Assert.That(newContact.AssociatedCompanyId, Is.EqualTo(0));
        }
示例#8
0
        public async Task SaveAsync_persists_a_new_contact(TestContact contact, PropertyData[] properties)
        {
            contact.Id      = 0;
            contact.Created = default;

            var toCreate = CreateFromContact(contact);

            mockTypeManager.Setup(p => p.GetPropertyData(It.IsAny <TestContact>())).Returns(properties);

            mockContactClient.Setup(p => p.CreateAsync(It.IsAny <IReadOnlyList <ValuedProperty> >())).ReturnsAsync(toCreate);

            mockTypeManager.Setup(p => p.ConvertTo <TestContact>(It.IsAny <HubSpotContact>())).Returns(contact);

            var sut = CreateSystemUnderTest();

            var newContact = await sut.SaveAsync(contact);

            Assert.That(newContact, Is.SameAs(contact));
        }
示例#9
0
        public async Task Reference_property_reset_to_default_value_should_be_persisted(TestContact contact)
        {
            SetPropertyDictionary(contact);

            contact.CustomProperty = null;

            mockClient.Setup(p => p.UpdateByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <ValuedProperty> >())).CompletesAsync();

            mockClient.Setup(p => p.GetByIdAsync(It.IsAny <long>(), It.IsAny <IReadOnlyList <IProperty> >(), It.IsAny <PropertyMode>(), It.IsAny <FormSubmissionMode>(), It.IsAny <bool>())).ReturnsAsync(CreateFromContact(contact));

            var sut = CreateSystemUnderTest();

            var newContact = await sut.SaveAsync(contact);

            mockClient.Verify(p => p.UpdateByIdAsync(contact.Id, It.IsAny <IReadOnlyList <ValuedProperty> >()), Times.Once);

            Assert.That(newContact.CustomProperty, Is.Null);
        }
示例#10
0
 public async Task SaveAsync_persists_a_new_contact(TestContact contact, (string, string)[] properties)