示例#1
0
        public MpPledge GetPledgeByCampaignAndDonor(int pledgeCampaignId, int donorId)
        {
            var searchString = string.Format(",{0},{1}", pledgeCampaignId, donorId);
            var records      = _ministryPlatformService.GetPageViewRecords("PledgesByDonorId", ApiLogin(), searchString);

            switch (records.Count)
            {
            case 1:
                var record = records.First();
                var pledge = new MpPledge();
                pledge.DonorId           = record.ToInt("Donor_ID");
                pledge.PledgeCampaignId  = record.ToInt("Pledge_Campaign_ID");
                pledge.PledgeId          = record.ToInt("Pledge_ID");
                pledge.PledgeStatusId    = record.ToInt("Pledge_Status_ID");
                pledge.PledgeTotal       = record["Total_Pledge"] as decimal? ?? 0;
                pledge.CampaignStartDate = record.ToDate("Start_Date");
                pledge.CampaignEndDate   = record.ToDate("End_Date");
                return(pledge);

            case 0:
                return(null);

            default:
                throw new ApplicationException(string.Format("GetPledgeByCampaignAndDonor returned multiple records. CampaignId: {0}, DonorId: {1}", pledgeCampaignId, donorId));
            }
        }
        public void ShouldGetPledgesByCampaignAndHandleException()
        {
            const int mockCampaign = 1;
            var       mockColumns  = new List <string>
            {
                "Pledges.Pledge_ID",
                "Donor_ID_Table.Donor_ID",
                "Pledge_Campaign_ID_Table.Pledge_Campaign_ID",
                "Pledge_Campaign_ID_Table.Campaign_Name",
                "Pledge_Campaign_ID_Table_Pledge_Campaign_Type_ID_Table.Pledge_Campaign_Type_ID",
                "Pledge_Campaign_ID_Table_Pledge_Campaign_Type_ID_Table.Campaign_Type",
                "Pledge_Campaign_ID_Table.Start_Date",
                "Pledge_Campaign_ID_Table.End_Date",
                "Pledge_Status_ID_Table.Pledge_Status_ID",
                "Pledge_Status_ID_Table.Pledge_Status",
                "Pledges.Total_Pledge"
            };

            var mockPledge = new MpPledge
            {
                CampaignName      = "Kernel Panic",
                DonorId           = 1234,
                PledgeTotal       = 1000000,
                CampaignEndDate   = DateTime.Today.AddDays(30),
                CampaignStartDate = DateTime.Today,
                CampaignTypeId    = 4,
                CampaignTypeName  = "Band Tour Fund",
                PledgeCampaignId  = 567,
                PledgeDonations   = 15.00M,
                PledgeId          = 42,
                PledgeStatus      = "Active",
                PledgeStatusId    = 1
            };
            var mockPledges = new List <MpPledge> {
                mockPledge
            };

            _ministryPlatformRestRepository.Setup(mocked => mocked.UsingAuthenticationToken("ABC")).Returns(_ministryPlatformRestRepository.Object);
            _ministryPlatformRestRepository.Setup(
                mocked =>
                mocked.Search <MpPledge>(
                    "Pledge_Campaign_ID_Table.Pledge_Campaign_ID=" + mockCampaign +
                    " AND Pledge_Status_ID_Table.Pledge_Status_ID=1",
                    mockColumns, It.IsAny <string>(), It.IsAny <bool>())).Throws <Exception>();

            Assert.Throws <Exception>(() =>
            {
                List <MpPledge> records = _fixture.GetPledgesByCampaign(mockCampaign, "ABC");
                _ministryPlatformRestRepository.VerifyAll();
            });
        }
