Ejemplo n.º 1
0
        public async Task <ActionResult <Invitation> > CreateInvitation(Invitation newInvitation)
        {
            var invitations = await _invitationService.GetInvitations(newInvitation.Sender);

            if (!invitations.Exists(x => (x.Sender == newInvitation.Sender && x.Receiver == newInvitation.Receiver)))
            {
                _invitationService.CreateInvitation(newInvitation);
                return(CreatedAtRoute("GetInvitation", new { id = newInvitation.Id.ToString() }, newInvitation));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public void CanCreateInvitationsForGroups()
        {
            const string token = "dude";

            var invitation = new Invitation()
            {
                EmailAddress   = "*****@*****.**",
                GroupRoleId    = GroupRoleLeader,
                InvitationType = GroupInvitationType,
                RecipientName  = "Dudley Doright",
                RequestDate    = new DateTime(2016, 7, 6),
                SourceId       = 33
            };

            var mpInvitation = new MpInvitation
            {
                InvitationType = invitation.InvitationType,
                EmailAddress   = invitation.EmailAddress,
                GroupRoleId    = invitation.GroupRoleId,
                RecipientName  = invitation.RecipientName,
                RequestDate    = invitation.RequestDate,
                SourceId       = invitation.SourceId,
                InvitationGuid = "guid123",
                InvitationId   = 11
            };

            _invitationRepository.Setup(
                m =>
                m.CreateInvitation(
                    It.Is <MpInvitation>(
                        i =>
                        i.InvitationType == invitation.InvitationType && i.EmailAddress.Equals(invitation.EmailAddress) && i.GroupRoleId == invitation.GroupRoleId &&
                        i.RecipientName.Equals(invitation.RecipientName) && i.RequestDate.Equals(invitation.RequestDate) && i.SourceId == invitation.SourceId))).Returns(mpInvitation);

            var testGroup = new MpGroup
            {
                GroupId = 33,
                Name    = "TestGroup"
            };

            _groupRepository.Setup(mocked => mocked.getGroupDetails(invitation.SourceId)).Returns(testGroup);

            var testLeaderParticipant = new MpParticipant
            {
                DisplayName  = "TestLeaderName",
                ContactId    = 123,
                EmailAddress = "*****@*****.**"
            };

            var leaderContact = new MpMyContact
            {
                Last_Name = "TestLast",
                Nickname  = "TestNick"
            };

            _contactRespository.Setup(mocked => mocked.GetContactById(testLeaderParticipant.ContactId)).Returns(leaderContact);

            _participantRepository.Setup(mocked => mocked.GetParticipantRecord(token)).Returns(testLeaderParticipant);

            var template = new MpMessageTemplate
            {
                Body                = "body",
                FromContactId       = 12,
                FromEmailAddress    = "*****@*****.**",
                ReplyToContactId    = 34,
                ReplyToEmailAddress = "*****@*****.**",
                Subject             = "subject"
            };

            _communicationService.Setup(mocked => mocked.GetTemplate(GroupInvitationEmailTemplate)).Returns(template);

            //_communicationService.Setup(
            //    mocked =>
            //        mocked.SendMessage(
            //            It.Is<MpCommunication>(
            //                c =>
            //                    c.AuthorUserId == 5 && c.DomainId == DomainId && c.EmailBody.Equals(template.Body) && c.EmailSubject.Equals(template.Subject) &&
            //                    c.FromContact.ContactId == template.FromContactId && c.FromContact.EmailAddress.Equals(template.FromEmailAddress) &&
            //                    c.ReplyToContact.ContactId == template.ReplyToContactId && c.ReplyToContact.EmailAddress.Equals(template.ReplyToEmailAddress) &&
            //                    c.ToContacts.Count == 1 && c.ToContacts[0].EmailAddress.Equals(invitation.EmailAddress) &&
            //                    c.MergeData["Invitation_GUID"].ToString().Equals(mpInvitation.InvitationGuid) &&
            //                    c.MergeData["Recipient_Name"].ToString().Equals(mpInvitation.RecipientName) &&
            //                    c.MergeData["Leader_Name"].ToString().Equals(testLeaderParticipant.DisplayName) &&
            //                    c.MergeData["Group_Name"].ToString().Equals(testGroup.Name)),
            //            false)).Returns(77);

            _communicationService.Setup(
                mocked =>
                mocked.SendMessage(
                    It.Is <MpCommunication>(
                        c =>
                        c.AuthorUserId == 5 && c.DomainId == DomainId && c.EmailBody.Equals(template.Body) && c.EmailSubject.Equals(template.Subject) &&
                        c.FromContact.ContactId == template.FromContactId && c.FromContact.EmailAddress.Equals(template.FromEmailAddress) &&
                        c.ReplyToContact.ContactId == testLeaderParticipant.ContactId && c.ReplyToContact.EmailAddress.Equals(template.ReplyToEmailAddress) &&
                        c.ToContacts.Count == 1 && c.ToContacts[0].EmailAddress.Equals(invitation.EmailAddress) &&
                        c.MergeData["Invitation_GUID"].ToString().Equals(mpInvitation.InvitationGuid) &&
                        c.MergeData["Recipient_Name"].ToString().Equals(mpInvitation.RecipientName) &&
                        c.MergeData["Leader_Name"].ToString().Equals(leaderContact.Nickname + " " + leaderContact.Last_Name) &&
                        c.MergeData["Group_Name"].ToString().Equals(testGroup.Name)),
                    false)).Returns(77);

            var created = _fixture.CreateInvitation(invitation, token);

            _invitationRepository.VerifyAll();
            _communicationService.VerifyAll();
            Assert.AreSame(invitation, created);
            Assert.AreEqual(mpInvitation.InvitationId, created.InvitationId);
            Assert.AreEqual(mpInvitation.InvitationGuid, created.InvitationGuid);
        }