Exemple #1
0
        public static async Task CreateApproval()
        {
            Printer.PrintStepTitle("Uploads A Dummpy PDF For Approval");

            var random   = new Random();
            var filePath = Path.Combine("dummy.pdf");

            var requestParameters = new ApprovalCreateParameters
            {
                Description = "Test Approval",
                NumberOfDecisionsRequired = random.Next(1, 10),
                OwnerUserId = TestContainer.User.Id,
            };

            Printer.Print("Creating new approval...");

            var approvalResult = await ApiClient.Approvals.Create(filePath, requestParameters);

            Printer.Print($"New approval created:{approvalResult.Id}");

            var approval = new Approval
            {
                Id = approvalResult.Id
            };

            TestContainer.SetApproval(approval);
        }
Exemple #2
0
        public static async Task PublishApprovalDraft()
        {
            Printer.PrintStepTitle("Publish Approval Draft");

            var approvalDraft = await ApiClient.Approvals.GetApprovalDraftByIdAsync(TestContainer.ApprovalDraft.Id);

            while (approvalDraft.Status != ApprovalDraftStatus.Ready)
            {
                Printer.Print("Checking Approval Draft Status...");

                approvalDraft = await ApiClient.Approvals.GetApprovalDraftByIdAsync(TestContainer.ApprovalDraft.Id);

                Printer.Print("Approval Draft: " + approvalDraft.Status);

                if (approvalDraft.Status == ApprovalDraftStatus.Processing)
                {
                    Printer.Print("Waiting 10 secs....");
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                }
            }

            TestContainer.SetApprovalDraft(approvalDraft);

            Printer.Print("Publishing Approval Draft...");

            var parameters = new ApprovalCreateParameters
            {
                Description = "approval draft testing",
                OwnerUserId = TestContainer.RandomUserId,
            };
            var result = await ApiClient.Approvals.PublishDraftAsync(TestContainer.ApprovalDraft.Id, parameters);

            Printer.Print($"Published: {result.Id}");
            TestContainer.SetApprovalDraft(null);
        }
Exemple #3
0
        internal async Task CreateApproval()
        {
            Printer.PrintStepTitle("Uploads A Dummpy PDF For Approval");
            Console.Write("Enter Description:");
            string name = Console.ReadLine();

            if (name == "-1")
            {
                return;
            }

            Console.Write("Enter Number of Decisions Required:");
            string numberOfDecisionsRequiredInput = Console.ReadLine();

            int.TryParse(numberOfDecisionsRequiredInput, out int numberOfDecisionsRequired);

            Console.Write("Enter Approval Owner User ID:");
            string ownerUserId = Console.ReadLine();

            var filePath = Path.Combine("dummy.pdf");

            var requestParameters = new ApprovalCreateParameters
            {
                Description = name,
                NumberOfDecisionsRequired = numberOfDecisionsRequired,
                OwnerUserId = ownerUserId,
            };

            Console.WriteLine("Creating new approval...");
            var approvalResult = await _apiClient.Approvals.Create(filePath, requestParameters);

            Console.WriteLine($"New approval created:{approvalResult.Id}");
        }
Exemple #4
0
        public async Task <ApprovalCreateResult> Create(string filePath, ApprovalCreateParameters parameters)
        {
            var filename    = Path.GetFileName(filePath);
            var fileContent = File.ReadAllBytes(filePath);

            return(await Create(filename, fileContent, parameters));
        }
Exemple #5
0
        /// <inheritdoc />
        public async Task <ApprovalCreateResult> PublishDraftAsync(string id, ApprovalCreateParameters parameters)
        {
            var response = await ApiClient.PostAsJsonAsync($"/drafts/{id}/publish", parameters);

            if (response.IsSuccessStatusCode)
            {
                return(await response.Content.ReadAsJsonAsync <ApprovalCreateResult>());
            }

            throw new ApiException("ApprovalDraftsPublish.Post", response.StatusCode, await response.Content.ReadAsStringAsync());
        }
