Exemple #1
0
        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);
        }
        public async Task GetRfi()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Rfi          rfi    = await client.GetRfi(TestData.Project1Uid, TestData.Project1Rfi1Uid);

            await ValidateRfi(rfi, client);
        }
        public async Task GetIssue()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Issue        issue  = await client.GetIssue(TestData.Project1Uid, "45460feb-2c09-663f-352f-d053444b138a");

            await ValidateIssue(issue, client);
        }
        public static async Task <T> Upload <T>(this IPlanGridApi api, FileUpload fileUpload, Stream payload, CancellationToken cancellationToken = default(CancellationToken))
        {
            var values = new List <IMultipartContent>();

            foreach (AwsPostFormArgument item in fileUpload.AwsPostFormArguments.Fields)
            {
                values.Add(new StringMultipartContent(item.Name, item.Value));
            }

            var           generatedApi = (AutoGeneratedIPlanGridApi)api;
            RefitSettings settings     = generatedApi.Settings;

            values.Add(new StreamMultipartContent("file", "data", fileUpload.AwsPostFormArguments.Fields.Single(x => x.Name == "Content-Type").Value, payload));
            HttpResponseMessage response = await MultipartUploader.Upload(fileUpload.AwsPostFormArguments.Action, cancellationToken, values.ToArray());

            if (typeof(T) != typeof(object))
            {
                string responseText = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <T>(responseText, settings.JsonSerializerSettings));
            }
            else
            {
                return(default(T));
            }
        }
        public async Task GetProject()
        {
            IPlanGridApi client  = PlanGridClient.Create();
            Project      project = await client.GetProject(TestData.Project1Uid);

            Assert.AreEqual("Project 1", project.Name);
        }
Exemple #6
0
        public async Task GetComments()
        {
            IPlanGridApi   client   = PlanGridClient.Create();
            Page <Comment> comments = await client.GetComments(TestData.Project1Uid);

            Assert.AreEqual(2, comments.TotalCount);
        }
        public async Task HitRateLimit()
        {
            IPlanGridApi client = PlanGridClient.Create(TestData.RateLimitedPlanGridApiKey);

            try
            {
                await client.GetProjects();
            }
            catch
            {
                // The rate limit for this user is 1 per day.  So the first one might succeed, or it might not.
            }

            try
            {
                await client.GetProjects();

                Assert.Fail("Should have exceeded the rate limit");
            }
            catch (RateLimitExceededException ex)
            {
                Assert.AreEqual(1, ex.RateLimit.Limit);
                Assert.AreEqual(0, ex.RateLimit.Remaining);
                Assert.AreEqual(RequestType.All, ex.RateLimit.RequestType);
                Assert.AreNotEqual(DateTime.MinValue, ex.RateLimit.Reset);
                Assert.AreEqual(86400, ex.RateLimit.Interval);  // 1 day
            }
        }
Exemple #8
0
        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;
                }
            }
        }
        public async Task GetProjectsTotalCount()
        {
            IPlanGridApi   client = PlanGridClient.Create();
            Page <Project> page   = await client.GetProjects();

            Assert.AreEqual(3, page.TotalCount);
        }
        public async Task ReferencePhoto()
        {
            IPlanGridApi client    = PlanGridClient.Create();
            var          rfiInsert = new RfiUpsert
            {
                Question   = "test question",
                Answer     = "test answer",
                AssignedTo = new[] { TestData.ApiTestsUserUid },
                DueAt      = new DateTime(2020, 1, 1),
                IsLocked   = false,
                SentAt     = 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);

            await client.RemovePhotoFromRfi(TestData.Project2Uid, rfi.Uid, rfiPhoto.Uid);

            photos = await client.GetRfiPhotos(TestData.Project2Uid, rfi.Uid);

            Assert.AreEqual(0, photos.Data.Length);
        }
        public async Task GetIssueList()
        {
            IPlanGridApi client    = PlanGridClient.Create();
            IssueList    issueList = await client.GetIssueList(TestData.Project1Uid, "SomeUid");

            await ValidateIssueList(issueList, client);
        }
        public async Task GetProjectsLimit()
        {
            IPlanGridApi   client = PlanGridClient.Create();
            Page <Project> page   = await client.GetProjects(limit : 1);

            Assert.AreEqual(1, page.Data.Length);
        }
        public async Task CreateRfi()
        {
            IPlanGridApi client    = PlanGridClient.Create();
            var          rfiInsert = new RfiUpsert
            {
                Question   = "test question",
                Answer     = "test answer",
                AssignedTo = new[] { TestData.ApiTestsUserUid },
                DueAt      = new DateTime(2020, 1, 1),
                IsLocked   = true,
                SentAt     = new DateTime(2019, 1, 1),
                StatusUid  = TestData.Project2DraftRfiStatusUid,
                Title      = "test title"
            };
            Rfi rfi = await client.CreateRfi(TestData.Project2Uid, rfiInsert);

            Assert.AreEqual(rfiInsert.Question, rfi.Question);
            Assert.AreEqual(rfiInsert.Answer, rfi.Answer);
            Assert.AreEqual(rfiInsert.AssignedTo[0], rfi.AssignedTo[0].Uid);
            Assert.AreEqual(rfiInsert.DueAt, rfi.DueAt);
            Assert.AreEqual(rfiInsert.IsLocked, rfi.IsLocked);
            Assert.AreEqual(rfiInsert.SentAt, rfi.SentAt);
            Assert.AreEqual(rfiInsert.StatusUid, rfi.Status.Uid);
            Assert.AreEqual(rfiInsert.Title, rfi.Title);
            Assert.AreEqual(TestData.ApiTestsUserUid, rfi.CreatedBy.Uid);
            Assert.AreNotEqual(rfi.CreatedAt, default(DateTime));
            Assert.AreEqual(TestData.ApiTestsUserUid, rfi.UpdatedBy.Uid);
            Assert.AreNotEqual(rfi.UpdatedAt, default(DateTime));
        }