示例#3
0
        public void Search()
        {
            var mockMpSearchResponse = MockMpSearchResponse();

            _eventParticipantService.Setup(m => m.TripParticipants(It.IsAny <string>())).Returns(mockMpSearchResponse);

            var mockPledge1 = new MpPledge
            {
                PledgeId         = 1,
                DonorId          = mockMpSearchResponse[0].DonorId,
                PledgeCampaignId = mockMpSearchResponse[0].CampaignId,
                PledgeStatusId   = 1
            };
            var mockPledge2 = new MpPledge
            {
                PledgeId         = 2,
                DonorId          = mockMpSearchResponse[1].DonorId,
                PledgeCampaignId = mockMpSearchResponse[1].CampaignId,
                PledgeStatusId   = 1
            };
            var mockPledge3 = new MpPledge
            {
                PledgeId         = 3,
                DonorId          = mockMpSearchResponse[2].DonorId,
                PledgeCampaignId = mockMpSearchResponse[2].CampaignId,
                PledgeStatusId   = 1
            };

            _pledgeService.Setup(m => m.GetPledgeByCampaignAndDonor(mockMpSearchResponse[0].CampaignId, mockMpSearchResponse[0].DonorId)).Returns(mockPledge1);
            _pledgeService.Setup(m => m.GetPledgeByCampaignAndDonor(mockMpSearchResponse[1].CampaignId, mockMpSearchResponse[1].DonorId)).Returns(mockPledge2);
            _pledgeService.Setup(m => m.GetPledgeByCampaignAndDonor(mockMpSearchResponse[2].CampaignId, mockMpSearchResponse[2].DonorId)).Returns(mockPledge3);

            var searchResults = _fixture.Search(It.IsAny <string>());

            _eventParticipantService.VerifyAll();
            _pledgeService.VerifyAll();
            Assert.AreEqual(2, searchResults.Count);

            var p1 = searchResults.FirstOrDefault(s => s.ParticipantId == 9999);

            Assert.IsNotNull(p1);
            Assert.AreEqual(2, p1.Trips.Count);

            var p2 = searchResults.FirstOrDefault(s => s.ParticipantId == 5555);

            Assert.IsNotNull(p2);
            Assert.AreEqual(1, p2.Trips.Count);
        }
示例#4
0
        private static List <List <MpPledge> > ValidMpPledgeList()
        {
            var mpPledge = new MpPledge
            {
                CampaignName = "asdfasdf",
                DonorId      = 1234,
                PledgeId     = 9087
            };

            return(new List <List <MpPledge> >
            {
                new List <MpPledge>
                {
                    mpPledge
                }
            });
        }
