-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
1,099 additions
and
266 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using StrongGrid.Models; | ||
using StrongGrid.Models.Search; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
@@ -72,17 +73,15 @@ public async Task RunAsync(IClient client, TextWriter log, CancellationToken can | |
{ | ||
new KeyValuePair<SearchLogicalOperator, IEnumerable<ISearchCriteria>>(SearchLogicalOperator.And, new[] | ||
{ | ||
new SearchCriteriaEqual(ContactsFilterField.FirstName, "Jane"), | ||
new SearchCriteriaEqual(ContactsFilterField.LastName, "Doe") | ||
new SearchCriteriaLike(ContactsFilterField.EmailAddress, "%hotmail.com") | ||
}) | ||
}; | ||
var segment = await client.Segments.CreateAsync("StrongGrid Integration Testing: First Name is Jane and last name is Doe", filterConditions, list.Id, cancellationToken).ConfigureAwait(false); | ||
var segment = await client.Segments.CreateAsync("StrongGrid Integration Testing: Recipients @ Hotmail", filterConditions, list.Id, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"Segment '{segment.Name}' created. Id: {segment.Id}").ConfigureAwait(false); | ||
|
||
// UPDATE THE SEGMENT (three contacts match the criteria) | ||
var hotmailCriteria = new SearchCriteriaLike(ContactsFilterField.EmailAddress, "%hotmail.com"); | ||
segment = await client.Segments.UpdateAsync(segment.Id, "StrongGrid Integration Testing: Recipients @ Hotmail", hotmailCriteria, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"Segment {segment.Id} updated. The new name is: '{segment.Name}'").ConfigureAwait(false); | ||
// PLEASE NOTE: you must wait at least 5 minutes before updating a segment. | ||
// If you attempt to update a segment too quickly, the SendGrid API will throw the following exception: | ||
// "Update request came too soon, please wait 5 minutes before trying again" | ||
|
||
// GET THE SEGMENT | ||
segment = await client.Segments.GetAsync(segment.Id, cancellationToken).ConfigureAwait(false); | ||
|
@@ -91,6 +90,17 @@ public async Task RunAsync(IClient client, TextWriter log, CancellationToken can | |
// GET THE CONTACTS | ||
contacts = await client.Contacts.GetMultipleByEmailAddressAsync(new[] { "[email protected]", "[email protected]", "[email protected]" }, cancellationToken).ConfigureAwait(false); | ||
|
||
// CREATE ANOTHER SEGMENT | ||
filterConditions = new[] | ||
{ | ||
new KeyValuePair<SearchLogicalOperator, IEnumerable<ISearchCriteria>>(SearchLogicalOperator.And, new[] | ||
{ | ||
new SearchCriteriaGreaterThan(ContactsFilterField.ModifiedOn, DateTime.UtcNow.AddYears(-1)), | ||
}) | ||
}; | ||
var anotherSegment = await client.Segments.CreateAsync("StrongGrid Integration Testing: Modified in the prior year", filterConditions, list.Id, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"Segment '{anotherSegment.Name}' created. Id: {anotherSegment.Id}").ConfigureAwait(false); | ||
|
||
// REMOVE THE CONTACTS FROM THE LIST (THEY WILL AUTOMATICALLY BE REMOVED FROM THE HOTMAIL SEGMENT) | ||
if (contacts.Any()) | ||
{ | ||
|
@@ -109,6 +119,10 @@ public async Task RunAsync(IClient client, TextWriter log, CancellationToken can | |
await client.Segments.DeleteAsync(segment.Id, false, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"Segment {segment.Id} deleted").ConfigureAwait(false); | ||
|
||
// DELETE THE OTHER SEGMENT | ||
await client.Segments.DeleteAsync(anotherSegment.Id, false, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"Segment {anotherSegment.Id} deleted").ConfigureAwait(false); | ||
|
||
// DELETE THE LIST | ||
await client.Lists.DeleteAsync(list.Id, false, cancellationToken).ConfigureAwait(false); | ||
await log.WriteLineAsync($"List {list.Id} deleted").ConfigureAwait(false); | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,9 @@ | |
|
||
namespace StrongGrid.UnitTests.Utilities | ||
{ | ||
public class QueryDslTests | ||
public class QueryDsl | ||
{ | ||
public class ToQueryDslVersion2 | ||
public class Version2Tests | ||
{ | ||
[Fact] | ||
public void One_condition_with_two_criteria() | ||
|
@@ -28,7 +28,7 @@ public void One_condition_with_two_criteria() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.first_name='John' AND contacts.last_name='Doe'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.first_name='John' AND c.last_name='Doe'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -41,7 +41,7 @@ public void All_contacts() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -60,7 +60,7 @@ public void All_contacts_with_firstname_Dave() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.first_name='Dave'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.first_name='Dave'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -79,7 +79,7 @@ public void All_contacts_in_Colorado() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.state_province_region='CO'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.state_province_region='CO'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -98,7 +98,7 @@ public void All_contacts_at_gmail() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.email LIKE '%gmail.com%'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.email LIKE '%gmail.com%'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -117,7 +117,7 @@ public void All_contacts_with_custom_text_field() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.my_text_custom_field='abc'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.my_text_custom_field='abc'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -136,7 +136,7 @@ public void All_contacts_with_custom_number_field() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.my_number_custom_field=12"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.my_number_custom_field=12"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -155,7 +155,7 @@ public void All_contacts_with_custom_date_field() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.my_date_custom_field='2021-01-01T12:46:24Z'"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.my_date_custom_field='2021-01-01T12:46:24Z'"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -174,7 +174,7 @@ public void All_contacts_where_alternate_email_contains() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE array_contains(contacts.alternate_emails,'[email protected]')"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE array_contains(c.alternate_emails,'[email protected]')"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -193,7 +193,7 @@ public void All_contacts_member_of_either_of_lists() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE array_contains(contacts.list_ids,['aaa','bbb'])"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE array_contains(c.list_ids,['aaa','bbb'])"); | ||
} | ||
|
||
[Fact] | ||
|
@@ -213,11 +213,30 @@ public void All_contacts_not_Dave_or_first_name_is_null() | |
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT contacts.contact_id, contacts.updated_at FROM contact_data AS contacts WHERE contacts.first_name!='Dave' OR contacts.first_name IS NULL"); | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.first_name!='Dave' OR c.first_name IS NULL"); | ||
} | ||
|
||
[Fact] | ||
public void All_contacts_modified_before_given_date() | ||
{ | ||
// Arrange | ||
var filter = new[] | ||
{ | ||
new KeyValuePair<SearchLogicalOperator, IEnumerable<ISearchCriteria>>(SearchLogicalOperator.And, new[] | ||
{ | ||
new SearchCriteriaLessThan(ContactsFilterField.ModifiedOn, new DateTime(2024, 6, 19, 0, 0, 0, DateTimeKind.Utc)) | ||
}) | ||
}; | ||
|
||
// Act | ||
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion2(filter); | ||
|
||
// Assert | ||
result.ShouldBe("SELECT c.contact_id, c.updated_at FROM contact_data AS c WHERE c.updated_at<'2024-06-19T00:00:00Z'"); | ||
} | ||
} | ||
|
||
public class ToQueryDslVersion1 | ||
public class Version1Tests | ||
{ | ||
[Fact] | ||
public void Filter_by_subject() | ||
|
@@ -275,6 +294,25 @@ public void Filter_by_bounced_email() | |
// Assert | ||
result.ShouldBe("status=\"bounce\""); | ||
} | ||
|
||
[Fact] | ||
public void Contacts_modified_prior_to_given_date() | ||
{ | ||
// Arrange | ||
var filter = new[] | ||
{ | ||
new KeyValuePair<SearchLogicalOperator, IEnumerable<ISearchCriteria>>(SearchLogicalOperator.And, new[] | ||
{ | ||
new SearchCriteriaLessThan(ContactsFilterField.ModifiedOn, new DateTime(2024, 6, 19, 0, 0, 0, DateTimeKind.Utc)), | ||
}) | ||
}; | ||
|
||
// Act | ||
var result = StrongGrid.Utilities.Utils.ToQueryDslVersion1(filter); | ||
|
||
// Assert | ||
result.ShouldBe("updated_at<TIMESTAMP \"2024-06-19T00:00:00Z\""); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.