private void CreateOrUpdateFormAnswer(MpFormAnswer answer, string token)
        {
            var formAnswer = new Dictionary <string, object>
            {
                { "Form_Response_ID", answer.FormResponseId },
                { "Form_Field_ID", answer.FieldId },
                { "Response", answer.Response },
                { "Opportunity_Response", answer.OpportunityResponseId },
                { "Event_Participant_ID", answer.EventParticipantId }
            };

            try
            {
                var responseAnswerId = GetFormResponseAnswerIdForFormFeildFormResponse(answer.FormResponseId, answer.FieldId);
                if (responseAnswerId == 0)
                {
                    _ministryPlatformService.CreateRecord(_formAnswerPageId, formAnswer, token, true);
                }
                else
                {
                    formAnswer.Add("Form_Response_Answer_ID", responseAnswerId);
                    _ministryPlatformService.UpdateRecord(_formAnswerPageId, formAnswer, token);
                }
            }
            catch (Exception exception)
            {
                throw new ApplicationException($"CreateFormAnswer failed.  Field Id: {answer.FieldId}", exception);
            }
        }
예제 #2
0
        public void SetUp()
        {
            _ministryPlatformService = new Mock <IMinistryPlatformService>();
            _authService             = new Mock <IAuthenticationRepository>();
            _configWrapper           = new Mock <IConfigurationWrapper>();
            _dbConnection            = new Mock <IDbConnection>();
            _ministryPlatformRest    = new Mock <IMinistryPlatformRestRepository>();

            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_USER")).Returns("uid");
            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_PASSWORD")).Returns("pwd");
            _authService.Setup(m => m.Authenticate(It.IsAny <string>(), It.IsAny <string>())).Returns(new AuthToken
            {
                AccessToken = "ABC",
                ExpiresIn   = 123
            });

            _fixture = new FormSubmissionRepository(_ministryPlatformService.Object, _dbConnection.Object, _authService.Object, _configWrapper.Object, _ministryPlatformRest.Object);

            _mockAnswer1 = new MpFormAnswer
            {
                FieldId               = 375,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test Last Name",
                EventParticipantId    = null
            };

            _mockAnswer2 = new MpFormAnswer
            {
                FieldId               = 376,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test First Name",
                EventParticipantId    = null
            };

            _mockAnswer3 = new MpFormAnswer
            {
                FieldId               = 377,
                FormResponseId        = responseId,
                OpportunityResponseId = 7329,
                Response              = "Test Middle Initial",
                EventParticipantId    = null
            };

            _mockForm = new MpFormResponse
            {
                FormId                = 17,
                ContactId             = 2389887,
                OpportunityId         = 313,
                OpportunityResponseId = 7329,
                FormAnswers           = new List <MpFormAnswer>
                {
                    _mockAnswer1,
                    _mockAnswer2,
                    _mockAnswer3
                }
            };
        }
예제 #3
0
        private MpFormAnswer SetCustomField(CustomField customField, int opportunityResponseId)
        {
            int fieldId;

            try
            {
                fieldId = _formFields.Single(f => f.CrossroadsId == customField.CrossroadsId).FormFieldId;
            }
            catch
            {
                throw new ApplicationException(string.Format("Failed to locate id for crossroads field {0}",
                                                             customField.CrossroadsId));
            }
            var answer = new MpFormAnswer();

            answer.FieldId = fieldId;
            answer.OpportunityResponseId = opportunityResponseId;
            answer.Response = customField.Value;
            return(answer);
        }
        public void SubmitFormResponse()
        {
            var expectedResponseDict = new Dictionary <string, object>
            {
                { "Form_ID", _mockForm.FormId },
                { "Response_Date", DateTime.Today },
                { "Contact_ID", _mockForm.ContactId },
                { "Opportunity_ID", _mockForm.OpportunityId },
                { "Opportunity_Response", _mockForm.OpportunityResponseId },
                { "Pledge_Campaign_ID", null }
            };

            var expectedAnswerDict1 = new Dictionary <string, object>
            {
                { "Form_Response_ID", _mockAnswer1.FormResponseId },
                { "Form_Field_ID", _mockAnswer1.FieldId },
                { "Response", _mockAnswer1.Response },
                { "Opportunity_Response", _mockAnswer1.OpportunityResponseId },
                { "Event_Participant_ID", null }
            };

            var expectedAnswerDict2 = new Dictionary <string, object>
            {
                { "Form_Response_ID", _mockAnswer2.FormResponseId },
                { "Form_Field_ID", _mockAnswer2.FieldId },
                { "Response", _mockAnswer2.Response },
                { "Opportunity_Response", _mockAnswer2.OpportunityResponseId },
                { "Event_Participant_ID", null }
            };

            var expectedAnswerDict3 = new Dictionary <string, object>
            {
                { "Form_Response_ID", _mockAnswer3.FormResponseId },
                { "Form_Field_ID", _mockAnswer3.FieldId },
                { "Response", _mockAnswer3.Response },
                { "Opportunity_Response", _mockAnswer3.OpportunityResponseId },
                { "Event_Participant_ID", null }
            };


            _ministryPlatformService.Setup(m => m.CreateRecord(formResponsePageId, expectedResponseDict, It.IsAny <string>(), true)).Returns(responseId);
            _ministryPlatformService.Setup(m => m.CreateRecord(formAnswerPageId, expectedAnswerDict1, It.IsAny <string>(), true));
            _ministryPlatformService.Setup(m => m.CreateRecord(formAnswerPageId, expectedAnswerDict2, It.IsAny <string>(), true));
            _ministryPlatformService.Setup(m => m.CreateRecord(formAnswerPageId, expectedAnswerDict3, It.IsAny <string>(), true));

            _ministryPlatformRest.Setup(m => m.UsingAuthenticationToken(It.IsAny <string>())).Returns(_ministryPlatformRest.Object);

            var formResult = new List <MpFormResponse>();
            var f          = new MpFormResponse {
                FormResponseId = 0
            };

            formResult.Add(f);
            _ministryPlatformRest.Setup(m => m.Search <MpFormResponse>(It.IsAny <string>(), It.IsAny <string>(), null, true)).Returns(formResult);

            var ansResult = new List <MpFormAnswer>();
            var a         = new MpFormAnswer {
                FormResponseAnswerId = 0
            };

            _ministryPlatformRest.Setup(m => m.Search <MpFormAnswer>(It.IsAny <string>(), It.IsAny <string>(), null, true)).Returns(ansResult);


            var result = _fixture.SubmitFormResponse(_mockForm);

            Assert.AreEqual(responseId, result);
            _ministryPlatformService.VerifyAll();
        }