public void OrgNoIsValid(string orgNo) { // Arrange PartyLookup target = new PartyLookup { OrgNo = orgNo }; // Act IList <ValidationResult> issues = ModelValidator.ValidateModel(target); // Assert Assert.Empty(issues); }
public async Task <ActionResult <Party> > PostPartyLookup([FromBody] PartyLookup partyLookup) { string lookupValue = partyLookup.OrgNo ?? partyLookup.Ssn; Party party = await _partiesWrapper.LookupPartyBySSNOrOrgNo(lookupValue); if (party == null) { return(NotFound()); } return(Ok(party)); }
public void SsnIsValid(string ssn) { // Arrange PartyLookup target = new PartyLookup { Ssn = ssn }; // Act IList <ValidationResult> issues = ModelValidator.ValidateModel(target); // Assert Assert.Empty(issues); }
public void OrgNoInvalid(string orgNo) { // Arrange PartyLookup target = new PartyLookup { OrgNo = orgNo }; // Act IList <ValidationResult> issues = ModelValidator.ValidateModel(target); // Assert Assert.True(issues.All(i => i.MemberNames.Contains("OrgNo") && i.ErrorMessage.Contains("exactly 9 digits"))); }
public void SsnInvalid(string ssn) { // Arrange PartyLookup target = new PartyLookup { Ssn = ssn }; // Act IList <ValidationResult> issues = ModelValidator.ValidateModel(target); // Assert Assert.True(issues.All(i => i.MemberNames.Contains("Ssn") && i.ErrorMessage.Contains("exactly 11 digits"))); }
public void TwoPropertiesSet_ReturnsIssue() { // Arrange PartyLookup target = new PartyLookup { Ssn = "09054300139", OrgNo = "910072218" }; // Act IList <ValidationResult> issues = ModelValidator.ValidateModel(target); // Assert Assert.True(issues.All(i => i.MemberNames.Contains("OrgNo") && i.ErrorMessage.Contains("With Ssn already"))); }
public async Task PostPartyLookup_InputIsOrgNo_BackendServiceRespondsWithParty_ControllerRespondsWithOkAndParty() { string token = PrincipalUtil.GetToken(1); // Arrange string OrgNo = "555000103"; Party party = new Party { OrgNumber = OrgNo }; Mock <IParties> partiesService = new Mock <IParties>(); partiesService.Setup(s => s.LookupPartyBySSNOrOrgNo(It.Is <string>(p => p == OrgNo))).ReturnsAsync(party); HttpClient client = GetTestClient(partiesService.Object); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); PartyLookup lookUp = new PartyLookup { OrgNo = OrgNo }; StringContent requestBody = new StringContent(JsonSerializer.Serialize(lookUp), Encoding.UTF8, "application/json"); HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/register/api/v1/parties/lookup"); httpRequestMessage.Content = requestBody; httpRequestMessage.Headers.Add("PlatformAccessToken", PrincipalUtil.GetAccessToken("ttd", "unittest")); // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); // HttpResponseMessage response = await client.PostAsync("/register/api/v1/parties/lookup", requestBody); // Assert partiesService.VerifyAll(); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Party actual = await JsonSerializer.DeserializeAsync <Party>(await response.Content.ReadAsStreamAsync()); Assert.NotNull(actual); }
public Task <Party> LookupParty(PartyLookup partyLookup) { if (!string.IsNullOrEmpty(partyLookup.Ssn)) { // TODO: fetch from disk Party party = new Party { PartyId = 1000, Name = "Test Lookup", SSN = partyLookup.Ssn, PartyTypeName = PartyType.Person, }; return(Task.FromResult(party)); } return(Task.FromResult(new Party())); }
public async Task PostPartyLookup_ModelIsInvalid_ReturnsBadRequest() { string token = PrincipalUtil.GetToken(1); // Arrange Mock <IParties> partiesService = new Mock <IParties>(); HttpClient client = GetTestClient(partiesService.Object); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); PartyLookup lookUp = new PartyLookup(); StringContent requestBody = new StringContent(JsonSerializer.Serialize(lookUp), Encoding.UTF8, "application/json"); // Act HttpResponseMessage response = await client.PostAsync("/register/api/v1/parties/lookup", requestBody); // Assert Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); }
/// <inheritdoc/> public async Task <Party> LookupParty(PartyLookup partyLookup) { Party party; string endpointUrl = "parties/lookup"; string token = JwtTokenUtil.GetTokenFromContext(_httpContextAccessor.HttpContext, _settings.RuntimeCookieName); StringContent content = new StringContent(JsonConvert.SerializeObject(partyLookup)); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); HttpRequestMessage request = new HttpRequestMessage { RequestUri = new System.Uri(endpointUrl, System.UriKind.Relative), Method = HttpMethod.Post, Content = content, }; request.Headers.Add("Authorization", "Bearer " + token); request.Headers.Add("PlatformAccessToken", _accessTokenGenerator.GenerateAccessToken(_appResources.GetApplication().Org, _appResources.GetApplication().Id)); HttpResponseMessage response = await _client.SendAsync(request); if (response.StatusCode == HttpStatusCode.OK) { party = await response.Content.ReadAsAsync <Party>(); } else { string reason = await response.Content.ReadAsStringAsync(); _logger.LogError($"// Getting party with orgNo: {partyLookup.OrgNo} or ssn: {partyLookup.Ssn} failed with statuscode {response.StatusCode} - {reason}"); throw await PlatformHttpException.CreateAsync(response); } return(party); }
public async Task PostPartyLookup_InputIsSsn_BackendServiceRespondsWithNull_ControllerRespondsWithNotFound() { string token = PrincipalUtil.GetToken(1); // Arrange string ssn = "27108775284"; Mock <IParties> partiesService = new Mock <IParties>(); partiesService.Setup(s => s.LookupPartyBySSNOrOrgNo(It.Is <string>(p => p == ssn))).ReturnsAsync((Party)null); HttpClient client = GetTestClient(partiesService.Object); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); PartyLookup lookUp = new PartyLookup { Ssn = ssn }; StringContent requestBody = new StringContent(JsonSerializer.Serialize(lookUp), Encoding.UTF8, "application/json"); HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "/register/api/v1/parties/lookup") { Content = requestBody }; httpRequestMessage.Headers.Add("PlatformAccessToken", PrincipalUtil.GetAccessToken("ttd", "unittest")); // Act HttpResponseMessage response = await client.SendAsync(httpRequestMessage); // Assert partiesService.VerifyAll(); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public static string GetNameFromDuns(string duns) { PartyLookup p = new PartyLookup(duns, PartyLookupField.DUNS); return(p.Name); }
public static string GetNameFromDuns(string duns) { PartyLookup p = new PartyLookup(duns, PartyLookupField.DUNS); return p.Name; }