public Group getGroupDetails(int groupId) { return (WithApiLogin<Group>(apiToken => { logger.Debug("Getting group details for group " + groupId); var groupDetails = ministryPlatformService.GetRecordDict(GroupsPageId, groupId, apiToken, false); if (groupDetails == null) { logger.Debug("No group found for group id " + groupId); return (null); } var g = new Group(); object gid = null; groupDetails.TryGetValue("Group_ID", out gid); if (gid != null) { g.GroupId = (int) gid; } object gn = null; groupDetails.TryGetValue("Group_Name", out gn); if (gn != null) { g.Name = (string) gn; } object gt = null; groupDetails.TryGetValue("Group_Type_ID", out gt); if (gt != null) { g.GroupType = (int) gt; } object gsz = null; groupDetails.TryGetValue("Target_Size", out gsz); if (gsz != null) { g.TargetSize = (short) gsz; } object gf = null; groupDetails.TryGetValue("Group_Is_Full", out gf); if (gf != null) { g.Full = (Boolean) gf; } object gwl = null; groupDetails.TryGetValue("Enable_Waiting_List", out gwl); if (gwl != null) { g.WaitList = (Boolean) gwl; } object gcc = null; groupDetails.TryGetValue("Child_Care_Available", out gcc); if (gcc != null) { g.ChildCareAvailable = (Boolean) gcc; } object gc = null; groupDetails.TryGetValue("Congregation_ID_Text", out gc); if (gc != null) { g.Congregation = (string)gc; } object ma = null; groupDetails.TryGetValue("Online_RSVP_Minimum_Age", out ma); if (ma != null) { g.MinimumAge = (int) ma; } if (g.WaitList) { var subGroups = ministryPlatformService.GetSubPageRecords(GroupsSubgroupsPageId, groupId, apiToken); if (subGroups != null) { foreach (var i in subGroups) { if (i.ContainsValue("Wait List")) { object gd = null; i.TryGetValue("dp_RecordID", out gd); g.WaitListGroupId = (int) gd; break; } } } else { logger.Debug("No wait list found for group id " + groupId); } } logger.Debug("Getting participants for group " + groupId); var participants = ministryPlatformService.GetSubpageViewRecords(GroupsParticipantsSubPageId, groupId, apiToken); if (participants != null && participants.Count > 0) { foreach (Dictionary<string, object> p in participants) { object pid = null; p.TryGetValue("Participant_ID", out pid); if (pid != null) { g.Participants.Add(new GroupParticipant { ContactId = p.ToInt("Contact_ID"), ParticipantId = p.ToInt("Participant_ID"), GroupRoleId = p.ToInt("Group_Role_ID"), GroupRoleTitle = p.ToString("Role_Title"), LastName = p.ToString("Last_Name"), NickName = p.ToString("Nickname") }); } } } else { logger.Debug("No participants found for group id " + groupId); } logger.Debug("Group details: " + g); return (g); })); }
public GroupFullException(Group group) : base("Group is full: " + group.Participants.Count + " > " + group.TargetSize) { this.group = group; }
public Group GetGroupParticipantsForOpportunity(int opportunityId, string token) { var opp = _ministryPlatformService.GetRecordDict(_opportunityPage, opportunityId, token); var groupId = opp.ToInt("Add_to_Group"); var groupName = opp.ToString("Add_to_Group_Text"); var searchString = ",,,," + opp.ToString("Group_Role_ID"); var eventTypeId = opp.ToInt("Event_Type_ID"); var group = _ministryPlatformService.GetSubpageViewRecords(_groupParticpantsSubPageView, groupId, token, searchString); var participants = new List<GroupParticipant>(); foreach (var groupParticipant in group) { participants.Add(new GroupParticipant { ContactId = groupParticipant.ToInt("Contact_ID"), GroupRoleId = groupParticipant.ToInt("Group_Role_ID"), GroupRoleTitle = groupParticipant.ToString("Role_Title"), LastName = groupParticipant.ToString("Last_Name"), NickName = groupParticipant.ToString("Nickname"), ParticipantId = groupParticipant.ToInt("dp_RecordID") }); } var retGroup = new Group { GroupId = groupId, Name = groupName, Participants = participants, EventTypeId = eventTypeId }; return retGroup; }
public void testAddParticipantToGroupWhenGroupFull() { int groupId = 333; Group g = new Group(); g.GroupId = 333; g.GroupType = 8; g.GroupRole = "Member"; g.Name = "Test Me"; g.TargetSize = 5; g.WaitList = false; g.Full = true; var particpantIdToAdd = new List<ParticipantSignup> { new ParticipantSignup() { particpantId = 90210, childCareNeeded = false }, new ParticipantSignup() { particpantId = 41001, childCareNeeded = false } }; var groupFull = new GroupFullException(g); groupServiceMock.Setup(mocked => mocked.addParticipantsToGroup(groupId, particpantIdToAdd)).Throws(groupFull); try { fixture.Post(333, particpantIdToAdd); Assert.Fail("Expected exception was not thrown"); } catch (Exception e) { Assert.AreEqual(typeof(HttpResponseException), e.GetType()); var ex = (HttpResponseException)e; Assert.IsNotNull(ex.Response); Assert.AreEqual((HttpStatusCode)422, ex.Response.StatusCode); } }
public void testGetGroupDetails() { int groupId = 333; int contactId = 777; Group g = new Group(); g.GroupId = 333; g.GroupType = 8; g.GroupRole = "Member"; g.Name = "Test Me"; g.GroupId = 123456; g.TargetSize = 5; g.WaitList = true; g.WaitListGroupId = 888; Participant participant = new Participant(); participant.ParticipantId = 90210; participantServiceMock.Setup( mocked => mocked.GetParticipantRecord(fixture.Request.Headers.Authorization.ToString())) .Returns(participant); authenticationServiceMock.Setup(mocked => mocked.GetContactId(fixture.Request.Headers.Authorization.ToString())).Returns(contactId); var relationRecord = new GroupSignupRelationships { RelationshipId = 1, RelationshipMinAge = 00, RelationshipMaxAge = 100 }; var groupDto = new GroupDTO { }; groupServiceMock.Setup(mocked => mocked.getGroupDetails(groupId, contactId, participant, fixture.Request.Headers.Authorization.ToString())).Returns(groupDto); IHttpActionResult result = fixture.Get(groupId); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<GroupDTO>), result); groupServiceMock.VerifyAll(); var groupDtoResponse = ((OkNegotiatedContentResult<GroupDTO>)result).Content; Assert.NotNull(result); Assert.AreSame(groupDto, groupDtoResponse); }
public void shouldThrowGroupIsFullExceptionWhenGroupFullIndicatorIsSet() { var g = new Group { TargetSize = 3, Full = true, Participants = new List<GroupParticipant> { new GroupParticipant() } }; groupService.Setup(mocked => mocked.getGroupDetails(456)).Returns(g); try { fixture.addParticipantsToGroup(456, mockParticipantSignup); Assert.Fail("Expected exception was not thrown"); } catch (Exception e) { Assert.IsInstanceOf(typeof (GroupFullException), e); } groupService.VerifyAll(); }
public void testGetGroupDetails() { var g = new Group { TargetSize = 0, Full = true, Participants = new List<GroupParticipant>(), GroupType = 90210, WaitList = true, WaitListGroupId = 10101, GroupId = 98765 }; var eventList = new List<Event>() { EventHelpers.TranslationEvent() }; groupService.Setup(mocked => mocked.getGroupDetails(456)).Returns(g); groupService.Setup(mocked => mocked.getAllEventsForGroup(456)).Returns(eventList); var relations = new List<GroupSignupRelationships> { new GroupSignupRelationships {RelationshipId = 111} }; groupService.Setup(mocked => mocked.GetGroupSignupRelations(90210)).Returns(relations); var contactRelations = new List<ContactRelationship> { new ContactRelationship { Contact_Id = 333, Relationship_Id = 111, Participant_Id = 222 } }; contactRelationshipService.Setup(mocked => mocked.GetMyCurrentRelationships(777, "auth token")).Returns(contactRelations); var participant = new Participant { ParticipantId = 555, }; groupService.Setup(mocked => mocked.checkIfUserInGroup(555, It.IsAny<List<GroupParticipant>>())).Returns(false); groupService.Setup(mocked => mocked.checkIfUserInGroup(222, It.IsAny<List<GroupParticipant>>())).Returns(false); var response = fixture.getGroupDetails(456, 777, participant, "auth token"); groupService.VerifyAll(); contactRelationshipService.VerifyAll(); Assert.IsNotNull(response); Assert.IsTrue(response.GroupFullInd); Assert.AreEqual(g.GroupId, response.GroupId); Assert.AreEqual(2, response.SignUpFamilyMembers.Count); Assert.AreEqual(g.WaitListGroupId, response.WaitListGroupId); Assert.AreEqual(g.WaitList, response.WaitListInd); }
public void shouldAddParticipantsToGroupAndEvents() { var g = new Group { TargetSize = 0, Full = false, Participants = new List<GroupParticipant>() }; groupService.Setup(mocked => mocked.getGroupDetails(456)).Returns(g); groupService.Setup(mocked => mocked.addParticipantToGroup(999, 456, GROUP_ROLE_DEFAULT_ID, false, It.IsAny<DateTime>(), null, false)).Returns(999456); groupService.Setup(mocked => mocked.addParticipantToGroup(888, 456, GROUP_ROLE_DEFAULT_ID, false, It.IsAny<DateTime>(), null, false)).Returns(888456); groupService.Setup(mocked => mocked.SendCommunityGroupConfirmationEmail(It.IsAny<int>(), 456, true, false)); var events = new List<Event> { new Event {EventId = 777}, new Event {EventId = 555}, new Event {EventId = 444} }; groupService.Setup(mocked => mocked.getAllEventsForGroup(456)).Returns(events); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(999, 777, 456, 999456)).Returns(999777); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(999, 555, 456, 999456)).Returns(999555); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(999, 444, 456, 999456)).Returns(999444); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(888, 777, 456, 888456)).Returns(888777); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(888, 555, 456, 888456)).Returns(888555); eventService.Setup(mocked => mocked.RegisterParticipantForEvent(888, 444, 456, 888456)).Returns(888444); fixture.addParticipantsToGroup(456, mockParticipantSignup); groupService.VerifyAll(); eventService.VerifyAll(); }