Beispiel #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();
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public async Task GetContact_forwards_to_client(EmailContactSelector sut, HubSpotContact contact, IReadOnlyList <Property> properties)
        {
            mockContactClient.Setup(p => p.GetByEmailAsync(It.IsAny <string>(), It.IsAny <IReadOnlyList <IProperty> >(), It.IsAny <PropertyMode>(), It.IsAny <FormSubmissionMode>(), It.IsAny <bool>()))
            .ReturnsAsync(contact);

            var response = await sut.GetContact(mockClient.Object, properties);

            Assert.That(response, Is.SameAs(contact));

            mockContactClient.Verify(p => p.GetByEmailAsync(It.IsAny <string>(), properties, PropertyMode.ValueOnly, FormSubmissionMode.None, false), Times.Once);
        }
        public async Task Basic_contacts_can_be_retrieved_by_id(long contactId, string firstName, string lastName, string email, DateTimeOffset createdDate)
        {
            var fromApi = new HubSpotContact
            {
                Id         = contactId,
                Properties = new Dictionary <string, VersionedProperty>
                {
                    ["firstname"] = new VersionedProperty {
                        Value = firstName
                    },
                    ["lastname"] = new VersionedProperty {
                        Value = lastName
                    },
                    ["email"] = new VersionedProperty {
                        Value = email
                    },
                    ["createdate"] = new VersionedProperty {
                        Value = createdDate.ToUnixTimeMilliseconds().ToString("D")
                    }
                }
            };

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

            var sut = CreateSystemUnderTest();

            var result = await sut.GetByIdAsync <Contact>(contactId);

            mockClient.Verify(
                p => p.GetByIdAsync(
                    contactId,
                    It.Is <IReadOnlyList <IProperty> >(list => list.Select(l => l.Name).IsSupersetOf(fromApi.Properties.Keys)),
                    PropertyMode.ValueOnly,
                    FormSubmissionMode.None,
                    false),
                Times.Once
                );

            Assert.That(result, Is.InstanceOf <Contact>());

            Assert.That(result.Email, Is.EqualTo(email));
            Assert.That(result.FirstName, Is.EqualTo(firstName));
            Assert.That(result.LastName, Is.EqualTo(lastName));
            Assert.That(result.Created, Is.EqualTo(createdDate).Within(TimeSpan.FromMilliseconds(100)));
        }