Ejemplo n.º 1
0
        public PartyRelationshipsInquiry GetDto(string personNumber)
        {
            var inquiry = new PartyRelationshipsInquiry()
            {
                PartyId = Convert.ToInt32(personNumber)
            };

            return(inquiry);
        }
Ejemplo n.º 2
0
        public void MakeInquiry_WhenAPersonDoesNotExistInCore_ShouldReturnPartyNotFound(int personNumber)
        {
            // Arrange
            var inquiry = new PartyRelationshipsInquiry();

            inquiry.PartyId = personNumber;

            var mockRepo = Substitute.For <IRestRepository>();

            var stubProxy = GetServiceProxy();

            var relationshipInfos = new List <RelationshipInfo>()
            {
                new RelationshipInfo()
                {
                    PartyId = "222"
                },
                new RelationshipInfo()
                {
                    PartyId = "333"
                }
            };

            var partyRelationshipResponse = new PartyRelationshipsInquiryResponse()
            {
                RelationshipInfos = relationshipInfos
            };

            stubProxy.MakeInquiry(inquiry).Returns(partyRelationshipResponse);

            var serviceResponse = stubProxy.MakeInquiry(inquiry);
            var relationships   = serviceResponse?.RelationshipInfos;

            // Act
            mockRepo.MakeInquiry(inquiry).Returns(relationships);
            var relationshipInfosList = mockRepo.MakeInquiry(inquiry);

            string result = string.Empty;

            foreach (var relationshipInfo in relationshipInfosList)
            {
                if (relationshipInfo.PartyId.Equals(inquiry.PartyId.ToString(), StringComparison.InvariantCulture))
                {
                    result = "Found";
                    break;
                }
                else
                {
                    result = "Party not found";
                }
            }

            // Assert
            Assert.AreEqual("Party not found", result);
        }
Ejemplo n.º 3
0
        public void MakeInquiry_WhenCalled_ShouldCallProxyMakeInquiry()
        {
            // Arrange
            var mockProxy   = GetServiceProxy();
            var credentials = new Credentials();
            var repo        = new RestRepository(_userToken, credentials, mockProxy);
            var inquiry     = new PartyRelationshipsInquiry();

            // Act
            var dontCare = repo.MakeInquiry(inquiry);

            // Assert
            mockProxy.Received().MakeInquiry(Arg.Any <PartyRelationshipsInquiry>());
        }
Ejemplo n.º 4
0
        public IList <RelationshipInfo> MakeInquiry(PartyRelationshipsInquiry inquiry)
        {
            IList <RelationshipInfo> relationshipInfos = null;

            using (var tr = new Tracer("LMS.Connector.CCM.Repositories.RestRepository.MakeInquiry"))
            {
                tr.Log("Calling IServiceProxy.MakeInquiry");
                var inquiryResponse = _proxy.MakeInquiry(inquiry);
                tr.LogObject(inquiryResponse);

                relationshipInfos = inquiryResponse?.RelationshipInfos;
                tr.LogObject(relationshipInfos);
            }

            return(relationshipInfos);
        }
Ejemplo n.º 5
0
        public PartyRelationshipsInquiryResponse MakeInquiry(PartyRelationshipsInquiry inquiry)
        {
            using (var tr = new Tracer("LMS.Connector.CCM.Proxies.RestProxy.MakeInquiry"))
            {
                var authToken = GetAuthorization();
                tr.Log($"MakeInquiry(PartyRelationshipsInquiry) authToken = {authToken}");

                _api.Value.Headers = new Dictionary <string, string>();
                _api.Value.Headers.Add("Authorization", authToken);
                _api.Value.URL = $"{BaseUrlApi}/parties/{inquiry.PartyId}/relationships";
                tr.Log($"URL: {_api.Value.URL}");

                int headerIndex = 0;
                tr.Log("api.Value.Headers:");
                foreach (var header in _api.Value.Headers)
                {
                    tr.Log($"Header[{headerIndex}] Key = {header.Key}, Value = {header.Value}");
                    headerIndex++;
                }

                PartyRelationshipsInquiryResponse inquiryResponse = null;

                try
                {
                    inquiryResponse = _api.Value.Get <PartyRelationshipsInquiryResponse>();
                    tr.LogObject(inquiryResponse);
                }
                catch (Exception ex)
                {
                    tr.LogException(ex);
                    Utility.LogError(ex, "LMS.Connector.CCM.Proxies.RestProxy.MakeInquiry");
                    throw;
                }

                return(inquiryResponse);
            }
        }
