Exemplo n.º 1
0
        public void SetUp()
        {
            donorServiceMock           = new Mock <MinistryPlatform.Translation.Repositories.Interfaces.IDonorRepository>();
            invoiceServiceMock         = new Mock <MinistryPlatform.Translation.Repositories.Interfaces.IInvoiceRepository>();
            gatewayDonorServiceMock    = new Mock <IDonorService>();
            stripeServiceMock          = new Mock <IPaymentProcessorService>();
            authenticationServiceMock  = new Mock <IAuthenticationRepository>();
            contactRepositoryMock      = new Mock <IContactRepository>();
            gatewayDonationServiceMock = new Mock <IDonationService>();
            mpPledgeService            = new Mock <IPledgeRepository>();
            impersonationService       = new Mock <IUserImpersonationService>();
            paymentServiceMock         = new Mock <IPaymentService>();
            mpDonationService          = new Mock <MinistryPlatform.Translation.Repositories.Interfaces.IDonationRepository>();
            analyticsService           = new Mock <IAnalyticsService>();

            fixture = new DonationController(donorServiceMock.Object, stripeServiceMock.Object
                                             , authenticationServiceMock.Object, contactRepositoryMock.Object, gatewayDonorServiceMock.Object, gatewayDonationServiceMock.Object
                                             , mpDonationService.Object, mpPledgeService.Object, impersonationService.Object, paymentServiceMock.Object, invoiceServiceMock.Object, analyticsService.Object);

            authType        = "auth_type";
            authToken       = "auth_token";
            fixture.Request = new HttpRequestMessage();
            fixture.Request.Headers.Authorization = new AuthenticationHeaderValue(authType, authToken);
            fixture.RequestContext = new HttpRequestContext();
        }
Exemplo n.º 2
0
        public void Index_Action_Returns_View()
        {
            var controller = new DonationController(donationsService, campaignService);
            var result     = controller.Index();

            result.AssertViewRendered();
        }
    public async Task SetUp()
    {
        eventController = EventControllerTest.GetEventController();
        testEvent       = (await eventController.Add(new DtoEvent
        {
            Date = new DateTime(1775, 7, 2),
            Description = "Independence",
            Location = "Philly",
            Title = "Sign Here"
        })).Value;

        unassignedDonation = new DtoDonation
        {
            EventID = testEvent.ID,
            Amount  = 1_000M,
            Date    = new DateTime(1775, 7, 4)
        };

        donationController = GetDonationController();
        dtoDonation        = (await donationController.Add(unassignedDonation)).Value;

        var personController = PersonControllerTest.GetPersonController();

        team1Owner = (await personController.Add(new DtoPerson {
            Name = "Team 1 Owner"
        })).Value;
        team2Owner = (await personController.Add(new DtoPerson {
            Name = "Team 2 Owner"
        })).Value;

        var teamController = TeamControllerTest.GetTeamController();

        team1 = (await teamController.Add(new DtoTeam {
            Description = "Team1", EventID = testEvent.ID, Name = "Team1", OwnerID = team1Owner.ID
        })).Value;
        team2 = (await teamController.Add(new DtoTeam {
            Description = "Team2", EventID = testEvent.ID, Name = "Team2", OwnerID = team2Owner.ID
        })).Value;


        team1Donations = new[]
        {
            createDonation(testEvent.ID, team1.ID, 100),
            createDonation(testEvent.ID, team1.ID, 200)
        };

        team2Donations = new[]
        {
            createDonation(testEvent.ID, team2.ID, 300),
            createDonation(testEvent.ID, team2.ID, 400)
        };

        foreach (var donation in team1Donations.Union(team2Donations))
        {
            await donationController.Add(donation);
        }
    }
Exemplo n.º 4
0
        public void QuickDonate_Action_Returns_View_With_A_QuickDonateViewModel()
        {
            const int id = 1;

            var controller = new DonationController(donationsService, campaignService);
            var result     = controller.QuickDonate(id);

            result.AssertViewRendered().WithViewData <QuickDonateViewModel>();
        }
