public void testPostParticipantToGroupIsSuccessful()
        {
            const int groupId = 456;

            List<ParticipantSignup> particpantIdToAdd = new List<ParticipantSignup>
            {
                new ParticipantSignup(){
                    particpantId = 90210,
                    childCareNeeded = false
                },
                new ParticipantSignup()
                {
                    particpantId = 41001,
                    childCareNeeded = false
                }
            };

            List<Event> events = new List<Event>();
            Event e1 = new Event();
            e1.EventId = 101;
            Event e2 = new Event();
            e2.EventId = 202;
            events.Add(e1);
            events.Add(e2);

            var participantsAdded = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object> {
                    {"123", "456"}
                },
                new Dictionary<string, object> {
                    {"abc", "def"}
                },
            };
            groupServiceMock.Setup(mocked => mocked.addParticipantsToGroup(groupId, particpantIdToAdd));

            IHttpActionResult result = fixture.Post(groupId, particpantIdToAdd);

            authenticationServiceMock.VerifyAll();
            groupServiceMock.VerifyAll();

            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkResult), result);
        }
Esempio n. 2
0
        public Event GetEvent(int eventId)
        {
            var token = ApiLogin();
            var searchString = string.Format("{0},", eventId);
            var r = _ministryPlatformService.GetPageViewRecords("EventsWithDetail", token, searchString);
            if (r.Count == 1)
            {
                var record = r[0];
                var e = new Event
                {
                    EventEndDate = record.ToDate("Event_End_Date"),
                    EventId = record.ToInt("Event_ID"),
                    EventStartDate = record.ToDate("Event_Start_Date"),
                    EventTitle = record.ToString("Event_Title"),
                    ParentEventId = record.ToNullableInt("Parent_Event_ID"),
                    PrimaryContact = new Contact
                    {
                        ContactId = record.ToInt("Contact_ID"),
                        EmailAddress = record.ToString("Email_Address")
                    }
                };


                return e;
            }
            if (r.Count == 0)
            {
                return null;
            }
            throw new ApplicationException(string.Format("Duplicate Event ID detected: {0}", eventId));
        }
        public void SendTwoRsvpEmails()
        {
            const int daysBefore = 999;
            const int emailTemplateId = 77;
            const int unassignedContact = 7386594;
            var participants = new List<EventParticipant>
            {
                new EventParticipant
                {
                    ParticipantId = 1,
                    EventId = 123,
                    ContactId = 987654
                },
                new EventParticipant
                {
                    ParticipantId = 2,
                    EventId = 456,
                    ContactId = 456123
                }
            };

            var mockPrimaryContact = new Contact
            {
                ContactId = 98765,
                EmailAddress = "*****@*****.**"
            };

            var defaultContact = new MyContact
            {
                Contact_ID = 123456,
                Email_Address = "*****@*****.**"
            };

            var mockEvent1 = new Event {EventType = "Childcare", PrimaryContact = mockPrimaryContact};
            var mockEvent2 = new Event {EventType = "DoggieDaycare", PrimaryContact = mockPrimaryContact};
            var mockEvents = new List<Event> {mockEvent1, mockEvent2};

            _configurationWrapper.Setup(m => m.GetConfigIntValue("NumberOfDaysBeforeEventToSend")).Returns(daysBefore);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareRequestTemplate")).Returns(emailTemplateId);
            _communicationService.Setup(m => m.GetTemplate(emailTemplateId)).Returns(new MessageTemplate());            
            _eventParticipantService.Setup(m => m.GetChildCareParticipants(daysBefore)).Returns(participants);
            _communicationService.Setup(m => m.SendMessage(It.IsAny<Communication>())).Verifiable();

            var kids = new List<Participant> { new Participant { ContactId = 456321987 } };
            _crdsEventService.Setup(m => m.EventParticpants(987654321, It.IsAny<string>())).Returns(kids);
            var mockChildcareEvent = new Event {EventId = 987654321};
            var mockContact = new Contact
            {
                ContactId = 8888888,
                EmailAddress = "*****@*****.**"
            };
            mockChildcareEvent.PrimaryContact = mockContact;
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[0].EventId)).Returns(mockChildcareEvent);
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[1].EventId)).Returns(mockChildcareEvent);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(mocked => mocked.GetContactById(1234)).Returns(defaultContact); 
            var myKids = new List<Participant>();
            _crdsEventService.Setup(m => m.MyChildrenParticipants(987654, kids, It.IsAny<string>())).Returns(myKids);

            _fixture.SendRequestForRsvp();

            _configurationWrapper.VerifyAll();
            _communicationService.VerifyAll();
            _contactService.VerifyAll();
            _eventParticipantService.VerifyAll();
            _communicationService.VerifyAll();
            _communicationService.Verify(m => m.SendMessage(It.IsAny<Communication>()), Times.Exactly(2));
            _eventService.VerifyAll();
        }
