public void PostOfExistingInvitedEmailIsUntouchedByNewInvitation()
        {
            // Arrange
            Guid   manageToken    = Guid.NewGuid();
            Guid   ballotToken    = Guid.NewGuid();
            Ballot existingBallot = new Ballot()
            {
                Email = "[email protected]", ManageGuid = manageToken, TokenGuid = ballotToken
            };

            _dummyBallots.Add(existingBallot);
            _mainPoll.Ballots.Add(existingBallot);
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true, ManageToken = manageToken
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            Ballot newBallot = _mainPoll.Ballots.FirstOrDefault();

            Assert.IsNotNull(newBallot);
            Assert.AreEqual(manageToken, newBallot.ManageGuid);
            Assert.AreEqual(ballotToken, newBallot.TokenGuid);
            Assert.AreEqual("[email protected]", newBallot.Email);
        }
        public void PostOfExistingPendingEmailIsLeftAsPending()
        {
            // Arrange
            Guid   manageToken   = Guid.NewGuid();
            Ballot pendingBallot = new Ballot()
            {
                Email = "[email protected]", ManageGuid = manageToken
            };

            _dummyBallots.Add(pendingBallot);
            _mainPoll.Ballots.Add(pendingBallot);
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = false, ManageToken = manageToken
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            Ballot newBallot = _mainPoll.Ballots.FirstOrDefault();

            Assert.IsNotNull(newBallot);
            Assert.AreEqual(manageToken, newBallot.ManageGuid);
            Assert.AreEqual(Guid.Empty, newBallot.TokenGuid);
            Assert.AreEqual("[email protected]", newBallot.Email);
        }
        public void SavingAnEmailWithoutSendingInvitationDoesNotGenerateANewBallotMetric()
        {
            // Arrange
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = false
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            _mockMetricHandler.Verify(m => m.HandleBallotAddedEvent(It.IsAny <Ballot>(), It.IsAny <Guid>()), Times.Never());
        }
        public void AddingANewInvitationGeneratesAnAddBallotMetric()
        {
            // Arrange
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            _mockMetricHandler.Verify(m => m.HandleBallotAddedEvent(It.Is <Ballot>(b => b.Email == "[email protected]"), _mainPoll.UUID), Times.Once());
        }
        public void PostOfNewEmailIsSentAnInvitation()
        {
            // Arrange
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            Ballot newBallot = _mainPoll.Ballots.FirstOrDefault();

            _mockInvitationService.Verify(mis => mis.SendInvitation(_mainPoll.UUID, newBallot, _mainPoll.Name));
        }
        public void PostOfNewEmailIsSavedAsInvitedBallot()
        {
            // Arrange
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            Ballot newBallot = _mainPoll.Ballots.FirstOrDefault();

            Assert.IsNotNull(newBallot);
            Assert.AreNotEqual(Guid.Empty, newBallot.ManageGuid);
            Assert.AreNotEqual(Guid.Empty, newBallot.TokenGuid);
            Assert.AreEqual("[email protected]", newBallot.Email);
        }
        public void ResendingEmailToAnExistingBallotDoesNotGenerateNewBallotMetric()
        {
            // Arrange
            Ballot existingBallot = new Ballot {
                Email = "[email protected]", TokenGuid = Guid.NewGuid(), ManageGuid = Guid.NewGuid()
            };

            _mainPoll.Ballots.Add(existingBallot);
            _dummyBallots.Add(existingBallot);
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true, ManageToken = existingBallot.ManageGuid
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            _mockMetricHandler.Verify(m => m.HandleBallotAddedEvent(It.IsAny <Ballot>(), It.IsAny <Guid>()), Times.Never());
        }
        public void PostCanHandleBallotsWithoutEmails()
        {
            // Arrange
            Ballot nullEmailBallot = new Ballot()
            {
                Email = null, TokenGuid = Guid.Empty
            };

            _inviteOnlyPoll.Ballots = new List <Ballot> {
                nullEmailBallot
            };
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]"
            };

            // Act
            _controller.Post(_inviteOnlyManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert - No error thrown
        }
        public void PostOfExistingEmailIsSentAnInvitation()
        {
            // Arrange
            Guid   manageToken   = Guid.NewGuid();
            Ballot pendingBallot = new Ballot()
            {
                Email = "[email protected]", ManageGuid = manageToken
            };

            _dummyBallots.Add(pendingBallot);
            _mainPoll.Ballots.Add(pendingBallot);
            var request = new ManageInvitationRequestModel {
                Email = "[email protected]", SendInvitation = true, ManageToken = manageToken
            };

            // Act
            _controller.Post(_mainManageID, new List <ManageInvitationRequestModel> {
                request
            });

            // Assert
            _mockInvitationService.Verify(mis => mis.SendInvitation(_mainPoll.UUID, pendingBallot, _mainPoll.Name));
        }