Exemplo n.º 5
0
        public void LatestDonations_Action_Returns_View_With_A_List_Donations()
        {
            donationsService.GetLatestDonations(5).Received().Returns(new List <Donation>());

            var controller = new DonationController(donationsService, campaignService);
            var result     = controller.LatestDonations();

            result.AssertViewRendered().WithViewData <IEnumerable <Donation> >();
        }
        public void PostDonation(Donation donation)
        {
            this._tracer.Trace("Method: Service.PostDonation");

            try
            {
                this.LogDonationInfo(donation);

                if (this.IsValidInput(donation))
                {
                    var sdk = ConnectionController.ConnectToCrm(this._tracer);
                    if (sdk != null)
                    {
                        DonationController dc = new DonationController(sdk, this._tracer);
                        dc.ProcessDonation(donation);
                        this._tracer.Trace("Donation processed");
                    }
                    else
                    {
                        string message = "Unable to connect to CRM. Check web.config";
                        this._tracer.Trace(message);
                        throw new Exception(message);
                    }
                }
                else
                {
                    throw new Exception("Invalid input. The Donor and Pledge cannot be null for a Donation");
                }
            }
            catch (FaultException <OrganizationServiceFault> fe)
            {
                if (fe.Detail != null)
                {
                    this._tracer.Trace(fe.Detail.ToString());
                }

                this._tracer.Trace(fe.ToString());

                string reference = donation != null ? donation.DpsTransactionReference : "Donation is Null";
                throw new WebFaultException <Error>(ConvertToError(fe, reference), HttpStatusCode.InternalServerError);
            }
            catch (Exception ex)
            {
                this._tracer.Trace(ex.ToString());

                string reference = donation != null ? donation.DpsTransactionReference : "Donation is Null";
                throw new WebFaultException <Error>(ConvertToError(ex, reference), HttpStatusCode.InternalServerError);
            }
            finally
            {
                // write to the log file
                this._tracer.WriteToLog(this._logPath);
            }
        }
Exemplo n.º 7
0
        private DonationController CreateSut()
        {
            var sut = new DonationController(_mediatorMock.Object, _loggerMock.Object)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext()
                }
            };

            return(sut);
        }
