public void ReceiveSubscription()
        {
            SqlParameterCollection sqlParameters = GetSqlParameterCollectionForTestProcedure(10);

            SetDBState.SetSingleSubscriptionInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass,
                CommonTestsValues.FirstSunscriberName,
                "P_TestGetProcedure",
                sqlParameters);

            SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure");

            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false));
            serviceAccessDBAdmin.SQLRunNonQueryProcedure(dataChangeCommand, 30);

            List <NotificationMessage> testResult = SqlProceduresInstance.ReceiveSubscription(CommonTestsValues.MainServiceName, 15);

            if (testResult.Count < 1 || string.IsNullOrWhiteSpace(testResult[0].MessageString) || testResult[0].MessageType != NotificationMessageType.InsertedData || testResult[0].Inserted == null)
            {
                Assert.Fail(testResult[0].MessageString);
            }
        }
        public void UninstallSingleSubscription()
        {
            SqlParameterCollection sqlParameters = GetSqlParameterCollectionForTestProcedure(10);

            SetDBState.SetTwoSubscriptionInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass,
                CommonTestsValues.FirstSunscriberName,
                "P_TestGetProcedure",
                sqlParameters,
                CommonTestsValues.SecondSunscriberName,
                "P_TestGetProcedure",
                sqlParameters);

            Subscription subscription = new Subscription(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.FirstSunscriberName,
                CommonTestsValues.SubscribedProcedureSchema,
                "P_TestGetProcedure",
                sqlParameters);

            SqlProceduresInstance.UninstallSubscription(subscription);

            List <Tuple <string> > testResult = SetDBState.RunFile <Tuple <string> >(
                Resources.SetSubscription_Test,
                SetDBState.AccesType.StandardUser,
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginName,
                CommonTestsValues.SchemaName,
                CommonTestsValues.Username,
                CommonTestsValues.QueryName,
                CommonTestsValues.ServiceName,
                CommonTestsValues.SubscribersTableName,
                CommonTestsValues.AnySunscriberName);

            if (testResult.Count != 1 || string.IsNullOrWhiteSpace(testResult[0].Item1) || testResult[0].Item1.Substring(0, 1) != "1")
            {
                Assert.Fail(testResult[0].Item1);
            }
            List <NotificationMessage> testMessage = SqlProceduresInstance.ReceiveSubscription(CommonTestsValues.MainServiceName, 15);

            if (testMessage.Count < 1 || string.IsNullOrWhiteSpace(testMessage[0].MessageString) || testMessage[0].MessageType != NotificationMessageType.Unsubscribed)
            {
                Assert.Fail(testMessage[0].MessageString);
            }
        }
        public void AdminUninstallOnAdminInstalledDB()
        {
            SetDBState.SetAdminInstalledDB(CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginPass);
            AdminDependencyDBInstance.AdminUnInstall(CommonTestsValues.DefaultTestDBName, CommonTestsValues.MainServiceName, CommonTestsValues.LoginName);

            List <Tuple <string> > testResult = SetDBState.RunFile <Tuple <string> >(
                Resources.AdminUnInstall_Test,
                SetDBState.AccesType.Admin,
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginName,
                CommonTestsValues.SchemaName,
                CommonTestsValues.Username,
                CommonTestsValues.QueryName,
                CommonTestsValues.ServiceName,
                CommonTestsValues.SubscribersTableName);

            if (testResult.Count != 1 && !string.IsNullOrWhiteSpace(testResult[0].Item1))
            {
                Assert.Fail(testResult[0].Item1);
            }
        }
        public void TestTimeout()
        {
            SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10);

            SetDBState.SetSingleSubscriptionInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass,
                CommonTestsValues.FirstSunscriberName,
                "P_TestGetProcedure",
                sqlParameters);

            DependencyDB.AddReceiver(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.ServiceConnectionString
                );
            Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName);

            receiver.MessageHandler             += HandleMsg;
            receiver.ErrorMessageHandler        += HandleMsg;
            receiver.UnsubscribedMessageHandler += HandleMsg;
            Task receiverTask = new Task(receiver.Listen);

            receiverTask.Start();

            Task waitForResults = new Task(() =>
            {
                while (Message == null)
                {
                    Thread.Sleep(100);
                }
            });

            waitForResults.Start();
            waitForResults.Wait(10000);
        }
