Skip to content

Commit

Permalink
API-489: Update API client to 1.5
Browse files Browse the repository at this point in the history
* Rfis, attachments
  • Loading branch information
kirkplangrid committed Jan 22, 2016
1 parent bbcf831 commit 9c55759
Show file tree
Hide file tree
Showing 49 changed files with 479 additions and 53 deletions.
4 changes: 2 additions & 2 deletions PlanGrid.Api.Net45/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="AssemblyInfo.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System.Reflection;
Expand All @@ -13,7 +13,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("PlanGrid, Inc.")]
[assembly: AssemblyProduct("PlanGrid.Api")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
74 changes: 74 additions & 0 deletions PlanGrid.Api.Tests/AttachmentTests.cs
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()));
}
}
}
}
14 changes: 7 additions & 7 deletions PlanGrid.Api.Tests/IssuesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="IssuesTests.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System;
Expand All @@ -21,15 +21,15 @@ public async Task GetIssues()
Issue issue = page.Data[0];
Assert.IsFalse(issue.IsDeleted);
Assert.AreEqual(TestData.ApiTestsUserEmail, issue.AssignedTo.Single().Email);
Assert.AreEqual(DateTime.Parse("11/16/2015 10:13:49.845"), issue.CreatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:13:49"), issue.CreatedAt);
Assert.AreEqual(TestData.ApiTestsUserEmail, issue.CreatedBy.Email);
Assert.AreEqual("Test Description", issue.Description);
Assert.AreEqual(1, issue.Number);
Assert.AreEqual("Test Room", issue.Room);
Assert.AreEqual(IssueStatus.Open, issue.Status);
Assert.AreEqual(TestData.ApiTestsUserEmail, issue.UpdatedBy.Email);
Assert.IsFalse(string.IsNullOrEmpty(issue.Uid));
Assert.AreEqual(DateTime.Parse("11/16/2015 10:13:50.830"), issue.UpdatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:13:50"), issue.UpdatedAt);
Assert.IsFalse(issue.IsDeleted);
Assert.AreEqual("#FF0000", issue.CurrentAnnotation.Color);
Assert.IsFalse(issue.CurrentAnnotation.IsDeleted);
Expand All @@ -44,7 +44,7 @@ public async Task GetIssues()
Page<Photo> photos = await client.Resolve(issue.Photos);
Assert.AreEqual(1, photos.TotalCount);
Assert.AreEqual(1, issue.Photos.TotalCount);
Assert.AreEqual(DateTime.Parse("11/16/2015 10:32:43.584"), photos.Data[0].CreatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:32:43"), photos.Data[0].CreatedAt);
Assert.AreEqual(TestData.ApiTestsUserEmail, photos.Data[0].CreatedBy.Email);
Assert.AreEqual("Galaxy", photos.Data[0].Title);
Assert.AreEqual(TestData.PhotoUrl, photos.Data[0].Url);
Expand All @@ -54,7 +54,7 @@ public async Task GetIssues()
Page<Comment> comments = await client.Resolve(issue.Comments);
Assert.AreEqual(1, comments.TotalCount);
Assert.AreEqual(1, issue.Comments.TotalCount);
Assert.AreEqual(DateTime.Parse("11/16/2015 10:35:21.698"), comments.Data[0].CreatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:35:21.698"), comments.Data[0].CreatedAt);
Assert.AreEqual(TestData.ApiTestsUserEmail, comments.Data[0].CreatedBy.Email);
Assert.AreEqual("Test Comment", comments.Data[0].Text);
Assert.IsFalse(string.IsNullOrEmpty(comments.Data[0].Uid));
Expand All @@ -66,7 +66,7 @@ public async Task GetIssueComments()
IPlanGridApi client = PlanGridClient.Create();
Page<Comment> comments = await client.GetIssueComments(TestData.Project1Uid, TestData.Project1Issue1Uid);
Assert.AreEqual(1, comments.TotalCount);
Assert.AreEqual(DateTime.Parse("11/16/2015 10:35:21.698"), comments.Data[0].CreatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:35:21.698"), comments.Data[0].CreatedAt);
Assert.AreEqual(TestData.ApiTestsUserEmail, comments.Data[0].CreatedBy.Email);
Assert.AreEqual("Test Comment", comments.Data[0].Text);
Assert.IsFalse(string.IsNullOrEmpty(comments.Data[0].Uid));
Expand All @@ -78,7 +78,7 @@ public async Task GetIssuePhotos()
IPlanGridApi client = PlanGridClient.Create();
Page<Photo> photos = await client.GetIssuePhotos(TestData.Project1Uid, TestData.Project1Issue1Uid);
Assert.AreEqual(1, photos.TotalCount);
Assert.AreEqual(DateTime.Parse("11/16/2015 10:32:43.584"), photos.Data[0].CreatedAt);
Assert.AreEqual(DateTime.Parse("11/16/2015 18:32:43"), photos.Data[0].CreatedAt);
Assert.AreEqual(TestData.ApiTestsUserEmail, photos.Data[0].CreatedBy.Email);
Assert.AreEqual("Galaxy", photos.Data[0].Title);
Assert.AreEqual(TestData.PhotoUrl, photos.Data[0].Url);
Expand Down
6 changes: 5 additions & 1 deletion PlanGrid.Api.Tests/PlanGrid.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AttachmentTests.cs" />
<Compile Include="IssuesTests.cs" />
<Compile Include="ProjectsTests.cs" />
<Compile Include="RfisTests.cs" />
Expand All @@ -53,8 +54,11 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
<EmbeddedResource Include="TestData\Sample.pdf" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PlanGrid.Api.Net45\PlanGrid.Api.Net45.csproj">
Expand Down
70 changes: 65 additions & 5 deletions PlanGrid.Api.Tests/RfisTests.cs
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;

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion PlanGrid.Api.Tests/RoleTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="RoleTests.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System.Threading.Tasks;
Expand Down
4 changes: 3 additions & 1 deletion PlanGrid.Api.Tests/TestData.cs
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
Expand All @@ -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";
Expand Down
Binary file added PlanGrid.Api.Tests/TestData/Sample.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions PlanGrid.Api.Tests/UserTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="ProjectUserTests.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System.Threading.Tasks;
Expand All @@ -15,9 +15,9 @@ public async Task GetUsers()
{
IPlanGridApi api = PlanGridClient.Create();
Page<User> users = await api.GetUsers(TestData.Project1Uid);
Assert.AreEqual(2, users.Data.Length);
Assert.AreEqual(3, users.Data.Length);

User user = users.Data[1];
User user = users.Data[2];
Assert.AreEqual(TestData.ApiTestsUserEmail, user.Email);
Assert.IsTrue(!string.IsNullOrEmpty(user.Uid));

Expand Down
2 changes: 1 addition & 1 deletion PlanGrid.Api/AnnotationVisibility.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="AnnotationVisibility.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System.Runtime.Serialization;
Expand Down
2 changes: 1 addition & 1 deletion PlanGrid.Api/Attachment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="Attachment.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System;
Expand Down
10 changes: 10 additions & 0 deletions PlanGrid.Api/AttachmentReference.cs
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; }
}
}
22 changes: 22 additions & 0 deletions PlanGrid.Api/AttachmentUpload.cs
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; }
}
}
20 changes: 20 additions & 0 deletions PlanGrid.Api/AttachmentUploadRequest.cs
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; }
}
}
2 changes: 1 addition & 1 deletion PlanGrid.Api/AutoGeneratedIPlanGridApi.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// <copyright file="AutoGeneratedIPlanGridApi.cs" company="PlanGrid, Inc.">
// Copyright (c) 2015 PlanGrid, Inc. All rights reserved.
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System;
Expand Down
Loading

0 comments on commit 9c55759

Please sign in to comment.