public void GetMessagePoolsByPoolId_ReturnsMessagePools()
        {
            var messagePoolDto = new MessagePoolDto
            {
                MessageId = _message.iMessageID,
                PoolId = _pool.iPoolID
            };

            var id = _messagePoolService.AddMessagePool(messagePoolDto);

            Assert.IsTrue(_messagePoolService.GetMessagePoolsByPoolId(_pool.iPoolID).Count > 0);
        }
        public void AddMessagePool_AddsMessagePoolAndReturnsId()
        {
            var messagePoolDto = new MessagePoolDto
            {
                MessageId = _message.iMessageID,
                PoolId = _pool.iPoolID
            };

            var id = _messagePoolService.AddMessagePool(messagePoolDto);

            Assert.IsNotNull(id);
        }
        public int AddMessagePool(MessagePoolDto messagePoolDto)
        {
            var messagePool = new MessagePool
            {
                iMessageID = messagePoolDto.MessageId,
                iPoolID = messagePoolDto.PoolId
            };

            Uow.MessagePools.Add(messagePool);
            Uow.Commit();

            return messagePool.iMessagePoolID;
        }
        public void AddMessagePool_AddsPoolAndCommits()
        {
            // arrange
            var messagePool = new MessagePoolDto
            {
                MessageId = 1,
                PoolId = 5
            };

            // act
            MessagePoolService.AddMessagePool(messagePool);

            // assert
            MockRepoMessagePool.Verify(x => x.Add(It.Is<MessagePool>(pool => pool.iMessageID == messagePool.MessageId && pool.iPoolID == messagePool.PoolId)));
            MockUow.Verify(x => x.Commit());
        }
        /// <summary>
        /// Pool a message for a specific rule
        /// </summary>
        /// <param name="rule"></param>
        /// <param name="messageId"></param>
        /// <returns>If the message should be delivered to the recipient</returns>
        private bool PoolMessage(RuleDto rule, int messageId)
        {
            var pool = _poolService.GetActivePoolByRuleId(rule.Id);
            var deliver = true;

            // check if a pool is sill active for the matched rule. if it is, just add the message to the pool
            if (pool != null)
            {
                // Make sure this pool should remain active or not
                var active = DateTime.Now - pool.StartTime <= rule.PoolActiveTime &&
                             _messagePoolService.GetMessagePoolsByPoolId(pool.Id).Count + 1 < rule.PoolMaxMessages;

                var messagePool = new MessagePoolDto
                {
                    MessageId = messageId,
                    PoolId = pool.Id
                };

                if (active)
                {
                    // pool message
                    _messagePoolService.AddMessagePool(messagePool);
                    deliver = false;
                }
                else
                {
                    // close pool and perform action
                    _messagePoolService.AddMessagePool(messagePool);
                    _poolService.DeactivatePool(pool.Id);
                }
            }
            else
            {
                // Create a new pool for this rule, and add the message and pool to the MassgePool table
                var poolId = _poolService.AddPool(rule.Id);
                var messagePool = new MessagePoolDto
                {
                    MessageId = messageId,
                    PoolId = poolId
                };
                _messagePoolService.AddMessagePool(messagePool);
                deliver = false;
            }

            return deliver;
        }