-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
49 changed files
with
479 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// <copyright file="AttachmentTests.cs" company="PlanGrid, Inc."> | ||
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
namespace PlanGrid.Api.Tests | ||
{ | ||
[TestFixture] | ||
public class AttachmentTests | ||
{ | ||
[Test] | ||
public async Task UploadAttachment() | ||
{ | ||
IPlanGridApi client = PlanGridClient.Create(); | ||
AttachmentUploadRequest request = await client.CreateAttachmentUploadRequest(TestData.Project2Uid, new AttachmentUpload | ||
{ | ||
ContentType = AttachmentUpload.Pdf, | ||
Name = "test name", | ||
Folder = "test folder" | ||
}); | ||
|
||
Stream payload = typeof(AttachmentTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf"); | ||
Attachment attachment = await client.Upload(request, payload); | ||
|
||
Assert.AreEqual("test name", attachment.Name); | ||
Assert.AreEqual("test folder", attachment.Folder); | ||
Assert.AreEqual(TestData.ApiTestsUserUid, attachment.CreatedBy.Uid); | ||
Assert.AreNotEqual(attachment.CreatedAt, default(DateTime)); | ||
Assert.AreEqual(request.Uid, attachment.Uid); | ||
|
||
using (var downloader = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = true })) | ||
{ | ||
Stream returnedPayload = await downloader.GetStreamAsync(attachment.Url); | ||
payload = typeof(AttachmentTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf"); | ||
var payloadBytes = new MemoryStream(); | ||
await payload.CopyToAsync(payloadBytes); | ||
var returnedBytes = new MemoryStream(); | ||
await returnedPayload.CopyToAsync(returnedBytes); | ||
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray())); | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task UploadPdfAttachment() | ||
{ | ||
IPlanGridApi client = PlanGridClient.Create(); | ||
Stream payload = typeof(AttachmentTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf"); | ||
Attachment attachment = await client.UploadPdfAttachment(TestData.Project2Uid, "test name", payload, "test folder"); | ||
|
||
Assert.AreEqual("test name", attachment.Name); | ||
Assert.AreEqual("test folder", attachment.Folder); | ||
Assert.AreEqual(TestData.ApiTestsUserUid, attachment.CreatedBy.Uid); | ||
Assert.AreNotEqual(attachment.CreatedAt, default(DateTime)); | ||
|
||
using (var downloader = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = true })) | ||
{ | ||
Stream returnedPayload = await downloader.GetStreamAsync(attachment.Url); | ||
payload = typeof(AttachmentTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf"); | ||
var payloadBytes = new MemoryStream(); | ||
await payload.CopyToAsync(payloadBytes); | ||
var returnedBytes = new MemoryStream(); | ||
await returnedPayload.CopyToAsync(returnedBytes); | ||
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray())); | ||
} | ||
} | ||
} | ||
} |
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,8 +1,10 @@ | ||
// <copyright file="RfisTests.cs" company="PlanGrid, Inc."> | ||
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved. | ||
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved. | ||
// </copyright> | ||
|
||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework; | ||
|
||
|
@@ -23,10 +25,10 @@ public async Task GetRfis() | |
Assert.AreEqual("Test Rfi Question", rfi.Question); | ||
Assert.AreEqual("Test Rfi", rfi.Title); | ||
Assert.AreEqual(1, rfi.Number); | ||
Assert.AreEqual(DateTime.Parse("11/18/2015 11:30:21.000"), rfi.SentDate); | ||
Assert.AreEqual(DateTime.Parse("11/19/2015 11:30:13.000"), rfi.DueDate); | ||
Assert.AreEqual(DateTime.Parse("11/17/2015 12:06:47.912"), rfi.UpdatedAt); | ||
Assert.AreEqual(DateTime.Parse("11/16/2015 13:48:26.641"), rfi.CreatedAt); | ||
Assert.AreEqual(DateTime.Parse("11/18/2015 19:30:21.000"), rfi.SentDate); | ||
Assert.AreEqual(DateTime.Parse("11/19/2015 19:30:13.000"), rfi.DueDate); | ||
Assert.AreEqual(DateTime.Parse("11/17/2015 20:06:47.912"), rfi.UpdatedAt); | ||
Assert.AreEqual(DateTime.Parse("11/16/2015 21:48:26.641"), rfi.CreatedAt); | ||
Assert.AreEqual("[email protected]", rfi.AssignedTo[0].Email); | ||
Assert.AreEqual("[email protected]", rfi.UpdatedBy.Email); | ||
Assert.AreEqual("[email protected]", rfi.CreatedBy.Email); | ||
|
@@ -187,5 +189,63 @@ public async Task UpdateRfi() | |
Assert.AreEqual(TestData.ApiTestsUserUid, rfi.UpdatedBy.Uid); | ||
Assert.AreNotEqual(rfi.UpdatedAt, default(DateTime)); | ||
} | ||
|
||
[Test] | ||
public async Task ReferenceAttachment() | ||
{ | ||
IPlanGridApi client = PlanGridClient.Create(); | ||
var rfiInsert = new RfiUpsert | ||
{ | ||
Question = "test question", | ||
Answer = "test answer", | ||
AssignedTo = new[] { TestData.ApiTestsUserUid }, | ||
DueDate = new DateTime(2020, 1, 1), | ||
IsLocked = false, | ||
SentDate = new DateTime(2019, 1, 1), | ||
StatusUid = TestData.Project2DraftRfiStatusUid, | ||
Title = "test title" | ||
}; | ||
Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert); | ||
|
||
AttachmentUploadRequest request = await client.CreateAttachmentUploadRequest(TestData.Project2Uid, new AttachmentUpload | ||
{ | ||
ContentType = AttachmentUpload.Pdf, | ||
Name = "test name", | ||
Folder = "test folder" | ||
}); | ||
|
||
Stream payload = typeof(AttachmentTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf"); | ||
Attachment attachment = await client.Upload(request, payload); | ||
|
||
await client.ReferenceAttachmentFromRfi(TestData.Project2Uid, rfi.Uid, new AttachmentReference { AttachmentUid = attachment.Uid }); | ||
|
||
Page<Attachment> attachments = await client.GetRfiAttachments(TestData.Project2Uid, rfi.Uid); | ||
Attachment rfiAttachment = attachments.Data.Single(); | ||
Assert.AreEqual(attachment.Uid, rfiAttachment.Uid); | ||
} | ||
|
||
[Test] | ||
public async Task ReferencePhoto() | ||
{ | ||
IPlanGridApi client = PlanGridClient.Create(); | ||
var rfiInsert = new RfiUpsert | ||
{ | ||
Question = "test question", | ||
Answer = "test answer", | ||
AssignedTo = new[] { TestData.ApiTestsUserUid }, | ||
DueDate = new DateTime(2020, 1, 1), | ||
IsLocked = false, | ||
SentDate = new DateTime(2019, 1, 1), | ||
StatusUid = TestData.Project2DraftRfiStatusUid, | ||
Title = "test title" | ||
}; | ||
Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert); | ||
|
||
await client.ReferencePhotoFromRfi(TestData.Project2Uid, rfi.Uid, new PhotoReference { PhotoUid = TestData.Project2PhotoUid }); | ||
|
||
Page<Photo> photos = await client.GetRfiPhotos(TestData.Project2Uid, rfi.Uid); | ||
Photo rfiPhoto = photos.Data.Single(); | ||
Assert.AreEqual(TestData.Project2PhotoUid, rfiPhoto.Uid); | ||
} | ||
} | ||
} |
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,6 +1,7 @@ | ||
// <copyright file="TestData.cs" company="PlanGrid, Inc."> | ||
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved. | ||
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved. | ||
// </copyright> | ||
|
||
namespace PlanGrid.Api.Tests | ||
{ | ||
public static class TestData | ||
|
@@ -11,6 +12,7 @@ public static class TestData | |
public const string Project2Uid = "269ad633-0688-395e-5c30-cc685e0ce964"; | ||
public const string Project2DraftRfiStatusUid = "00a8b880"; | ||
public const string Project2OpenRfiStatusUid = "bcadf1c9"; | ||
public const string Project2PhotoUid = "6f976878-d243-c787-dfda-0290b7761968"; | ||
public const string PhotoUrl = "https://photo-assets-test.plangrid.com/5a16f6d9-8006-ea7d-12ee-76c778b7094f.jpg"; | ||
public const string ApiTestsUserEmail = "[email protected]"; | ||
public const string ApiTestsUserUid = "5644e9acf0cb79476f1d48ee"; | ||
|
Binary file not shown.
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Newtonsoft.Json; | ||
|
||
namespace PlanGrid.Api | ||
{ | ||
public class AttachmentReference | ||
{ | ||
[JsonProperty("attachment_uid")] | ||
public string AttachmentUid { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// <copyright file="RfisTests.cs" company="PlanGrid, Inc."> | ||
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved. | ||
// </copyright> | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace PlanGrid.Api | ||
{ | ||
public class AttachmentUpload | ||
{ | ||
public const string Pdf = "application/pdf"; | ||
|
||
[JsonProperty("content_type")] | ||
public string ContentType { get; set; } | ||
|
||
[JsonProperty("name")] | ||
public string Name { get; set; } | ||
|
||
[JsonProperty("folder")] | ||
public string Folder { get; set; } | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// <copyright file="RfisTests.cs" company="PlanGrid, Inc."> | ||
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved. | ||
// </copyright> | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace PlanGrid.Api | ||
{ | ||
public class AttachmentUploadRequest | ||
{ | ||
[JsonProperty("webhook_url")] | ||
public string WebhookUrl { get; set; } | ||
|
||
[JsonProperty("uid")] | ||
public string Uid { get; set; } | ||
|
||
[JsonProperty("aws_post_form_arguments")] | ||
public AwsPostFormArguments AwsPostFormArguments { get; set; } | ||
} | ||
} |
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.