Last active
February 27, 2018 16:44
-
-
Save Kralizek/248200b93b93d0e3172b2dcc7d4faea2 to your computer and use it in GitHub Desktop.
Customization with timed Do
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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