Esempio n. 5
0
        public void PublicReceiveSingleSubscription()
        {
            SetDBState.SetAdminInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass);

            DependencyDB.AddReceiver(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.ServiceConnectionString
                );
            Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName);

            receiver.MessageHandler             += HandleMsg;
            receiver.ErrorMessageHandler        += HandleMsg;
            receiver.UnsubscribedMessageHandler += HandleMsg;
            Task receiverTask = new Task(receiver.Listen);

            receiverTask.Start();

            SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10);
            DateTime validTill = (DateTime.Now).AddDays(5.0);

            receiver.Subscribe(
                CommonTestsValues.FirstSunscriberName,
                CommonTestsValues.SubscribedProcedureSchema,
                "P_TestGetProcedure",
                sqlParameters,
                validTill
                );

            AccessDB   accessDB          = new AccessDB(CommonTestsValues.AdminConnectionString);
            SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure");

            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false));
            accessDB.SQLRunNonQueryProcedure(dataChangeCommand, 30);

            Task waitForResults = new Task(() =>
            {
                while (Message == null)
                {
                    Thread.Sleep(100);
                }
            });

            waitForResults.Start();
            waitForResults.Wait(10000);
            receiverTask.Wait(1);

            DependencyDB.StopReceiver(CommonTestsValues.MainServiceName);

            if (Message == null)
            {
                Assert.Fail();
            }
        }
        public void TestStopListening()
        {
            SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10);

            SetDBState.SetSingleSubscriptionInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass,
                CommonTestsValues.FirstSunscriberName,
                "P_TestGetProcedure",
                sqlParameters);

            Receiver receiver = DependencyDB.AddReceiver(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.ServiceConnectionString
                );

            receiver.MessageHandler             += HandleMsg;
            receiver.ErrorMessageHandler        += HandleMsg;
            receiver.UnsubscribedMessageHandler += HandleMsg;
            Task receiverTask = new Task(receiver.Listen);

            receiverTask.Start();

            SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure");

            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false));
            serviceAccessDBAdmin.SQLRunNonQueryProcedure(dataChangeCommand, 30);

            Task waitForResults = new Task(() =>
            {
                while (Message == null)
                {
                    Thread.Sleep(100);
                }
            });

            waitForResults.Start();
            waitForResults.Wait(10000);
            if (Message == null)
            {
                Assert.Fail("No mesage received after DependencyDB.StartListener().");
            }

            DependencyDB.StopReceiver(CommonTestsValues.MainServiceName);
            Thread.Sleep(100000);
            Message = null;

            dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure");
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false));
            serviceAccessDBAdmin.SQLRunNonQueryProcedure(dataChangeCommand, 30);

            waitForResults = new Task(() =>
            {
                while (Message == null)
                {
                    Thread.Sleep(100);
                }
            });
            waitForResults.Start();
            waitForResults.Wait(10000);
            receiverTask.Wait(1);
            if (Message != null)
            {
                Assert.Fail("Mesage received after DependencyDB.StopListener().");
            }
        }
        public void ParallelUnSubscribeSubscribeTest()
        {
            ParallelUnSubscribeTest_Subscribers = new List <string>();
            SetDBState.SetAdminInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass);

            DependencyDB.AddReceiver(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.ServiceConnectionString
                );
            Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName);

            receiver.MessageHandler             += ParallelUnSubscribeSubscribeTest_HandleMsg;
            receiver.ErrorMessageHandler        += ParallelUnSubscribeSubscribeTest_HandleMsg;
            receiver.UnsubscribedMessageHandler += ParallelUnSubscribeSubscribeTest_HandleMsg;
            Task receiverTask = new Task(receiver.Listen);

            receiverTask.Start();


            SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10);
            DateTime validTill = (DateTime.Now).AddDays(5.0);

            for (int i = 0; i < CountParallelInstances; i++)
            {
                string subscriberName = "subscriber" + i;
                ParallelUnSubscribeTest_Subscribers.Add(subscriberName);
            }
            Parallel.ForEach(ParallelUnSubscribeTest_Subscribers,
                             (subscriberName) =>
            {
                switch (subscriberName.GetHashCode() % 2)
                {
                case 1:
                    accesDB.SQLRunNonQueryProcedure(new SqlCommand(Resources.SelectFromTable));
                    break;

                default:
                    receiver.Subscribe(
                        subscriberName,
                        CommonTestsValues.SubscribedProcedureSchema,
                        "P_TestGetProcedure",
                        sqlParameters,
                        validTill
                        );
                    break;
                }
            });

            Parallel.ForEach(ParallelUnSubscribeTest_Subscribers,
                             (subscriberName) =>
            {
                switch (subscriberName.GetHashCode() % 3)
                {
                case 1:
                    accesDB.SQLRunNonQueryProcedure(new SqlCommand(Resources.SelectFromTable));
                    break;

                case 2:
                    receiver.UnSubscribe(
                        subscriberName,
                        CommonTestsValues.SubscribedProcedureSchema,
                        "P_TestGetProcedure",
                        sqlParameters
                        );
                    break;

                default:
                    receiver.Subscribe(
                        subscriberName,
                        CommonTestsValues.SubscribedProcedureSchema,
                        "P_TestGetProcedure",
                        sqlParameters,
                        validTill
                        );
                    break;
                }
            });
            receiverTask.Wait(1);

            DependencyDB.StopReceiver(CommonTestsValues.MainServiceName);
        }
        public void SingleChangeWithMultipleSubscribers()
        {
            SingleChangeWithMultipleSubscribers_Subscribers = new List <string>();
            SetDBState.SetAdminInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass);

            DependencyDB.AddReceiver(
                CommonTestsValues.MainServiceName,
                CommonTestsValues.ServiceConnectionString
                );
            Receiver receiver = DependencyDB.GetReceiver(CommonTestsValues.MainServiceName);

            receiver.MessageHandler             += SingleChangeWithMultipleSubscribers_HandleMsg;
            receiver.ErrorMessageHandler        += SingleChangeWithMultipleSubscribers_HandleMsg;
            receiver.UnsubscribedMessageHandler += SingleChangeWithMultipleSubscribers_HandleMsg;
            Task receiverTask = new Task(receiver.Listen);

            receiverTask.Start();

            SqlParameterCollection sqlParameters = SqlProceduresTests.GetSqlParameterCollectionForTestProcedure(10);
            DateTime validTill = (DateTime.Now).AddDays(5.0);

            for (int i = 0; i < CountParallelInstances; i++)
            {
                string subscriberName = "subscriber" + i;
                SingleChangeWithMultipleSubscribers_Subscribers.Add(subscriberName);
                receiver.Subscribe(
                    subscriberName,
                    CommonTestsValues.SubscribedProcedureSchema,
                    "P_TestGetProcedure",
                    sqlParameters,
                    validTill
                    );
            }

            AccessDB   accessDB          = new AccessDB(CommonTestsValues.AdminConnectionString);
            SqlCommand dataChangeCommand = new SqlCommand("dbo.P_TestSetProcedure");

            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param1", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Param2", SqlDbType.Int, 10));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert1", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Insert2", SqlDbType.Bit, true));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete1", SqlDbType.Bit, false));
            dataChangeCommand.Parameters.Add(AccessDB.CreateSqlParameter("@V_Delete2", SqlDbType.Bit, false));
            accessDB.SQLRunNonQueryProcedure(dataChangeCommand, 30);


            Task waitForResults = new Task(() =>
            {
                while (SingleChangeWithMultipleSubscribers_Subscribers.Count > 0)
                {
                    Thread.Sleep(100);
                }
            });

            waitForResults.Start();
            waitForResults.Wait(20000);
            receiverTask.Wait(1);

            DependencyDB.StopReceiver(CommonTestsValues.MainServiceName);

            if (SingleChangeWithMultipleSubscribers_Subscribers.Count > 0)
            {
                Assert.Fail(SingleChangeWithMultipleSubscribers_Subscribers.Count + " subscribers not recived notification.");
            }
        }