Skip to content

Commit

Permalink
API Updates as of 7/27/2015 (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkplangrid authored Jul 28, 2016
1 parent 9c55759 commit 3a31178
Show file tree
Hide file tree
Showing 44 changed files with 849 additions and 57 deletions.
1 change: 0 additions & 1 deletion PlanGrid.Api.Tests/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="PlanGridApiBaseUrl" value="https://plangrid-c-api-dispatcher-test.herokuapp.com" />
</appSettings>
</configuration>
21 changes: 19 additions & 2 deletions PlanGrid.Api.Tests/AttachmentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ public class AttachmentTests
public async Task UploadAttachment()
{
IPlanGridApi client = PlanGridClient.Create();
AttachmentUploadRequest request = await client.CreateAttachmentUploadRequest(TestData.Project2Uid, new AttachmentUpload
FileUpload 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);
Attachment attachment = await client.Upload<Attachment>(request, payload);

Assert.AreEqual("test name", attachment.Name);
Assert.AreEqual("test folder", attachment.Folder);
Expand All @@ -45,6 +45,12 @@ public async Task UploadAttachment()
await returnedPayload.CopyToAsync(returnedBytes);
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray()));
}

Attachment retrievedAttachment = await client.GetAttachment(TestData.Project2Uid, attachment.Uid);
Assert.IsFalse(retrievedAttachment.IsDeleted);
await client.RemoveAttachment(TestData.Project2Uid, attachment.Uid);
Attachment removedAttachment = await client.GetAttachment(TestData.Project2Uid, attachment.Uid);
Assert.IsTrue(removedAttachment.IsDeleted);
}

[Test]
Expand All @@ -69,6 +75,17 @@ public async Task UploadPdfAttachment()
await returnedPayload.CopyToAsync(returnedBytes);
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray()));
}

Attachment retrievedAttachment = await client.GetAttachment(TestData.Project2Uid, attachment.Uid);
Assert.IsFalse(retrievedAttachment.IsDeleted);
await client.UpdateAttachment(TestData.Project2Uid, attachment.Uid, new AttachmentUpdate { Name = "new name", Folder = "new folder" });
retrievedAttachment = await client.GetAttachment(TestData.Project2Uid, attachment.Uid);
Assert.AreEqual("new name", retrievedAttachment.Name);
Assert.AreEqual("new folder", retrievedAttachment.Folder);

await client.RemoveAttachment(TestData.Project2Uid, attachment.Uid);
Attachment removedAttachment = await client.GetAttachment(TestData.Project2Uid, attachment.Uid);
Assert.IsTrue(removedAttachment.IsDeleted);
}
}
}
14 changes: 8 additions & 6 deletions PlanGrid.Api.Tests/IssuesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ public async Task GetIssues()
Assert.AreEqual("AC", issue.CurrentAnnotation.Stamp);
Assert.IsFalse(string.IsNullOrEmpty(issue.CurrentAnnotation.Uid));
Assert.AreEqual(AnnotationVisibility.Master, issue.CurrentAnnotation.Visibility);
Assert.AreEqual("AR.1", issue.CurrentAnnotation.Sheet.Name);
Assert.IsFalse(issue.CurrentAnnotation.Sheet.IsDeleted);
Assert.IsFalse(string.IsNullOrEmpty(issue.CurrentAnnotation.Sheet.Uid));
Assert.AreEqual("Initial Set", issue.CurrentAnnotation.Sheet.VersionName);

Sheet sheet = await client.Resolve(issue.CurrentAnnotation.Sheet);
Assert.AreEqual("AR.1", sheet.Name);
Assert.IsFalse(sheet.IsDeleted);
Assert.IsFalse(string.IsNullOrEmpty(sheet.Uid));
Assert.AreEqual("Initial Set", sheet.VersionName);

Page<Photo> photos = await client.Resolve(issue.Photos);
Assert.AreEqual(1, photos.TotalCount);
Assert.AreEqual(1, issue.Photos.TotalCount);
Assert.AreEqual(1, issue.Photos.TotalCount);
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);
Expand Down Expand Up @@ -83,7 +85,7 @@ public async Task GetIssuePhotos()
Assert.AreEqual("Galaxy", photos.Data[0].Title);
Assert.AreEqual(TestData.PhotoUrl, photos.Data[0].Url);
Assert.IsFalse(string.IsNullOrEmpty(photos.Data[0].Uid));
Assert.IsFalse(photos.Data[0].IsDeleted);
Assert.IsFalse(photos.Data[0].IsDeleted);
}
}
}
80 changes: 80 additions & 0 deletions PlanGrid.Api.Tests/PhotoTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// <copyright file="PhotoTests.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
{
public class PhotoTests
{
[Test]
public async Task UploadPngPhoto()
{
IPlanGridApi client = PlanGridClient.Create();
Stream payload = typeof(PhotoTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.png");
Photo photo = await client.UploadPngPhoto(TestData.Project2Uid, "test name", payload);

Assert.AreEqual("test name", photo.Title);
Assert.AreEqual(TestData.ApiTestsUserUid, photo.CreatedBy.Uid);
Assert.AreNotEqual(photo.CreatedAt, default(DateTime));

using (var downloader = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = true }))
{
Stream returnedPayload = await downloader.GetStreamAsync(photo.Url);
payload = typeof(PhotoTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.png");
var payloadBytes = new MemoryStream();
await payload.CopyToAsync(payloadBytes);
var returnedBytes = new MemoryStream();
await returnedPayload.CopyToAsync(returnedBytes);
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray()));
}

Photo retrievedPhoto = await client.GetPhotoInProject(TestData.Project2Uid, photo.Uid);
Assert.IsFalse(retrievedPhoto.IsDeleted);
await client.RemovePhoto(TestData.Project2Uid, photo.Uid);
Photo removedPhoto = await client.GetPhotoInProject(TestData.Project2Uid, photo.Uid);
Assert.IsTrue(removedPhoto.IsDeleted);
}