Ejemplo n.º 6
0
        public BaseResult Inquiry(string personNumber)
        {
            var result = new BaseResult();

            _errorMessage = "Relationship not found";

            using (var tr = new Tracer("LMS.Connector.CCM.Behaviors.Rest.InquiryBehavior.Inquiry"))
            {
                tr.Log($"Inquiry personNumber = {personNumber}");

                tr.Log($"PartyRelationshipsInquiry _inquiry null? => {_inquiry == null}");
                if (_inquiry == null)
                {
                    tr.Log("Call GetDto() to get new _inquiry");
                    _inquiry = GetDto(personNumber);
                }
                tr.LogObject(_inquiry);

                try
                {
                    tr.Log("Calling IRestRepository.MakeInquiry");
                    _relationshipInfos = _restRepository.MakeInquiry(_inquiry);
                    tr.LogObject(_relationshipInfos);
                }
                catch (Exception ex)
                {
                    tr.LogException(ex);
                    result.Result      = false;
                    result.ExceptionId = Utility.LogError(ex, "LMS.Connector.CCM.Behaviors.Rest.InquiryBehavior.Inquiry");
                    result.AddMessage(MessageType.Error, $"Exception when attempting to call REST Repository MakeInquiry(): {ex.Message}");
                }
                finally
                {
                    // Deallocate DTO
                    _inquiry = null;
                }

                if (_relationshipInfos?.Count > 0)
                {
                    int i = 0;
                    tr.Log($"Iterating through _relationshipInfos to determine if party has an account in CCM (i.e. relationshipInfo[i].AccountNumber == _app.CreditCardNumber <{_app.CreditCardNumber}>)");
                    foreach (var relationshipInfo in _relationshipInfos)
                    {
                        tr.Log($"_relationshipInfos[{i}].AccountNumber = {relationshipInfo.AccountNumber}");
                        if (relationshipInfo.AccountNumber == _app.CreditCardNumber)
                        {
                            _errorMessage = "Found";
                            tr.Log($"Found in _relationshipInfos[{i}]");

                            break;
                        }

                        i++;
                    }
                }

                tr.Log($"Inquiry error message: {_errorMessage}");
            }

            return(result);
        }
Ejemplo n.º 7
0
        public void Inquiry_WhenAPerson_HasAnAccountNumberInCCM_ThatMatchesTheApplicationCreditCardNumber_Then_ShouldReturnFound
            (int existingPersonNumber, int existingAccountNumber)
        {
            // ARRANGE
            var stubProxy = Substitute.For <IServiceProxy>();

            stubProxy.GetAuthToken(Arg.Any <Session>()).Returns("71a4899f66ee2c2e30883e1c835eb5cf");
            stubProxy.GetAuthorization().Returns("AuthToken 71a4899f66ee2c2e30883e1c835eb5cf");

            var header = new Header()
            {
                ContentType   = "application/json",
                Authorization = stubProxy.GetAuthorization()
            };

            var partyRelationshipsInquiry = new PartyRelationshipsInquiry()
            {
                ApiVersion = "v1",
                PartyId    = existingPersonNumber
            };

            var request = new Request <PartyRelationshipsInquiry>()
            {
                Body = partyRelationshipsInquiry
            };

            var stubApi     = Substitute.For <IAPI>();
            var stubLazyApi = new Lazy <IAPI>(() => stubApi);
            var credentials = new Credentials()
            {
                BaseUrl  = "https://some.bank.or.cu/api",
                Username = "******",
                Password = "******",
                Facility = "validFacility"
            };

            stubLazyApi.Value.URL = $"{credentials.BaseUrl}/{_apiVersion}/parties/{existingPersonNumber}/relationships";

            var relationshipInfos = new List <RelationshipInfo>()
            {
                new RelationshipInfo()
                {
                    PartyId = "8675309", AccountNumber = "11111111"
                },
                new RelationshipInfo()
                {
                    PartyId = existingPersonNumber.ToString(), AccountNumber = existingAccountNumber.ToString()
                }
            };

            var partyRelationshipInquiryResponse = new PartyRelationshipsInquiryResponse()
            {
                RelationshipInfos = relationshipInfos
            };

            stubLazyApi.Value.Get <PartyRelationshipsInquiryResponse>().Returns(partyRelationshipInquiryResponse);
            var lazyApiValue = stubLazyApi.Value.Get <PartyRelationshipsInquiryResponse>();

            stubProxy.MakeInquiry(partyRelationshipsInquiry).Returns(lazyApiValue);
            var proxyMakeInquiry = stubProxy.MakeInquiry(partyRelationshipsInquiry);

            var stubRepo = Substitute.For <IRestRepository>();

            stubRepo.Proxy = stubProxy;
            stubRepo.Proxy.MakeInquiry(partyRelationshipsInquiry).Returns(proxyMakeInquiry);

            var makeInquiryResult = stubRepo.Proxy.MakeInquiry(partyRelationshipsInquiry);
            var relationships     = makeInquiryResult?.RelationshipInfos;

            stubRepo.MakeInquiry(partyRelationshipsInquiry).Returns(relationships);

            var mockBehavior = new InquiryBehavior(_app, _userToken, stubRepo);

            mockBehavior.PartyRelationshipInquiry = partyRelationshipsInquiry;

            // ACT
            var result       = mockBehavior.Inquiry(existingAccountNumber.ToString());
            var errorMessage = mockBehavior.ErrorMessage;

            // ASSERT
            Assert.IsNotEmpty(errorMessage);
            Assert.AreEqual("Found", errorMessage);
        }