示例#5
0
        public void testPostToCreateDonationAndDistributionWithPledgeUnauthenticated()
        {
            var contactId  = 999999;
            var donationId = 6186818;
            var charge     = new StripeCharge()
            {
                Id = "ch_crdscharge86868",
                BalanceTransaction = new StripeBalanceTransaction()
                {
                    Fee = 987
                }
            };

            var createDonationDTO = new CreateDonationDTO
            {
                ProgramId        = "3", //crossroads
                Amount           = 86868,
                DonorId          = 394256,
                EmailAddress     = "*****@*****.**",
                PledgeCampaignId = 23,
                PledgeDonorId    = 42,
                GiftMessage      = "Don't look a Gift Horse in the Mouth!",
                PaymentType      = "card",
                SourceUrl        = "www.ninjas.com",
                PredefinedAmount = 86868
            };

            var donor = new MpContactDonor
            {
                ContactId       = contactId,
                DonorId         = 424242,
                SetupDate       = new DateTime(),
                StatementFreq   = "1",
                StatementMethod = "2",
                StatementType   = "3",
                ProcessorId     = "cus_test1234567",
                Email           = "moc.tset@tset",
                Details         = new MpContactDetails
                {
                    FirstName = "Bart",
                    LastName  = "Simpson"
                }
            };

            var pledgeId = 3456;
            var pledge   = new MpPledge
            {
                DonorId          = 1,
                PledgeCampaignId = 2,
                PledgeId         = pledgeId,
                PledgeStatusId   = 1
            };


            fixture.Request.Headers.Authorization = null;
            gatewayDonorServiceMock.Setup(mocked => mocked.GetContactDonorForEmail(createDonationDTO.EmailAddress)).Returns(donor);

            mpPledgeService.Setup(mocked => mocked.GetPledgeByCampaignAndDonor(createDonationDTO.PledgeCampaignId.Value, createDonationDTO.PledgeDonorId.Value)).Returns(pledge);

            // it doesn't seem right to have donationId passed into this, but it's in the function now
            mpDonationService.Setup(mocked => mocked.SendMessageFromDonor(pledgeId, donationId, createDonationDTO.GiftMessage, "Daddy Warbucks"));

            stripeServiceMock.Setup(mocked => mocked.ChargeCustomer(donor.ProcessorId, createDonationDTO.Amount, donor.DonorId, false)).
            Returns(charge);


            donorServiceMock.Setup(mocked => mocked.
                                   CreateDonationAndDistributionRecord(It.Is <MpDonationAndDistributionRecord>(
                                                                           d => d.DonationAmt == createDonationDTO.Amount &&
                                                                           d.FeeAmt == charge.BalanceTransaction.Fee &&
                                                                           d.DonorId == donor.DonorId &&
                                                                           d.ProgramId.Equals(createDonationDTO.ProgramId) &&
                                                                           d.PledgeId == pledgeId &&
                                                                           d.ChargeId.Equals(charge.Id) &&
                                                                           d.PymtType.Equals(createDonationDTO.PaymentType) &&
                                                                           d.ProcessorId.Equals(donor.ProcessorId) &&
                                                                           !d.RegisteredDonor &&
                                                                           !d.Anonymous &&
                                                                           !d.RecurringGift &&
                                                                           d.RecurringGiftId == null &&
                                                                           d.DonorAcctId == null &&
                                                                           d.CheckScannerBatchName == null &&
                                                                           d.DonationStatus == null &&
                                                                           d.CheckNumber == null &&
                                                                           d.PredefinedAmount == createDonationDTO.PredefinedAmount &&
                                                                           d.SourceUrl == createDonationDTO.SourceUrl), true))
            .Returns(donationId);


            IHttpActionResult result = fixture.Post(createDonationDTO);


            donorServiceMock.VerifyAll();
            stripeServiceMock.VerifyAll();
            donorServiceMock.VerifyAll();
            mpPledgeService.VerifyAll();

            donorServiceMock.VerifyAll();
            stripeServiceMock.VerifyAll();
            donorServiceMock.VerifyAll();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult <DonationDTO>), result);
            var okResult = (OkNegotiatedContentResult <DonationDTO>)result;

            Assert.AreEqual(6186818, donationId);

            var resultDto = ((OkNegotiatedContentResult <DonationDTO>)result).Content;

            Assert.IsNotNull(resultDto);
            Assert.AreEqual(donor.Email, resultDto.Email);
        }
        public void ShouldGetPledgeByCampaignAndContact()
        {
            const int mockCampaign = 1;
            const int mockContact  = 10;

            var mockColumns = new List <string>
            {
                "Pledges.Pledge_ID",
                "Donor_ID_Table.Donor_ID",
                "Pledge_Campaign_ID_Table.Pledge_Campaign_ID",
                "Pledge_Campaign_ID_Table.Campaign_Name",
                "Pledge_Campaign_ID_Table_Pledge_Campaign_Type_ID_Table.Pledge_Campaign_Type_ID",
                "Pledge_Campaign_ID_Table_Pledge_Campaign_Type_ID_Table.Campaign_Type",
                "Pledge_Campaign_ID_Table.Start_Date",
                "Pledge_Campaign_ID_Table.End_Date",
                "Pledge_Status_ID_Table.Pledge_Status_ID",
                "Pledge_Status_ID_Table.Pledge_Status",
                "Pledges.Total_Pledge"
            };

            var mockPledge = new MpPledge
            {
                CampaignName      = "Kernel Panic",
                DonorId           = 1234,
                PledgeTotal       = 1000000,
                CampaignEndDate   = DateTime.Today.AddDays(30),
                CampaignStartDate = DateTime.Today,
                CampaignTypeId    = 4,
                CampaignTypeName  = "Band Tour Fund",
                PledgeCampaignId  = 567,
                PledgeDonations   = 15.00M,
                PledgeId          = 42,
                PledgeStatus      = "Active",
                PledgeStatusId    = 1
            };
            var mockPledges = new List <MpPledge> {
                mockPledge
            };

            _ministryPlatformRestRepository.Setup(mocked => mocked.UsingAuthenticationToken("ABC")).Returns(_ministryPlatformRestRepository.Object);
            _ministryPlatformRestRepository.Setup(
                mocked =>
                mocked.Search <MpPledge>(
                    "Donor_ID_Table_Contact_ID_Table.Contact_ID=" + mockContact + " AND Pledge_Campaign_ID_Table.Pledge_Campaign_ID=" + mockCampaign +
                    " AND Pledge_Status_ID_Table.Pledge_Status_ID=1",
                    mockColumns, It.IsAny <string>(), It.IsAny <bool>())).Returns(mockPledges);

            var record = _fixture.GetPledgeByCampaignAndContact(mockCampaign, mockContact);

            Assert.AreEqual(mockPledge.CampaignName, record.CampaignName);
            Assert.AreEqual(mockPledge.DonorId, record.DonorId);
            Assert.AreEqual(mockPledge.PledgeTotal, record.PledgeTotal);
            Assert.AreEqual(mockPledge.CampaignEndDate, record.CampaignEndDate);
            Assert.AreEqual(mockPledge.CampaignStartDate, record.CampaignStartDate);
            Assert.AreEqual(mockPledge.CampaignTypeId, record.CampaignTypeId);
            Assert.AreEqual(mockPledge.CampaignTypeName, record.CampaignTypeName);
            Assert.AreEqual(mockPledge.PledgeCampaignId, record.PledgeCampaignId);
            Assert.AreEqual(mockPledge.PledgeDonations, record.PledgeDonations);
            Assert.AreEqual(mockPledge.PledgeId, record.PledgeId);
            Assert.AreEqual(mockPledge.PledgeStatus, record.PledgeStatus);
            Assert.AreEqual(mockPledge.PledgeStatusId, record.PledgeStatusId);
        }