Exemplo n.º 1
0
        public void ThrowsSoapFaultWhenFault()
        {
            string xml = EmbeddedResource.Get <CreateReportResponseTests>("SoapFaultResponse.txt");
            CreateReportResponse sut = new CreateReportResponse();

            var soapFaultException = Assert.Throws <SoapFaultException>(() => sut.LoadFromXml(xml));

            Assert.NotNull(soapFaultException.SoapFault);
        }
Exemplo n.º 2
0
        public void ParseResponse()
        {
            string xml = EmbeddedResource.Get <CreateReportResponseTests>("CreateResponse.txt");
            CreateReportResponse sut = new CreateReportResponse();

            sut.LoadFromXml(xml);

            Assert.Equal("Control4222019144914-embcTraining-159742987459901082006", sut.Fields["reportId"]);
            Assert.Equal("Control4222019144914-embcTraining-159742987459901082006", sut.Fields["id"]);
            Assert.Equal("resource_request", sut.Fields["reportType"]);
        }
Exemplo n.º 3
0
        public async Task <CreateReportResponse> CreateReportAsync(ExpenseAuthorizationRequest expenseAuthorizationRequest)
        {
            if (expenseAuthorizationRequest == null)
            {
                throw new ArgumentNullException(nameof(expenseAuthorizationRequest));
            }

            // login and get session cookie
            await LoginAsync(_options.Value);

            CreateReportResponse ret;
            // get the defaults, we could cache this in the future
            var resourceCategories = await GetLookupAsync(LookupType.ResourceCategory);

            var statuses = await GetLookupAsync(LookupType.StatusResource);

            var priorities = await GetLookupAsync(LookupType.PriorityResource);

            string resourceCategory = resourceCategories.FirstOrDefault(_ => _.Value == DefaultResourceCategory)?.Value;
            string currentStatus    = statuses.FirstOrDefault(_ => _.Value == DefaultCurrentStatus)?.Id;
            string priority         = priorities.FirstOrDefault(_ => _.Value == DefaultPriority)?.Id;

            var items = _mapper.Map(expenseAuthorizationRequest, priority, resourceCategory, currentStatus);

            var    request     = new CreaterReportRequest(items);
            string soapRequest = request.CreateSoapRequest();

            try
            {
                CreateReportResponse response1 = new CreateReportResponse();

                var soapResponse = await _client.CreateReportAsync(soapRequest);

                response1.LoadFromXml(soapResponse);

                ret = response1;
            }
            catch (ApiException exception)
            {
                throw new SoapFaultException(exception);
            }

            CreateReportResponse response = ret;

            return(response);
        }