Exemple #6
0
        /// <summary>
        /// Creates an approval, uploading the supplied media for the specified approval parameters
        /// </summary>
        /// <param name="filename">Filename of file on disk</param>
        /// <param name="fileContent">file content as a byte array</param>
        /// <param name="parameters">Create parameters, see <see cref="ApprovalCreateParameters"/></param>
        /// <returns></returns>
        public async Task <ApprovalCreateResult> Create(string filename, byte[] fileContent, ApprovalCreateParameters parameters)
        {
            // Basic client side validation to prevent unnesessary round trips on basic errors

            var fileExtension = Path.GetExtension(filename);

            if (string.IsNullOrWhiteSpace(fileExtension))
            {
                throw new ArgumentException("Approvals.Create: File must have an extension.");
            }

            if (fileContent.Length <= 0)
            {
                throw new ArgumentException("Approvals.Create: File length muct be greater than zero");
            }

            if (string.IsNullOrWhiteSpace(parameters.OwnerUserId))
            {
                throw new ArgumentException("Approvals.Create: Owner not specified");
            }

            if (string.IsNullOrWhiteSpace(parameters.Name))
            {
                throw new ArgumentException("Approvals.Create: Approval name not specified");
            }

            using (var content = new MultipartFormDataContent())
            {
                content.Add(new StreamContent(new MemoryStream(fileContent)), "file", WebUtility.UrlEncode(filename));

                var values = new[]
                {
                    new KeyValuePair <string, string>("name", parameters.Name),
                    new KeyValuePair <string, string>("ownerUserId", parameters.OwnerUserId),
                    new KeyValuePair <string, string>("numberOfDecisionsRequired", (parameters.NumberOfDecisionsRequired ?? 0).ToString()),
                    new KeyValuePair <string, string>("addOwnerToInitialApprovalGroup", (parameters.AddOwnerToInitialApprovalGroup ?? false).ToString()),
                    new KeyValuePair <string, string>("deadline", parameters.Deadline?.ToString("O") ?? ""),
                    new KeyValuePair <string, string>("reviewers", parameters.Reviewers.ToJson())
                };

                foreach (var keyValuePair in values)
                {
                    content.Add(new StringContent(keyValuePair.Value), $"\"{keyValuePair.Key}\"");
                }

                var response = await ApiClient.PostAsync("Approvals/Create/", content);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsJsonAsync <ApprovalCreateResult>());
                }

                throw new ApiException("Approvals.Create", response.StatusCode, await response.Content.ReadAsStringAsync());
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates an approval, uploading the supplied media for the specified approval parameters
        /// </summary>
        /// <param name="filename">Filename of file on disk</param>
        /// <param name="fileContent">file content as a byte array</param>
        /// <param name="parameters">Create parameters, see <see cref="ApprovalCreateParameters"/></param>
        /// <returns></returns>
        public async Task <ApprovalCreateResult> Create(string filename, byte[] fileContent, ApprovalCreateParameters parameters)
        {
            // Basic client side validation to prevent unnesessary round trips on basic errors

            var fileExtension = Path.GetExtension(filename);

            if (string.IsNullOrWhiteSpace(fileExtension))
            {
                throw new ArgumentException("Approvals.Create: File must have an extension.");
            }

            if (fileContent.Length <= 0)
            {
                throw new ArgumentException("Approvals.Create: File length muct be greater than zero");
            }

            if (string.IsNullOrWhiteSpace(parameters.OwnerUserId))
            {
                throw new ArgumentException("Approvals.Create: Owner not specified");
            }

            if (string.IsNullOrWhiteSpace(parameters.Description))
            {
                throw new ArgumentException("Approvals.Create: Approval name not specified");
            }

            using (var content = new MultipartFormDataContent())
            {
                var fileFormContent = new ByteArrayContent(fileContent, 0, fileContent.Length);
                fileFormContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "file", FileName = filename
                };
                fileFormContent.Headers.ContentLength = fileContent.Length;

                content.Add(fileFormContent);

                var values = new[]
                {
                    new KeyValuePair <string, string>("description", parameters.Description),
                    new KeyValuePair <string, string>("ownerUserId", parameters.OwnerUserId),
                    new KeyValuePair <string, string>("numberOfDecisionsRequired", (parameters.NumberOfDecisionsRequired ?? 0).ToString()),
                    new KeyValuePair <string, string>("deadline", parameters.Deadline?.ToString("O") ?? "")
                };

                foreach (var keyValuePair in values)
                {
                    content.Add(new StringContent(keyValuePair.Value), $"\"{keyValuePair.Key}\"");
                }


                ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data"));
                var response = await ApiClient.PostAsync("/approvals", content);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsJsonAsync <ApprovalCreateResult>());
                }

                throw new ApiException("Approvals.Create", response.StatusCode, await response.Content.ReadAsStringAsync());
            }
        }