public void SubscribeToChannel_Success() { RunInitSql("020.SubscribeToChannel_Success", _conn); IMessageQueue mq = CreateMQ(); // getting channel ID IMQGetChannelIdParams paramsGetChannelId = mq.CreateGetChannelIdParams(); paramsGetChannelId.ChannelName = ConfigurationManager.AppSettings["ChannelName"]; IMQGetChannelIdResult channelId = mq.GetChannelId(paramsGetChannelId); // getting subscriber ID IMQGetSubscriberIdParams paramsGetSubscriberId = mq.CreateGetSubscriberIdParams(); paramsGetSubscriberId.SubscriberName = ConfigurationManager.AppSettings["SenderName"]; IMQGetSubscriberIdResult subscriberId = mq.GetSubscriberId(paramsGetSubscriberId); // subscribing IMQSubscribeParams paramSubscribe = mq.CreateSubscribeParams(); paramSubscribe.ChannelId = (long)channelId.ChannelId; paramSubscribe.SubscriberId = (long)subscriberId.SubscriberId; var result = mq.Subscribe(paramSubscribe); RunFinalizeSql("020.SubscribeToChannel_Success", _conn); Assert.IsNotNull(result); Assert.IsTrue(result.Success); }
public void SubscribeToChannel_InvalidSubscriberId() { RunInitSql("022.SubscribeToChannel_InvalidSubscriberId", _conn); IMessageQueue mq = CreateMQ(); // getting channel ID// getting channel ID IMQGetChannelIdParams paramsGetChannelId = mq.CreateGetChannelIdParams(); paramsGetChannelId.ChannelName = ConfigurationManager.AppSettings["ChannelName"]; IMQGetChannelIdResult channelId = mq.GetChannelId(paramsGetChannelId); // getting subscriber ID long invalidSubscriberId = 666000666; // subscribing IMQSubscribeParams paramSubscribe = mq.CreateSubscribeParams(); paramSubscribe.ChannelId = (long)channelId.ChannelId; paramSubscribe.SubscriberId = invalidSubscriberId; var result = mq.Subscribe(paramSubscribe); RunFinalizeSql("022.SubscribeToChannel_InvalidSubscriberId", _conn); Assert.IsNotNull(result); Assert.IsFalse(result.Success); Assert.IsNotEmpty(result.Errors); }
public void PushMessage_Success() { RunInitSql("030.PushMessage_Success", _conn); IMessageQueue mq = CreateMQ(); // getting channel ID IMQGetChannelIdParams paramsGetChannelId = mq.CreateGetChannelIdParams(); paramsGetChannelId.ChannelName = ConfigurationManager.AppSettings["ChannelName"]; IMQGetChannelIdResult channelId = mq.GetChannelId(paramsGetChannelId); // getting subscribers ID IMQGetSubscriberIdParams paramsSenderId = mq.CreateGetSubscriberIdParams(); paramsSenderId.SubscriberName = ConfigurationManager.AppSettings["SenderName"]; IMQGetSubscriberIdResult senderId = mq.GetSubscriberId(paramsSenderId); IMQGetSubscriberIdParams paramsRecId = mq.CreateGetSubscriberIdParams(); paramsSenderId.SubscriberName = ConfigurationManager.AppSettings["ReceiverName"]; IMQGetSubscriberIdResult receiverId = mq.GetSubscriberId(paramsSenderId); // subscribing both IMQSubscribeParams paramSubscribe = mq.CreateSubscribeParams(); paramSubscribe.ChannelId = (long)channelId.ChannelId; paramSubscribe.SubscriberId = (long)senderId.SubscriberId; var subscribeResult = mq.Subscribe(paramSubscribe); paramSubscribe.SubscriberId = (long)receiverId.SubscriberId; subscribeResult = mq.Subscribe(paramSubscribe); // sending message IMQPushMessageParams paramsPush = mq.CreatePushMessageParams(); paramsPush.ChannelId = (long)channelId.ChannelId; paramsPush.SenderId = (long)senderId.SubscriberId; paramsPush.MessageType = ConfigurationManager.AppSettings["TestMessageType"]; paramsPush.Payload = ConfigurationManager.AppSettings["TestMessagePayload"]; paramsPush.RecipientId = null; var result = mq.PushMessage(paramsPush); RunFinalizeSql("030.PushMessage_Success", _conn); Assert.IsNotNull(result); Assert.IsTrue(result.Success); Assert.IsEmpty(result.Errors); Assert.Greater(result.MessageId, 0); }
public IMQGetChannelIdResult GetChannelId(IMQGetChannelIdParams paramsGetChnlId) { var result = new DbMQGetChannelIdResult(); string spName = "[SP_Get_Channel_Id]"; SqlConnection conn = OpenConnection("ConnectionString"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = schema + "." + spName; cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = conn; try { SqlParameter paramChannelName = new SqlParameter("@Channel_Name", SqlDbType.NVarChar, 255, ParameterDirection.Input, false, 0, 0, "", DataRowVersion.Current, paramsGetChnlId.ChannelName); SqlParameter paramOutChannelId = new SqlParameter("@Channel_Id", SqlDbType.BigInt, 0, ParameterDirection.Output, false, 0, 0, "", DataRowVersion.Current, result.ChannelId); cmd.Parameters.Add(paramChannelName); cmd.Parameters.Add(paramOutChannelId); cmd.ExecuteNonQuery(); result.ChannelId = (long)paramOutChannelId.Value; result.Success = true; } catch (Exception ex) { result.Success = false; result.Errors.Add(new Interfaces.Error() { Message = ex.Message, Code = Interfaces.EErrorCodes.MQDbError, Type = Interfaces.EErrorType.Error }); } conn.Close(); return(result); }