Пример #1
0
        public async Task ReferenceAttachment()
        {
            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);

            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 <Attachment>(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);

            await client.RemoveAttachmentFromRfi(TestData.Project2Uid, rfi.Uid, rfiAttachment.Uid);

            attachments = await client.GetRfiAttachments(TestData.Project2Uid, rfi.Uid);

            Assert.AreEqual(0, attachments.Data.Length);
        }