Exemplo n.º 8
0
        public void DoQuickDonate_Action_Returns_View()
        {
            const int    id         = 1;
            const int    amount     = 100;
            const string date       = "10/11/2011";
            const int    campaignId = 14;

            var controller = new DonationController(donationsService, campaignService);
            var result     = controller.DoQuickDonate(id, amount, date, campaignId);

            result.AssertViewRendered();
        }
        public void UpdateDonationProgram_ShouldUpdateDonationProgramREPO()
        {
            var mockDonationProgramsDto = new DonationProgramDto()
            {
                DonationProgramId   = 1,
                DonationProgramName = "EndPolio",
                Description         = "End Polio Now!",
                ImageRef            = "Ref",
                StartDate           = DateTime.Now,
                EndDate             = DateTime.Now,
                Total = 100
            };

            var mockExpected = new DonationProgram()
            {
                DonationProgramId   = mockDonationProgramsDto.DonationProgramId,
                DonationProgramName = mockDonationProgramsDto.DonationProgramName,
                Description         = mockDonationProgramsDto.Description,
                ImageRef            = mockDonationProgramsDto.ImageRef,
                StartDate           = mockDonationProgramsDto.StartDate,
                EndDate             = mockDonationProgramsDto.EndDate,
                Total = mockDonationProgramsDto.Total
            };

            var mockExpectedUpdated = new DonationProgramDto()
            {
                DonationProgramId   = 1,
                DonationProgramName = "EndPolioNow",
                Description         = "End Polio Now!",
                ImageRef            = "Ref",
                StartDate           = DateTime.Now,
                EndDate             = DateTime.Now,
                Total = 1000
            };

            var mockRepo = new Mock <IRotaractRepository>();

            mockRepo.Setup(d => d.UpdateDonation(mockExpected));

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

            //Act
            var result = donationController.UpdateDonation(mockExpectedUpdated);

            //Assert
            Assert.AreEqual(HttpStatusCode.Accepted, result.StatusCode);
        }
        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"));
        }
        public void GetActiveDonations_ShouldReturnAllActiveDonationPrograms()
        {
            //expected
            var expected = new List <Models.DonationProgram>()
            {
                new Models.DonationProgram {
                    DonationProgramId   = 23,
                    DonationProgramName = "Dona",
                    Description         = "Maxim",
                    ImageRef            = "an image ref",
                    StartDate           = DateTime.Now,
                    EndDate             = DateTime.Now,
                    Total = 12
                },
                new Models.DonationProgram {
                    DonationProgramId   = 24,
                    DonationProgramName = "Donna",
                    Description         = "Maxxim",
                    ImageRef            = "an image refs",
                    StartDate           = DateTime.UtcNow,
                    EndDate             = DateTime.UtcNow,
                    Total = 13
                }
            };

            //mock repository
            var mockRepo = new Mock <IRotaractRepository>();

            mockRepo.Setup(d => d.GetActiveDonationPrograms())
            .Returns(expected);

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

            //Act
            var result = donationController.GetActiveDonations();

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            Assert.IsTrue(result.TryGetContentValue <List <Models.DonationProgram> >(out expected));
        }
        public void SetUp()
        {
            donorServiceMock = new Mock<MinistryPlatform.Translation.Services.Interfaces.IDonorService>();
            gatewayDonorServiceMock = new Mock<IDonorService>();
            stripeServiceMock = new Mock<IPaymentService>();
            authenticationServiceMock = new Mock<IAuthenticationService>();
            gatewayDonationServiceMock = new Mock<IDonationService>();
            mpPledgeService = new Mock<IPledgeService>();
            impersonationService = new Mock<IUserImpersonationService>();
            mpDonationService = new Mock<MinistryPlatform.Translation.Services.Interfaces.IDonationService>();

            fixture = new DonationController(donorServiceMock.Object, stripeServiceMock.Object,
                authenticationServiceMock.Object, gatewayDonorServiceMock.Object, gatewayDonationServiceMock.Object, mpDonationService.Object, mpPledgeService.Object, impersonationService.Object);

            authType = "auth_type";
            authToken = "auth_token";
            fixture.Request = new HttpRequestMessage();
            fixture.Request.Headers.Authorization = new AuthenticationHeaderValue(authType, authToken);
            fixture.RequestContext = new HttpRequestContext();
        }
        public void MakeDonation_ShouldAllowAnUserToDonateREPO()
        {
            //declare and init
            var mockDonationProgram = new DonationProgram
            {
                DonationProgramId   = 1,
                DonationProgramName = "One",
                Description         = "Maxim one",
                ImageRef            = "An image ref",
                StartDate           = DateTime.Now,
                EndDate             = DateTime.Now,
                Total = 111
            };
            const int AmountToDonate = 20;
            const int UserID         = 1234;

            var mockExpected = new DonationDto()
            {
                donationProgram = mockDonationProgram,
                amount          = AmountToDonate
            };

            var mockRepo = new Mock <IRotaractRepository>();

            mockRepo.Setup(d => d.Donate(mockExpected, UserID));

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

            //Act
            var result = donationController.MakeDonation(mockExpected, UserID);

            //Assert
            Assert.AreEqual(HttpStatusCode.Accepted, result.StatusCode);
        }
        public void DeleteDonationProgram_ShouldDeleteTheDonationProgramREPO()
        {
            //Unit test inits
            var       mockRepo   = new Mock <IRotaractRepository>();
            const int IdToDelete = 1;

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

            //Act
            var result = donationController.DeletedDonation(IdToDelete);

            //Verify
            mockRepo.Verify(v => v.DeleteDonationProgram(IdToDelete), Times.Once());

            //Assert
            Assert.IsFalse(result.IsSuccessStatusCode);
        }
Exemplo n.º 15
0
        public static bool ApplicationShouldTerminateAfterDonationPrompt()
        {
            Logger.debug("ApplicationShouldTerminateAfterDonationPrompt");
            License l = LicenseFactory.find();
            if (!l.verify())
            {
                string appVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
                String lastversion = Preferences.instance().getProperty("donate.reminder");
                if (appVersion.Equals(lastversion))
                {
                    // Do not display if same version is installed
                    return true;
                }

                DateTime nextReminder =
                    new DateTime(Preferences.instance().getLong("donate.reminder.date"));
                // Display donationPrompt every n days
                nextReminder.AddDays(Preferences.instance().getLong("donate.reminder.interval"));
                Logger.debug("Next reminder: " + nextReminder);
                // Display after upgrade
                if (nextReminder.CompareTo(DateTime.Now) == 1)
                {
                    // Do not display if shown in the reminder interval
                    return true;
                }
                DonationController controller = new DonationController();
                controller.Show();
            }
            return true;
        }