Пример #1
0
        public void TestGetDonations()
        {
            var donations = new List <DonationDTO>
            {
                new DonationDTO
                {
                    BatchId      = 123,
                    Amount       = 78900,
                    DonationDate = DateTime.Now,
                    Id           = "456",
                    Source       = new DonationSourceDTO
                    {
                        SourceType         = PaymentType.CreditCard,
                        CardType           = CreditCardType.AmericanExpress,
                        AccountHolderName  = "ending in 1234",
                        PaymentProcessorId = "tx_123",
                    },
                    Email     = "*****@*****.**",
                    ProgramId = "3",
                    Status    = DonationStatus.Succeeded
                }
            };
            var dto = new DonationsDTO();

            dto.Donations.AddRange(donations);

            gatewayDonationServiceMock.Setup(mocked => mocked.GetDonationsForAuthenticatedUser(authType + " " + authToken, "1999", null, true, true)).Returns(dto);
            var response = fixture.GetDonations("1999", null, true);

            gatewayDonationServiceMock.VerifyAll();

            Assert.IsNotNull(response);
            Assert.IsInstanceOf <OkNegotiatedContentResult <DonationsDTO> >(response);
            var r = (OkNegotiatedContentResult <DonationsDTO>)response;

            Assert.IsNotNull(r.Content);
            Assert.AreSame(dto, r.Content);
        }
        public void GetDonations_ShouldReturnPaginatedListOfDonationPrograms()
        {
            //expected
            var expected = new List <DonationProgram>()
            {
                new DonationProgram {
                    DonationProgramId   = 1,
                    DonationProgramName = "One",
                    Description         = "Maxim one",
                    ImageRef            = "An image ref",
                    StartDate           = DateTime.Now,
                    EndDate             = DateTime.Now,
                    Total = 111
                },
                new DonationProgram
                {
                    DonationProgramId   = 2,
                    DonationProgramName = "Two",
                    Description         = "Maxim two",
                    ImageRef            = "An image refs",
                    StartDate           = DateTime.Now,
                    EndDate             = DateTime.Now,
                    Total = 112
                }
            };

            //mock repo with pagination
            var pageParameters = new PageResourseParameters();
            var mockRepo       = new Mock <IRotaractRepository>();

            var mockList = new PagedList <DonationProgram>(expected, 2, 1, 1);

            mockRepo.Setup(d => d.GetDonationPrograms(pageParameters)).Returns(mockList);

            //Arrange
            DonationController donationController = new DonationController(mockRepo.Object)
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            //Act
            var result = donationController.GetDonations(pageParameters);

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(HttpResponseMessage));
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.IsTrue(result.Headers.Contains("x-pagination"));
        }