[Test]
public async Task UploadJpegPhoto()
{
IPlanGridApi client = PlanGridClient.Create();
Stream payload = typeof(PhotoTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.jpg");
Photo photo = await client.UploadPngPhoto(TestData.Project2Uid, "test name", payload);

Assert.AreEqual("test name", photo.Title);
Assert.AreEqual(TestData.ApiTestsUserUid, photo.CreatedBy.Uid);
Assert.AreNotEqual(photo.CreatedAt, default(DateTime));

using (var downloader = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip, AllowAutoRedirect = true }))
{
Stream returnedPayload = await downloader.GetStreamAsync(photo.Url);
payload = typeof(PhotoTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.jpg");
var payloadBytes = new MemoryStream();
await payload.CopyToAsync(payloadBytes);
var returnedBytes = new MemoryStream();
await returnedPayload.CopyToAsync(returnedBytes);
Assert.IsTrue(payloadBytes.ToArray().SequenceEqual(returnedBytes.ToArray()));
}

Photo retrievedPhoto = await client.GetPhotoInProject(TestData.Project2Uid, photo.Uid);
Assert.AreEqual("test name", retrievedPhoto.Title);
await client.UpdatePhoto(TestData.Project2Uid, photo.Uid, new PhotoUpdate { Title = "new title" });
retrievedPhoto = await client.GetPhotoInProject(TestData.Project2Uid, photo.Uid);
Assert.AreEqual("new title", retrievedPhoto.Title);

Assert.IsFalse(retrievedPhoto.IsDeleted);
await client.RemovePhoto(TestData.Project2Uid, photo.Uid);
Photo removedPhoto = await client.GetPhotoInProject(TestData.Project2Uid, photo.Uid);
Assert.IsTrue(removedPhoto.IsDeleted);
}
}
}
11 changes: 11 additions & 0 deletions PlanGrid.Api.Tests/PlanGrid.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Private>True</Private>
Expand All @@ -46,9 +50,12 @@
<ItemGroup>
<Compile Include="AttachmentTests.cs" />
<Compile Include="IssuesTests.cs" />
<Compile Include="PhotoTests.cs" />
<Compile Include="ProjectsTests.cs" />
<Compile Include="RfisTests.cs" />
<Compile Include="RoleTests.cs" />
<Compile Include="SheetPacketTests.cs" />
<Compile Include="SheetTests.cs" />
<Compile Include="TestData.cs" />
<Compile Include="UserTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -66,6 +73,10 @@
<Name>PlanGrid.Api.Net45</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="TestData\Sample.jpg" />
<EmbeddedResource Include="TestData\Sample.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
14 changes: 10 additions & 4 deletions PlanGrid.Api.Tests/RfisTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public async Task GetRfis()
Assert.AreEqual(1, rfis.TotalCount);

Rfi rfi = rfis.Data[0];

Page<RfiChange> history = await client.GetRfiHistory(TestData.Project1Uid, rfi.Uid);
Assert.AreEqual("locked", history.Data[0].Field);
Assert.AreEqual(true, (bool)history.Data[0].NewValue);
Assert.AreEqual(false, (bool)history.Data[0].OldValue);

Assert.AreEqual("Test Rfi Answer", rfi.Answer);
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 19:30:21.000"), rfi.SentDate);
Assert.AreEqual(DateTime.Parse("11/19/2015 19:30:13.000"), rfi.DueDate);
Assert.AreEqual(Date.Parse("2015-11-18"), rfi.SentDate);
Assert.AreEqual(Date.Parse("2015-11-19"), 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);
Expand Down Expand Up @@ -207,15 +213,15 @@ public async Task ReferenceAttachment()
};
Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert);

AttachmentUploadRequest request = await client.CreateAttachmentUploadRequest(TestData.Project2Uid, new AttachmentUpload
FileUpload 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);
Attachment attachment = await client.Upload<Attachment>(request, payload);

await client.ReferenceAttachmentFromRfi(TestData.Project2Uid, rfi.Uid, new AttachmentReference { AttachmentUid = attachment.Uid });

