Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
        }