Exemple #14
0
        public async Task GetUserProfile()
        {
            IPlanGridApi api  = PlanGridClient.Create();
            User         user = await api.GetUserProfile();

            Assert.AreEqual(TestData.ApiTestsUserEmail, user.Email);
            Assert.IsTrue(!string.IsNullOrEmpty(user.Uid));
        }
Exemple #15
0
        public async Task GetAttachments()
        {
            IPlanGridApi      client      = PlanGridClient.Create();
            Page <Attachment> attachments = await client.GetAttachments(TestData.Project1Uid);

            Assert.AreEqual(1, attachments.Data.Count(x => !x.IsDeleted));
            Assert.AreEqual("0f1358c4-3cb4-4f68-ab46-2bebfc788ae9", attachments.Data[0].Uid);
        }
        public async Task GetRfiAttachments()
        {
            IPlanGridApi      client      = PlanGridClient.Create();
            Page <Attachment> attachments = await client.GetRfiAttachments(TestData.Project1Uid, TestData.Project1Rfi1Uid);

            Assert.AreEqual(1, attachments.TotalCount);
            Assert.AreEqual("PA1.11.pdf", attachments.Data[0].Name);
        }
        public async Task GetRfiPhotos()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Page <Photo> photos = await client.GetRfiPhotos(TestData.Project1Uid, TestData.Project1Rfi1Uid);

            Assert.AreEqual(1, photos.TotalCount);
            Assert.AreEqual(TestData.PhotoUrl, photos.Data[0].Url);
        }
        public async Task GetRfiComments()
        {
            IPlanGridApi   client   = PlanGridClient.Create();
            Page <Comment> comments = await client.GetRfiComments(TestData.Project1Uid, TestData.Project1Rfi1Uid);

            Assert.AreEqual(1, comments.TotalCount);
            Assert.AreEqual("Test Rfi Comment", comments.Data[0].Text);
        }
Exemple #19
0
        public async Task GetAttachments()
        {
            IPlanGridApi      client      = PlanGridClient.Create();
            Page <Attachment> attachments = await client.GetAttachments(TestData.Project1Uid);

            Assert.AreEqual(1, attachments.Data.Count(x => !x.IsDeleted));
            Assert.AreEqual("49ffb02f-a28d-970e-e8bc-9256a4fbae1c", attachments.Data[0].Uid);
        }
        public async Task GetSnapshots()
        {
            IPlanGridApi    client    = PlanGridClient.Create();
            Page <Snapshot> snapshots = await client.GetSnapshots(TestData.Project1Uid);

            Assert.AreEqual(1, snapshots.Data.Length);
            Assert.AreEqual("AR.1", snapshots.Data[0].Title);
        }