Expand Down
49 changes: 49 additions & 0 deletions PlanGrid.Api.Tests/SheetPacketTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// <copyright file="SheetPacketTests.cs" company="PlanGrid, Inc.">
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using NUnit.Framework;

namespace PlanGrid.Api.Tests
{
[TestFixture]
public class SheetPacketTests
{
[Test]
public async Task CreateSheetPacket()
{
IPlanGridApi client = PlanGridClient.Create();
Page<Sheet> sheets = await client.GetSheets(TestData.Project2Uid);
ShareableObject packetRequest = await client.CreateSheetPacket(TestData.Project2Uid, new SheetPacketRequest
{
SheetUids = new[] { sheets.Data[0].Uid }
});

for (int i = 0;; i++)
{
ShareableObject obj = await client.GetSheetPacket(TestData.Project2Uid, packetRequest.Uid);
if (obj.Status == Status.Incomplete)
{
if (i == 10)
{
Assert.Fail("Timed out after 10 seconds trying to get the packet.");
}
else
{
await Task.Delay(1000);
}
}
else
{
var get = new HttpClient();
HttpResponseMessage response = await get.GetAsync(obj.FileUrl);
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
break;
}
}
}
}
}
46 changes: 46 additions & 0 deletions PlanGrid.Api.Tests/SheetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <copyright file="SheetTests.cs" company="PlanGrid, Inc.">
// Copyright (c) 2016 PlanGrid, Inc. All rights reserved.
// </copyright>

using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;

namespace PlanGrid.Api.Tests
{
[TestFixture]
public class SheetTests
{
[Test]
public async Task GetSheetsObeysSkip()
{
IPlanGridApi client = PlanGridClient.Create();

Page<Sheet> sheets = await client.GetSheets(TestData.Project1Uid);
Assert.AreEqual("IS.1", sheets.Data[0].Name);
Assert.AreEqual("PA8.21", sheets.Data[1].Name);
sheets = await client.GetSheets(TestData.Project1Uid, 1);
Assert.AreEqual("PA8.21", sheets.Data[0].Name);
}

[Test]
public async Task GetSheetsObeysUpdatedAfter()
{
IPlanGridApi client = PlanGridClient.Create();

Page<Sheet> sheets = await client.GetSheets(TestData.Project1Uid, updated_after: new DateTime(2015, 12, 11, 19, 38, 16, DateTimeKind.Utc));
Assert.IsTrue(sheets.Data.Any());
sheets = await client.GetSheets(TestData.Project1Uid, updated_after: new DateTime(2016, 12, 11, 19, 39, 16, DateTimeKind.Utc));
Assert.IsFalse(sheets.Data.Any());
}

[Test]
public async Task UploadNewVersion()
{
IPlanGridApi client = PlanGridClient.Create();

await client.UploadVersion(TestData.Project2Uid, $"Version.{Guid.NewGuid()}", new VirtualFile { FileName = "Sample.pdf", Data = typeof(SheetTests).Assembly.GetManifestResourceStream("PlanGrid.Api.Tests.TestData.Sample.pdf") });
}
}
}
Binary file added PlanGrid.Api.Tests/TestData/Sample.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PlanGrid.Api.Tests/TestData/Sample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions PlanGrid.Api.Tests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ public async Task InviteAndRemoveUser()
Assert.IsFalse(invitedUser.IsRemoved);
Assert.AreEqual(TestData.AdminRoleId, invitedUser.Role.Uid);

User removedUser = await api.RemoveUser(TestData.Project1Uid, invitedUser.Uid);
Assert.IsTrue(removedUser.IsRemoved);
Assert.AreEqual(invitedUser.Uid, removedUser.Uid);
await api.RemoveUser(TestData.Project1Uid, invitedUser.Uid);
User user = await api.GetUser(TestData.Project1Uid, invitedUser.Uid);
Assert.IsTrue(user.IsRemoved);
}
}
}
1 change: 1 addition & 0 deletions PlanGrid.Api.Tests/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net45" />
<package id="NUnit" version="2.6.4" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion PlanGrid.Api.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForOtherTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForSimpleTypes/@EntryValue">UseVarWhenEvident</s:String>
<s:String x:Key="/Default/CodeStyle/FileHeader/FileHeaderText/@EntryValue">&lt;copyright file="$FILENAME$" company="PlanGrid, Inc."&gt;&#xD;
Copyright (c) 2015 PlanGrid, Inc. All rights reserved.&#xD;
Copyright (c) 2016 PlanGrid, Inc. All rights reserved.&#xD;
&lt;/copyright&gt;&#xD;
</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
Expand Down
13 changes: 13 additions & 0 deletions PlanGrid.Api/AttachmentUpdate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Newtonsoft.Json;

namespace PlanGrid.Api
{
public class AttachmentUpdate
{
[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("folder")]
public string Folder { get; set; }
}
}
Loading

0 comments on commit 3a31178

Please sign in to comment.