public ClickWrap GetClickWrap(string accountId)
        {
            if (accountId == null)
            {
                throw new ArgumentNullException(nameof(accountId));
            }

            var request = new RestRequest($"/accounts/{accountId}/clickwraps?name={_clickWrapName}", DataFormat.Json);

            IRestResponse response = _docuSignApiProvider.DocuSignClickApiRestClient.Get(request);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                switch (response.StatusCode)
                {
                case HttpStatusCode.Unauthorized:
                    throw new AuthenticationException(
                              "DucuSign Click API responded with status code Unauthorized");

                default:
                    throw new InvalidOperationException(
                              $"DucuSign Click API responded with status code {response.StatusCode}");
                }
            }

            var       clickwrapsResponse = JsonConvert.DeserializeObject <ClickWrapsResponse>(response.Content);
            ClickWrap clickWrap          = clickwrapsResponse.Clickwraps.FirstOrDefault(x => x.ClickwrapName == _clickWrapName);

            if (clickWrap == null)
            {
                throw new ClickWrapNotFoundException(_clickWrapName);
            }

            return(clickWrap);
        }
        public void Index_WhenGetClickWrap_ReturnsCorrectResult(
            Account account,
            User user)
        {
            // Arrange
            InitContext(account, user);
            var clickWrap = new ClickWrap
            {
                ClickwrapId   = "1",
                ClickwrapName = "Covid19Waiver"
            };

            _clickWrapService
            .Setup(c => c.GetClickWrap(It.IsAny <string>()))
            .Returns(() => clickWrap);

            // Act
            IActionResult result = _sut.Index();

            // Assert
            result.Should().BeEquivalentTo(new OkObjectResult
                                               (new ResponseClickWrapModel
            {
                AccountId       = account.Id,
                ClickWrap       = clickWrap,
                DocuSignBaseUrl = account.BaseUri
            }));
        }
        public IActionResult Index()
        {
            ClickWrap clickWrap = _clickWrapService.GetClickWrap(Context.Account.Id);

            return(Ok(
                       new ResponseClickWrapModel
            {
                ClickWrap = clickWrap,
                DocuSignBaseUrl = Context.Account.BaseUri,
                AccountId = Context.Account.Id,
            }));
        }
示例#4
0
        public void GetClickWrap_WhenClickWrapExists_ReturnsCorrectResponse()
        {
            //Arrange
            _restClient
            .Setup(x => x.Execute(It.IsAny <IRestRequest>(), Method.GET))
            .Returns(new RestResponse
            {
                Content =
                    "{\"clickwraps\":[{\"clickwrapId\":\"1\",\"clickwrapName\":\"TermsAndConditions\",\"status\":\"active\"}]}",
                StatusCode = HttpStatusCode.OK
            });

            //Act
            ClickWrap response = _sut.GetClickWrap(AccountId);

            //Assert
            response.Should().BeEquivalentTo(
                new ClickWrap
            {
                ClickwrapId   = "1",
                ClickwrapName = "TermsAndConditions",
                Status        = "active"
            });
        }