//RejectAdoProject public async Task <List <ProjectAdo> > RejectAdoProject(List <int> toReject, string rejectReason) { try { await base.AddAuthHeaderAsync(); var data = new RejectededListDto { ToReject = toReject, Reason = rejectReason }; var url = $"{ApiPart}RejectAdoProject"; var httpcontent = new StringContent(JsonSerializer.Serialize(data, _options), Encoding.UTF8, "application/json"); var apiData = await HttpClientBase.PostAsync(url, httpcontent).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options); return(ser); //var result = Mapper.Map<List<ProjectAdo>>(ser); //return result; } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <List <ProjectAdo> > GetProjectsForApproval() { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options); return(ser?.Where(a => a.State == ProjectState.CreatePending && a.Status == Common.AdoServices.Models.Status.Submitted)?.ToList()); //var result = Mapper.Map<List<ProjectAdo>>(ser); //return result; } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <bool> ProjectExists(string organization, string projectName, int projectId) { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}{organization}/{projectName}/{projectId}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.StatusCode == System.Net.HttpStatusCode.OK) { return(true); } else if (apiData.StatusCode == System.Net.HttpStatusCode.NotFound) { return(false); } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <ProjectAdo> GetItemByIdAsync(int id) { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}{id}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <ProjectAdo>(content, _options); return(ser); } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); } return(null); }
public async Task <List <ProjectAdo> > GetItemsAsync(CancellationToken cancelToken = default) { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options); return(ser); //var result = Mapper.Map<List<ProjectAdo>>(ser); //return result; } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <List <ProjectAdo> > ApproveAdoProject(List <int> toApprove) { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}ApproveAdoProject"; var httpcontent = new StringContent(JsonSerializer.Serialize(toApprove, _options), Encoding.UTF8, "application/json"); var apiData = await HttpClientBase.PostAsync(url, httpcontent).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <List <ProjectAdo> >(content, _options); return(ser); } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <ProjectAdo> UpdateItemAsync(ProjectAdo item) { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}"; //var add = Mapper.Map<ProjectAdo>(item); var httpcontent = new StringContent(JsonSerializer.Serialize(item, _options), Encoding.UTF8, "application/json"); var apiData = await HttpClientBase.PutAsync(url, httpcontent).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <ProjectAdo>(content, _options); return(ser); } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } //return false; }
public async void AgentInformationChangeUnitTest() { AgentInformationChangeArgs agentInformationChangeArgs = new AgentInformationChangeArgs() { agentInfo = new AgentInformationChange_agentinfo() { agentCode = "040999", agentRequestType = "C", agentNameChangeFlag = "N", agentAddressChangeFlag = "Y", agentAddress = "123 Main Street", agentCity = "New York", agentState = "NY", agentZipCode = "10001", agentCodeCrossReference = " ", agentName = " ", agentPhoneNumber = "", agentFaxNumber = "", agentEmailAddress = "", agentSSNFederalIdTypeFlag = "", agentSSNFederalId = "", agentMailOptionFlag = "", agentPhoneChangeFlag = "N", agentFaxChangeFlag = "N", agentEmailChangeFlag = "N", agentMailOptionChangeFlag = "N", agentSSNFederalIdChangeFlag = "N" } }; HttpClientBase <AgentInformationChange_agentinfo> httpClientBase = new HttpClientBase <AgentInformationChange_agentinfo>(); var result = await httpClientBase.AgentInformationChange(agentInformationChangeArgs); Assert.NotNull(result); }
public async void PolicyReinStatementUnitTest() { PolicyReinStatementArgs policyReinStatementArgs = new PolicyReinStatementArgs() { insuredId = "DEMOACCOUNT", aisAccountNumber = "98000001", note1 = "SAMPLE NOTE 01", note2 = "SAMPLE NOTE 02", agentCode = "040000", reinstateDate = "10012018", agentCodeCrossReference = " ", reinstateType = "P", requestedBy = "I", policies = new List <PolicyReinStatement_policy>() { new PolicyReinStatement_policy() { policyNumber = "TESTPFPOLICY0001" } } }; HttpClientBase <PolicyReinStatement_policy> httpClientBase = new HttpClientBase <PolicyReinStatement_policy>(); var result = await httpClientBase.PolicyReinStatement(policyReinStatementArgs); Assert.NotNull(result); }
public async void ReturnPreminumEndorsementUnitTest() { ReturnPreminumEndorsementArgs returnPreminumEndorsementArgs = new ReturnPreminumEndorsementArgs() { insuredId = "DEMOACCOUNT", insuredName1 = "JOHN", aisAccountNumber = "98000001", note1 = "SAMPLE NOTE 01", note2 = "SAMPLE NOTE 02" }; returnPreminumEndorsementArgs.policies = new List <ReturnPreminumEndorsement_policy>() { new ReturnPreminumEndorsement_policy() { policyNumber = "TESTPFPOLICY0001", policyReturnPremiumAmount = "1000.00" } }; HttpClientBase <ReturnPreminumEndorsement_policy> httpClientBase = new HttpClientBase <ReturnPreminumEndorsement_policy>(); var result = await httpClientBase.ReturnPreminumEndorsement(returnPreminumEndorsementArgs); Assert.NotNull(result); }
public async Task <List <IdName> > GetResourceGroupsIdName(string subscriptionId, CancellationToken cancelToken = default) { try { //1. Call azure api await base.AddAuthHeaderAsync(); //GET https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2020-06-01 var url = $"https://management.azure.com/subscriptions/{subscriptionId}/resourcegroups?api-version=2020-06-01"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <ResourceGroupsDto>(content, _options); if (ser?.Value?.Count > 0) { //"VM running" //var last = ser.Statuses.Last(); var idNameList = ser.Value.Select(a => new IdName(a.Id, a.Name)).ToList(); return(idNameList); } } } catch (Exception ex) { base.HandleException(ex); } return(null); }
public async Task <List <AdoProjectAccessModel> > GetProjectsForApproval() { try { await base.AddAuthHeaderAsync(); var url = $"{ApiPart}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); var ser = await JsonSerializer.DeserializeAsync <List <AdoProjectAccessDto> >(stream, _options); var result = Mapper.Map <List <AdoProjectAccessModel> >(ser); return(result.Where(a => a.Status == Models.Status.Submitted)?.ToList()); } else { throw new Exception(base.GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <TModel> RestGetById <TModel>(string id = null, string route = null, CancellationToken cancelToken = default) where TModel : class { try { await AddAuthHeaderAsync(); var url = string.IsNullOrWhiteSpace(route) ? $"{ApiPart}{id}" : $"{ApiPart}{route}/{id}"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); if (stream.Length == 0) { return(null); } var ser = await JsonSerializer.DeserializeAsync <TModel>(stream, _options, cancelToken); var con = await ConvertModelToLocalTimeBase(ser); return(con); } else { throw new Exception(GetErrorText(apiData)); } } catch (Exception ex) { HandleException(ex, cancelToken); return(null); } }
public async Task <List <AdoProjectHistoryModel> > GetItemsByParrentIdAsync(string parrentId) { try { await base.AddAuthHeaderAsync(); ApiPart = $"api/adoproject/{parrentId}/adoprojectHistory"; var url = $"{ApiPart}"; var apiData = await HttpClientBase.GetAsync(url).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <List <AdoProjectHistoryModel> >(content, _options); var result = Mapper.Map <List <AdoProjectHistoryModel> >(ser); return(result); } else { throw new Exception(GetErrorText(apiData)); } } catch (Exception ex) { base.HandleException(ex); throw; } }
public async Task <List <string> > GetAtCodes(CancellationToken cancelToken = default) { try { await AddAuthHeaderAsync(); var url = $"{ApiPart}GetAtCodes"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); var ser = await JsonSerializer.DeserializeAsync <List <string> >(stream, _options, cancelToken); if (ser.HasAnyInCollection()) { return(ser); } else { return(new List <string>()); } } else { throw new Exception(GetErrorText(apiData)); } } catch (Exception ex) { HandleException(ex); throw; } }
public async Task <List <Claim> > GetClaimsByUserNameAsync(string userName, ClaimsPrincipal principal, CancellationToken cancelToken = default) { try { //1. Call azure api //await base.AddAuthHeaderAsync(); var apiToken = await _tokenAcquisition.GetAccessTokenForUserAsync(new List <string> { Scope }, null, null, principal); HttpClientBase.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", apiToken); var url = $"{ApiPart}{userName}"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); var ser = await JsonSerializer.DeserializeAsync <List <UserClaimDto> >(stream, _options); if (ser.HasAnyInCollection()) { List <Claim> list = new(); ser.ForEach(a => list.Add(new Claim(a.Type, a.Value))); return(list); } } } catch (Exception ex) { base.HandleException(ex); } return(null); }
public async Task <Subscription> GetSubcription(string subscriptionId, CancellationToken cancelToken = default) { try { //1. Call azure api await base.AddAuthHeaderAsync(); //GET https://management.azure.com/subscriptions/{subscriptionId}?api-version=2020-01-01 var url = $"https://management.azure.com/subscriptions/{subscriptionId}?api-version=2020-01-01"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var content = await apiData.Content.ReadAsStringAsync(); var ser = JsonSerializer.Deserialize <SubscriptionsDto>(content, _options); if (ser?.Value?.Count > 0) { var first = ser.Value.FirstOrDefault(); var result = Mapper.Map <Subscription>(first); return(result); } } } catch (Exception ex) { base.HandleException(ex); } return(null); }
public async Task <List <Claim> > GetClaimsByUserNameAsync(string userName, CancellationToken cancelToken = default) { try { //1. Call azure api await base.AddAuthHeaderAsync(); var url = $"{ApiPart}{userName}"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); var ser = await JsonSerializer.DeserializeAsync <List <UserClaimDto> >(stream, _options); if (ser.HasAnyInCollection()) { List <Claim> list = new(); ser.ForEach(a => list.Add(new Claim(a.Type, a.Value))); return(list); } } } catch (Exception ex) { base.HandleException(ex); } return(null); }
public async void AdditionalPreminumEndorsementUnitTest() { AdditionalPreminumArgs additionalPreminumArgs = new AdditionalPreminumArgs() { insuredId = "DEMOACCOUNT", insuredName1 = "JOHN", aisAccountNumber = "98000001", note1 = "SAMPLE NOTE 01", note2 = "SAMPLE NOTE 02" }; AdditionalPreminum_policy additionalPreminum_Policy = new AdditionalPreminum_policy() { policyNumber = "TESTPFPOLICY0001", policyInceptionDate = "10012018", policyTerm = "12", policyInsuranceCompanyCrossReference = "XY", policyInsuranceCompanyNumber = "6688", policyCoverageTypeCode = "18", policyPremiumAmount = "1000.00", policyPremiumDownpay = "100.00", policyUnpaidPremiumAmount = "900.00", policyCommissionAmount = "0.00", policyCommissionPercentage = "0.000", policyCommissionRetainFlag = "N", policyFee1Type = "T", policyFee1Description = "TAXES", policyFee1Amount = "50.00", policyFee1AmountDownpay = "50.00", policyFee2Type = "F", policyFee1UnpaidAmount = "0.00", policyFee2Description = "FEES", policyFee2Amount = "100.00", policyFee2AmountDownpay = "100.00", policyFee2UnpaidAmount = "0.00", policyFee3Amount = "0.00", policyFee3AmountDownpay = "0.00", policyFee3UnpaidAmount = "0.00", policyFee4Amount = "0.00", policyFee4AmountDownpay = "0.00", policyFee4UnpaidAmount = "0.00", policyFilingFlag = "N", policyFilingDays = "0", policyInsuranceCompanyName = " ", policyInsuranceCompanyCO = " ", policyCoverageTypeCrossReference = " ", policyFee3Type = " ", policyFee3Description = " ", policyFee4Type = " ", policyFee4Description = " " }; additionalPreminumArgs.policies = new List <AdditionalPreminum_policy>() { additionalPreminum_Policy }; HttpClientBase <AdditionalPreminum_policy> httpClientBase = new HttpClientBase <AdditionalPreminum_policy>(); var result = await httpClientBase.AdditionalPreminum(additionalPreminumArgs); Assert.NotNull(result); }
public void AddCustomRequestHeaders_AddsHeaders() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); HttpRequestMessage httpRequest = new HttpRequestMessage(); httpClientBase.CustomRequestHeaders = new Dictionary <string, IEnumerable <string> > { { "x-custom-header", new List <string> { "value" } } }; httpClientBase.AddCustomRequestHeaders(httpRequest); httpRequest.Headers .Should() .NotBeEmpty(); httpRequest.Headers .First() .As <KeyValuePair <string, IEnumerable <string> > >() .Key .Should().Be("x-custom-header"); }
public void CreateHttpContent_ReturnsNullWhenContentIsNull() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = httpClientBase.CreateHttpContent(null); result.Should().BeNull(); }
public void TryDeserialize_ReturnsNullWhenReaderIsNull() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = httpClientBase.TryDeserialize <ServiceDTO>(null, true); result.Should().BeNull(); }
public void DesrializeJsonFromStream_ReturnsNullWhenStreamIsNull() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = httpClientBase.DeserializeJsonFromStream <string>(null); result.Should().BeNull(); }
public async Task StreamToStringAsync_ReturnsNullWhenStreamIsNull() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = await httpClientBase.StreamToStringAsync(null); result.Should().BeNull(); }
public void CreateHttpContent_ReturnsValueWhenContentHasValue() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = httpClientBase.CreateHttpContent("value"); result.Should().NotBeNull(); }
public async Task TryGetContentAsync_ReturnsNullWhenResponseIsNull() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); var result = await httpClientBase.TryGetContentAsync <string>(null); result.Should().BeNull(); }
public async Task <List <IdName> > GetSubcriptions(CancellationToken cancelToken = default) { List <IdName> list = new(); try { //1. Call azure api await base.AddAuthHeaderAsync(); var url = $"https://management.azure.com/subscriptions?api-version=2020-01-01"; var apiData = await HttpClientBase.GetAsync(url, cancelToken).ConfigureAwait(false); if (apiData.IsSuccessStatusCode) { var stream = await apiData.Content.ReadAsStreamAsync(); var ser = await JsonSerializer.DeserializeAsync <SubscriptionsIdNameDto>(stream, _options); if (ser?.Value?.Count > 0) { addToList(ref list, ser); while (ser.NextLink.HasValueExt()) { await stream.DisposeAsync(); apiData = null; apiData = await HttpClientBase.GetAsync(ser.NextLink, cancelToken).ConfigureAwait(false); stream = await apiData.Content.ReadAsStreamAsync(); ser = await JsonSerializer.DeserializeAsync <SubscriptionsIdNameDto>(stream, _options); if (ser?.Value?.Count > 0) { addToList(ref list, ser); } } } } } catch (Exception ex) { base.HandleException(ex); } return(list); void addToList(ref List <IdName> list, SubscriptionsIdNameDto ser) { var idNameList = ser.Value.Where(a => a.State == "Enabled").Select(a => new IdName(a.SubscriptionId.ToString(), a.DisplayName)).ToList(); if (idNameList.HasAnyInCollection()) { list.AddRange(idNameList); } } }
/// <summary> /// Static async version send event to TriggMine API /// </summary> /// <typeparam name="T">Type of event</typeparam> /// <param name="eventDto">Event data</param> /// <param name="apiKey">Client API key</param> /// <param name="apiUrl">Client Url</param> /// <returns>Task<HttpResponseMessage/></returns> public static HttpResponseMessage SendEvent <T>(T eventDto, string apiKey, Uri apiUrl) { using (var httpClient = HttpClientBase.CreateHttpClient(apiKey, apiUrl)) { var content = JsonConvert.SerializeObject(eventDto); var url = EventsRepository.GetEventUrl(typeof(T)); return(httpClient.PostAsync(url, new StringContent(content, Encoding.UTF8, "application/json")).Result); } }
public void DeserializeJsonFromStream_ReturnsValueWhenStreamHasValue() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("true"))) { var result = httpClientBase.DeserializeJsonFromStream <bool>(ms); result.Should().BeTrue(); } }
public async Task StreamToStringAsync_ReturnsValueWhenStreamHasValue() { HttpClient httpClient = new HttpClient(); HttpClientBase httpClientBase = new HttpClientBase(httpClient, loggerMock.Object); using (MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes("some value"))) { var result = await httpClientBase.StreamToStringAsync(ms); result.Should().BeEquivalentTo("some value"); } }