Esempio n. 4
0
        private Dictionary<string, object> HandleNoRsvp(Participant participant,
                                                        Event e,
                                                        List<int> opportunityIds,
                                                        string token,
                                                        MyContact groupLeader)
        {
            int templateId;
            Opportunity previousOpportunity = null;

            try
            {
                templateId = AppSetting("RsvpNoTemplate");
                //opportunityId = opportunityIds.First();
                _eventService.UnregisterParticipantForEvent(participant.ParticipantId, e.EventId);
            }
            catch (ApplicationException ex)
            {
                logger.Debug(ex.Message + ": There is no need to remove the event participant because there is not one.");
                templateId = AppSetting("RsvpNoTemplate");
            }

            // Responding no means that we are saying no to all opportunities for this group for this event            
            foreach (var oid in opportunityIds)
            {
                var comments = string.Empty; //anything of value to put in comments?
                var updatedOpp = _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                                          oid,
                                                                          comments,
                                                                          e.EventId,
                                                                          false);
                if (updatedOpp > 0)
                {
                    previousOpportunity = _opportunityService.GetOpportunityById(oid, token);
                }
            }

            if (previousOpportunity != null)
            {
                var emailName = participant.DisplayName;
                var emailEmail = participant.EmailAddress;
                var emailTeamName = previousOpportunity.GroupName;
                var emailOpportunityName = previousOpportunity.OpportunityName;
                var emailEventDateTime = e.EventStartDate.ToString();

                SendCancellationMessage(groupLeader, emailName, emailEmail, emailTeamName, emailOpportunityName, emailEventDateTime);
            }

            return new Dictionary<string, object>()
            {
                {"templateId", templateId},
                {"previousOpportunity", previousOpportunity},
                {"rsvp", false}
            };
        }
Esempio n. 5
0
        private Dictionary<string, object> HandleYesRsvp(Participant participant,
                                                         Event e,
                                                         int opportunityId,
                                                         IReadOnlyCollection<int> opportunityIds,
                                                         String token)
        {
            var templateId = AppSetting("RsvpYesTemplate");
            var deletedRSVPS = new List<int>();
            Opportunity previousOpportunity = null;

            var opportunity = _opportunityService.GetOpportunityById(opportunityId,token);
            //Try to register this user for the event
            _eventService.RegisterParticipantForEvent(participant.ParticipantId, e.EventId, opportunity.GroupId);

            // Make sure we are only rsvping for 1 opportunity by removing all existing responses
            deletedRSVPS.AddRange(from oid in opportunityIds
                let deletedResponse =
                                      _opportunityService.DeleteResponseToOpportunities(participant.ParticipantId, oid, e.EventId)
                where deletedResponse != 0
                select oid);

            if (deletedRSVPS.Count > 0)
            {
                templateId = AppSetting("RsvpChangeTemplate");
                if (opportunityIds.Count != deletedRSVPS.Count)
                {
                    //Changed yes to yes
                    //prevOppId = deletedRSVPS.First();
                    previousOpportunity = _opportunityService.GetOpportunityById(deletedRSVPS.First(), token);
                }
            }
            var comments = string.Empty; //anything of value to put in comments?
            _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                     opportunityId,
                                                     comments,
                                                     e.EventId,
                                                     true);
            return new Dictionary<string, object>()
            {
                {"templateId", templateId},
                {"previousOpportunity", previousOpportunity},
                {"rsvp", true}
            };
        }
Esempio n. 6
0
 private Dictionary<string, object> CreateRsvp(string token,
                                               int opportunityId,
                                               List<int> opportunityIds,
                                               bool signUp,
                                               Participant participant,
                                               Event @event,
                                               MyContact groupLeader)
 {
     var response = signUp
         ? HandleYesRsvp(participant, @event, opportunityId, opportunityIds, token)
         : HandleNoRsvp(participant, @event, opportunityIds, token, groupLeader);
     return response;
 }
Esempio n. 7
0
 private static DateTime IncrementSequenceDate(Event @event, DateTime sequenceDate, int increment)
 {
     if (@event.EventStartDate.Date > sequenceDate.Date)
     {
         sequenceDate = sequenceDate.AddDays(increment);
     }
     return sequenceDate;
 }
Esempio n. 8
0
 private static MyContact ReplyToContact(Event childEvent)
 {
     var contact = childEvent.PrimaryContact;
     var replyToContact = new MyContact
     {
         Contact_ID = contact.ContactId,
         Email_Address = contact.EmailAddress
     };
     return replyToContact;
 }