public void BpSearch_ExistingBP_Returns200Ok()
        {
            // Arrange
            var controller = GetController();
            var request    = new BpSearchRequest()
            {
                FirstName = "Feng",
                LastName  = "Chan"
            };
            var responseForExistingBp = new BpSearchModel()
            {
                MatchFound          = true,
                BpId                = 1234567,
                Reason              = "Valid match.",
                ReasonCode          = "match",
                BpSearchIdentifiers = new List <IdentifierModel>()
                {
                    new IdentifierModel()
                    {
                        IdentifierType  = IdentifierType.ZDOB,
                        IdentifierValue = "01/01/1975"
                    }
                }
            };

            MoveInLogicMock.Setup(m => m.GetDuplicateBusinessPartnerIfExists(It.IsAny <BpSearchRequest>()))
            .ReturnsAsync(responseForExistingBp);

            // Act
            var response = controller.BpSearch(request).Result;

            // Assert
            response.ShouldBeOfType <OkObjectResult>();
        }
Example #2
0
        private BpSearchRequest MapToBpSearchrequest(CreateBusinesspartnerRequest authorizedContactRequest)
        {
            var bpSearch = new BpSearchRequest()
            {
                Email      = authorizedContactRequest.Email,
                FirstName  = authorizedContactRequest.FirstName,
                MiddleName = authorizedContactRequest.MiddleName,
                LastName   = authorizedContactRequest.LastName,
                ServiceZip = authorizedContactRequest.Address.PostalCode,
                Phone      = authorizedContactRequest.Phone?.Number
            };

            return(bpSearch);
        }
        public void BpSearch_MissingParams_ReturnsBadRequest()
        {
            // Arrange
            var controller = GetController();
            var request    = new BpSearchRequest()
            {
                FirstName = "Feng",
            };

            // Act
            var response = controller.BpSearch(request).Result;

            // Assert
            response.ShouldBeOfType <BadRequestObjectResult>();
        }
Example #4
0
        /// <inheritdoc />
        public async Task <BpSearchModel> GetDuplicateBusinessPartnerIfExists(BpSearchRequest request)
        {
            try
            {
                _logger.LogInformation($"GetDuplicateBusinessPartnerIfExists({nameof(request)}: {request})");
                var mcfResponse = await _mcfClient.GetDuplicateBusinessPartnerIfExists(request);

                // if these Threshhold and Unique conditions are met
                // we can return the response and bpid
                //      unique = 1 (good bp to use)
                //      threshold = x(true..has been met)
                if (mcfResponse != null)
                {
                    var response = new BpSearchModel();

                    if (mcfResponse.Threshhold != null &&
                        mcfResponse.Threshhold.ToUpper().Contains("X") &&
                        mcfResponse.Unique != null &&
                        Convert.ToInt32(mcfResponse.Unique) == 1)
                    {
                        response.MatchFound          = true;
                        response.BpId                = Convert.ToInt64(mcfResponse.BpId);
                        response.BpSearchIdentifiers = mcfResponse.BpSearchIdInfoSet.Results?.ToList();
                        response.Reason              = mcfResponse.Reason;
                        response.ReasonCode          = mcfResponse.ReasonCode;
                    }
                    else
                    {
                        response.MatchFound = false;
                        var resultCount = mcfResponse.BpSearchIdInfoSet != null?mcfResponse.BpSearchIdInfoSet.Results.ToList().Count : 0;

                        response.Reason     = string.IsNullOrEmpty(mcfResponse.Reason) ? $"{resultCount} search results found as partial match." : mcfResponse.Reason;
                        response.ReasonCode = string.IsNullOrEmpty(mcfResponse.ReasonCode) ? $"Threshhold not met." : mcfResponse.ReasonCode;
                    }

                    return(response);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                this._logger.LogError(e, "Failed to search for Business Partner.");
                throw e;
            }
        }
Example #5
0
        public async Task <IActionResult> BpSearch([FromQuery] BpSearchRequest request)
        {
            _logger.LogInformation($"BpSearch({nameof(request)}: {request.ToJson()})");

            try
            {
                // null check
                if (request == null)
                {
                    throw new ArgumentNullException($"The request was empty.");
                }

                // confirm that something valid has been included in the request
                if ((request.FirstName == null || request.LastName == null) &&
                    (request.OrgName == null))
                {
                    return(BadRequest("The request must contain first and last name, or must contain organization name."));
                }

                // send call to logic class
                var searchResponse = await _moveInLogic.GetDuplicateBusinessPartnerIfExists(request);

                // view result from logic class
                if (!searchResponse.MatchFound)
                {
                    _logger.LogInformation($"There is not a match for an existing Business Partner based on the information provided.");
                }

                return(Ok(searchResponse));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Unable to search BP for a customer.", ex.Message);
                return(ex.ToActionResult());
            }
        }