Exemple #21
0
        public async Task GetSheet()
        {
            IPlanGridApi client = PlanGridClient.Create();

            Sheet sheet = await client.GetSheet(TestData.Project1Uid, "8e860282-2e05-4011-a538-d0a850857903");

            Assert.AreEqual("IS.1", sheet.Name);
        }
        public async Task GetRfiStatuses()
        {
            IPlanGridApi     client   = PlanGridClient.Create();
            Page <RfiStatus> statuses = await client.GetRfiStatuses(TestData.Project1Uid);

            Assert.AreEqual(6, statuses.TotalCount);
            Assert.AreEqual("draft", statuses.Data[0].Label);
            Assert.AreEqual("#34b27d", statuses.Data[0].Color);
        }
        public async Task GetRole()
        {
            IPlanGridApi api   = PlanGridClient.Create();
            var          roles = await api.GetRoles(TestData.Project1Uid);

            Role role = await api.GetRole(TestData.Project1Uid, TestData.AdminRoleId);

            Assert.AreEqual("Admin", role.Label);
        }
        public async Task GetSheetsByVersionSet()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Page <Sheet> sheets = await client.GetSheets(TestData.Project1Uid, version_set : TestData.Project1VersionSet1Uid);

            Assert.Less(0, sheets.Data.Length);
            Page <Sheet> sheets_empty = await client.GetSheets(TestData.Project1Uid, version_set : TestData.NotFoundUid);

            Assert.AreEqual(0, sheets_empty.Data.Length);
        }
        public async Task GetIssueLists()
        {
            IPlanGridApi     client = PlanGridClient.Create();
            Page <IssueList> page   = await client.GetIssueLists(TestData.Project1Uid);

            Assert.AreEqual(1, page.TotalCount);
            IssueList issueList = page.Data[0];

            await ValidateIssueList(issueList, client);
        }
        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 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));
        }
        public async Task GetProjectsOffset()
        {
            IPlanGridApi   client = PlanGridClient.Create();
            Page <Project> page   = await client.GetProjects();

            string secondProjectUid = page.Data[1].Uid;

            page = await client.GetProjects(1);

            Assert.AreEqual(secondProjectUid, page.Data.First().Uid);
        }
        public async Task GetRfis()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Page <Rfi>   rfis   = await client.GetRfis(TestData.Project1Uid);

            Assert.AreEqual(1, rfis.TotalCount);

            Rfi rfi = rfis.Data[0];

            await ValidateRfi(rfi, client);
        }
Exemple #29
0
        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());
        }
        public async Task GetSnapshot()
        {
            IPlanGridApi client   = PlanGridClient.Create();
            Snapshot     snapshot = await client.GetSnapshot(TestData.Project1Uid, TestData.SnapshotUid);

            Assert.AreEqual("AR.1", snapshot.Title);

            Sheet sheet = await client.Resolve(snapshot.Sheet);

            Assert.AreEqual("AR.1", sheet.Name);
        }
        private static async Task ValidateIssue(Issue issue, IPlanGridApi client)
        {
            Assert.IsFalse(issue.IsDeleted);
            Assert.AreEqual(TestData.ApiTestsUserEmail, issue.AssignedTo.Single().Email);
            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 18:13:50"), issue.UpdatedAt);
            Assert.IsFalse(issue.IsDeleted);
            Assert.AreEqual("#FF0000", issue.CurrentAnnotation.Color);
            Assert.IsFalse(issue.CurrentAnnotation.IsDeleted);
            Assert.AreEqual("AC", issue.CurrentAnnotation.Stamp);
            Assert.IsFalse(string.IsNullOrEmpty(issue.CurrentAnnotation.Uid));
            Assert.AreEqual(AnnotationVisibility.Master, issue.CurrentAnnotation.Visibility);

            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(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);
            Assert.IsFalse(string.IsNullOrEmpty(photos.Data[0].Uid));
            Assert.IsFalse(photos.Data[0].IsDeleted);

            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 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));
        }
        private async Task ValidateRfi(Rfi rfi, IPlanGridApi client)
        {
            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(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("*****@*****.**", rfi.AssignedTo[0].Email);
            Assert.AreEqual("*****@*****.**", rfi.UpdatedBy.Email);
            Assert.AreEqual("*****@*****.**", rfi.CreatedBy.Email);
            Assert.IsFalse(string.IsNullOrEmpty(rfi.Uid));
            Assert.IsTrue(rfi.IsLocked);

            Page<Photo> photos = await client.Resolve(rfi.Photos);
            Assert.AreEqual(1, rfi.Photos.TotalCount);
            Assert.AreEqual(1, photos.TotalCount);
            Assert.AreEqual(TestData.PhotoUrl, photos.Data[0].Url);

            Page<Snapshot> snapshots = await client.Resolve(rfi.Snapshots);
            Assert.AreEqual(1, rfi.Snapshots.TotalCount);
            Assert.AreEqual(1, snapshots.TotalCount);
            Assert.AreEqual("AR.1", snapshots.Data[0].Title);

            Page<Attachment> attachments = await client.Resolve(rfi.Attachments);
            Assert.AreEqual(1, rfi.Attachments.TotalCount);
            Assert.AreEqual(1, attachments.TotalCount);
            Assert.AreEqual("PA1.11.pdf", attachments.Data[0].Name);

            Page<Comment> comments = await client.Resolve(rfi.Comments);
            Assert.AreEqual(1, rfi.Comments.TotalCount);
            Assert.AreEqual(1, comments.TotalCount);
            Assert.AreEqual("Test Rfi Comment", comments.Data[0].Text);
        }