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

            SetDBState.SetSingleSubscriptionInstalledDB(
                CommonTestsValues.DefaultTestDBName,
                CommonTestsValues.MainServiceName,
                CommonTestsValues.LoginPass,
                CommonTestsValues.FirstSunscriberName,
                "P_TestSetProcedure",
                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, false));
            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);

            if (testResult.Count < 1 || string.IsNullOrWhiteSpace(testResult[0].MessageString) || testResult[0].MessageType != NotificationMessageType.Error || testResult[0].Error.ErrorNumber != "10700")
            {
                Assert.Fail(testResult[0].MessageString);
            }
        }
Пример #2
0
        public static void RunFile(string fileContent, AccesType asAdmin = AccesType.StandardUser, params string[] replacements)
        {
            string     slqCommandText = string.Format(fileContent, replacements);
            SqlCommand sqlCommand     = new SqlCommand(slqCommandText);

            switch (asAdmin)
            {
            case AccesType.Admin:
                serviceAccessDBAdmin.SQLRunNonQueryProcedure(sqlCommand);
                break;

            case AccesType.AdminAtMasterDB:
                serviceAccessDBAdminMaster.SQLRunNonQueryProcedure(sqlCommand);
                break;

            default:
                serviceAccessDB.SQLRunNonQueryProcedure(sqlCommand);
                break;
            }
        }
Пример #3
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 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.");
            }
        }