Skip to content

Instantly share code, notes, and snippets.

@Kralizek
Last active February 27, 2018 16:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kralizek/248200b93b93d0e3172b2dcc7d4faea2 to your computer and use it in GitHub Desktop.
Save Kralizek/248200b93b93d0e3172b2dcc7d4faea2 to your computer and use it in GitHub Desktop.
Customization with timed Do
public class Contact : IHubSpotEntity
{
[DefaultProperty("vid")]
public long Id { get; set; }
[DefaultProperty("portal-id")]
public long PortalId { get; set; }
[DefaultProperty("is-contact")]
public bool IsContact { get; set; }
[DefaultProperty("profile-token")]
public string UserToken { get; set; }
[DefaultProperty("profile-url")]
public Uri ProfileUrl { get; set; }
[CustomProperty("email")]
public string Email { get; set; }
[CustomProperty("createdate", IsReadOnly = true)]
public DateTimeOffset Created { get; set; }
[CustomProperty("firstname")]
public string FirstName { get; set; }
[CustomProperty("lastname")]
public string LastName { get; set; }
[CustomProperty("lastmodifieddate", IsReadOnly = true)]
public DateTimeOffset LastModified { get; set; }
[CustomProperty("associatedcompanyid")]
public long AssociatedCompanyId { get; set; }
IReadOnlyDictionary<string, object> IHubSpotEntity.Properties { get; set; } = new Dictionary<string, object>();
}
public class ContactAutoDataAttribute : AutoDataAttribute
{
public ContactAutoDataAttribute() : base(CreateFixture)
{
}
public static IFixture CreateFixture()
{
IFixture fixture = new Fixture();
fixture.Customize<Contact>(c => c.Do(contact =>
{
((IHubSpotEntity)contact).Properties = new Dictionary<string, object>
{
["firstname"] = contact.FirstName,
["lastname"] = contact.LastName,
["email"] = contact.Email,
["createdate"] = contact.Created,
["associatedcompanyId"] = contact.AssociatedCompanyId
};
}));
return fixture;
}
}
[Test, ContactAutoData]
public void Customization_works(Contact contact)
{
IHubSpotEntity hubSpot = contact;
Assert.That(contact.FirstName, Is.EqualTo(hubSpot.Properties["firstname"])); // BOOM!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment