Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeMayo committed Oct 26, 2021
2 parents c8ae5df + feec216 commit 1352a95
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ static async Task FindComplianceJobAsync(TwitterContext twitterCtx)
if (response?.Jobs?.Any() ?? false)
response.Jobs.ForEach(job =>
Console.WriteLine(
$"\nName: {job.JobName}" +
$"\nID: {job.ID}" +
$"\nName: {job.Name}" +
$"\nStatus: {job.Status}"));
else
Console.WriteLine("No entries found.");
Expand All @@ -89,28 +90,34 @@ static async Task GetMultipleComplianceJobsAsync(TwitterContext twitterCtx)
await
(from job in twitterCtx.Compliance
where job.Type == ComplianceType.MultipleJobs &&
job.StartTime == DateTime.Now.AddDays(-2) &&
job.EndTime == DateTime.Now &&
job.Status == ComplianceStatus.All
job.JobType == ComplianceJobType.Tweets //&&
//job.Status == ComplianceStatus.InProgress
select job)
.SingleOrDefaultAsync();

if (response?.Jobs?.Any() ?? false)
response.Jobs.ForEach(job =>
Console.WriteLine(
$"\nName: {job.JobName}" +
$"\nID: {job.ID}" +
$"\nName: {job.Name}" +
$"\nStatus: {job.Status}"));
else
Console.WriteLine("No entries found.");
}

static async Task CreateComplianceJobAsync(TwitterContext twitterCtx)
{
ComplianceJob? job = await twitterCtx.CreateComplianceJobAsync("test", true);
string jobName = $"test-{DateTime.Now.ToString("yyyyMMddhhmm")}";

ComplianceQuerySingle? response =
await twitterCtx.CreateComplianceJobAsync(ComplianceJobType.Tweets, jobName, true);

ComplianceJob? job = response?.Job;

if (job is not null)
Console.WriteLine(
$"\nName: {job.JobName}" +
$"\nID: {job.ID}" +
$"\nName: {job.Name}" +
$"\nStatus: {job.Status}");
else
Console.WriteLine("Job not returned");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using LinqToTwitter.Compliance;
using LinqToTwitter.OAuth;
using LinqToTwitter.Provider;
using LinqToTwitter.Tests.Common;
Expand Down Expand Up @@ -33,10 +35,11 @@ static async Task<TwitterContext> InitializeTwitterContextAsync(string result)

execMock.SetupGet(exec => exec.Authorizer).Returns(authMock.Object);
execMock.Setup(exec =>
exec.PostFormUrlEncodedToTwitterAsync<ComplianceJob>(
HttpMethod.Post.ToString(),
exec.SendJsonToTwitterAsync(
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<IDictionary<string, string>>(),
It.IsAny<ComplianceJobCreate>(),
It.IsAny<CancellationToken>()))
.Returns(tcsResponse.Task);
var ctx = new TwitterContext(execMock.Object);
Expand All @@ -46,26 +49,41 @@ static async Task<TwitterContext> InitializeTwitterContextAsync(string result)
[TestMethod]
public async Task CreateComplianceJobAsync_WithReply_ReturnsTrue()
{
const string JobType = ComplianceJobType.Tweets;
const string JobName = "abc";
const bool Resumable = true;
var ctx = await InitializeTwitterContextAsync(JobResponse);

ComplianceJob job = await ctx.CreateComplianceJobAsync(JobName, Resumable);
ComplianceQuerySingle query = await ctx.CreateComplianceJobAsync(JobType, JobName, Resumable);

Assert.IsNotNull(query);
ComplianceJob job = query.Job;
Assert.IsNotNull(job);
Assert.AreEqual("YIAh2p", job.JobID);
Assert.AreEqual("https://storage.googleapis.com/twitter-compliance/test_tweet_ids", job.DownloadUrl);
Assert.AreEqual(DateTime.Parse("2020-06-16T21:17:43.819+00:00"), job.DownloadExpiresAt);
Assert.AreEqual("https://storage.googleapis.com/twitter-compliance/customer_test_object_123456_d8ske9.json", job.UploadUrl);
Assert.AreEqual(DateTime.Parse("2020-06-16T21:17:43.818+00:00"), job.UploadExpiresAt);
Assert.AreEqual("1452446437015314435", job.ID);
Assert.AreEqual(DateTime.Parse("2021-11-01T01:26:30.000Z").ToUniversalTime(), job.DownloadExpiresAt);
Assert.AreEqual(ComplianceStatus.Created, job.Status);
Assert.AreEqual("https://storage.googleapis.com/up", job.UploadUrl);
Assert.AreEqual("https://storage.googleapis.com/down", job.DownloadUrl);
Assert.AreEqual(DateTime.Parse("2021-10-25T01:41:30.000Z").ToUniversalTime(), job.UploadExpiresAt);
Assert.AreEqual("test-202110240626", job.Name);
Assert.AreEqual(DateTime.Parse("2021-10-25T01:26:30.000Z").ToUniversalTime(), job.CreatedAt);
Assert.AreEqual(ComplianceJobType.Tweets, job.JobType);
Assert.AreEqual(true, job.Resumable);
}

const string JobResponse = @"{
""upload_url"" : ""https://storage.googleapis.com/twitter-compliance/customer_test_object_123456_d8ske9.json"",
""upload_expires_at"" : ""2020-06-16T21:17:43.818+00:00"",
""download_url"" : ""https://storage.googleapis.com/twitter-compliance/test_tweet_ids"",
""download_expires_at"" : ""2020-06-16T21:17:43.819+00:00"",
""job_id"" : ""YIAh2p""
""data"": {
""id"": ""1452446437015314435"",
""download_expires_at"": ""2021-11-01T01:26:30.000Z"",
""status"": ""created"",
""upload_url"": ""https://storage.googleapis.com/up"",
""download_url"": ""https://storage.googleapis.com/down"",
""upload_expires_at"": ""2021-10-25T01:41:30.000Z"",
""name"": ""test-202110240626"",
""created_at"": ""2021-10-25T01:26:30.000Z"",
""type"": ""tweets"",
""resumable"": true
}
}";

}
Expand Down
Loading

0 comments on commit 1352a95

Please sign in to comment.