示例#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);
        }
示例#2
0
        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);
        }
示例#3
0
        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 async Task GetProject()
        {
            IPlanGridApi client  = PlanGridClient.Create();
            Project      project = await client.GetProject(TestData.Project1Uid);

            Assert.AreEqual("Project 1", project.Name);
        }
示例#5
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 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
            }
        }
示例#7
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 GetProjectsTotalCount()
        {
            IPlanGridApi   client = PlanGridClient.Create();
            Page <Project> page   = await client.GetProjects();

            Assert.AreEqual(3, page.TotalCount);
        }
示例#9
0
        public async Task GetIssueList()
        {
            IPlanGridApi client    = PlanGridClient.Create();
            IssueList    issueList = await client.GetIssueList(TestData.Project1Uid, "SomeUid");

            await ValidateIssueList(issueList, client);
        }
示例#10
0
        public async Task GetRfi()
        {
            IPlanGridApi client = PlanGridClient.Create();
            Rfi          rfi    = await client.GetRfi(TestData.Project1Uid, TestData.Project1Rfi1Uid);

            await ValidateRfi(rfi, client);
        }
示例#11
0
        public async Task GetProjectsLimit()
        {
            IPlanGridApi   client = PlanGridClient.Create();
            Page <Project> page   = await client.GetProjects(limit : 1);

            Assert.AreEqual(1, page.Data.Length);
        }
示例#12
0
        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));
        }
示例#13
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));
        }
示例#14
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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
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);
        }
示例#19
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);
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        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);
        }
示例#23
0
        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);
        }
示例#24
0
        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);
        }
示例#25
0
        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);
        }
示例#26
0
        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);
        }
示例#27
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());
        }
示例#28
0
        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);
        }
示例#29
0
        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));
        }
示例#30
0
        public async Task GetUser()
        {
            IPlanGridApi api  = PlanGridClient.Create();
            User         user = await api.GetUser(TestData.Project1Uid, TestData.ApiTestsUserUid);

            Assert.AreEqual(TestData.ApiTestsUserEmail, user.Email);
            Assert.IsTrue(!string.IsNullOrEmpty(user.Uid));

            Role role = await api.Resolve(user.Role);

            Assert.AreEqual("Admin", role.Label);
        }