Ejemplo n.º 1
0
        public void DatabaseObjectCleanUpTest()
        {
            var mapper = new ModelToTableMapper <DatabaseObjectAutoCleanUpAfter2InsertsTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");

            var tableDependency = new SqlTableDependency <DatabaseObjectAutoCleanUpAfter2InsertsTestSqlServerModel>(ConnectionString, TableName, mapper);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            var dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            Thread.Sleep(500);

            tableDependency.StopWithoutDisposing();

            Thread.Sleep(500);

            var t = new Task(ModifyTableContent);

            t.Start();

            Thread.Sleep(1000 * 60 * 4);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(dbObjectsNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(dbObjectsNaming));
        }
Ejemplo n.º 2
0
        public void TaskCancellationTest()
        {
            string naming = null;
            SqlTableDependency <TaskCancellationTestSqlServerModel> tableDependency = null;

            try
            {
                var mapper = new ModelToTableMapper <TaskCancellationTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <TaskCancellationTestSqlServerModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                tableDependency.Stop();

                Thread.Sleep(5000);
            }
            catch
            {
                tableDependency?.Dispose();
            }

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
        public void ColumnTypesTest1()
        {
            SqlTableDependency <NVarcharMaxAndVarcharMaxModel> tableDependency = null;
            string naming;

            try
            {
                tableDependency            = new SqlTableDependency <NVarcharMaxAndVarcharMaxModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent1);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.varcharMAXColumn, CheckValues[ChangeType.Insert.ToString()].Item1.varcharMAXColumn);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.nvarcharMAXColumn, CheckValues[ChangeType.Insert.ToString()].Item1.nvarcharMAXColumn);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.varcharMAXColumn, CheckValues[ChangeType.Update.ToString()].Item1.varcharMAXColumn);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.nvarcharMAXColumn, CheckValues[ChangeType.Update.ToString()].Item1.nvarcharMAXColumn);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.varcharMAXColumn, CheckValues[ChangeType.Delete.ToString()].Item1.varcharMAXColumn);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.nvarcharMAXColumn, CheckValues[ChangeType.Delete.ToString()].Item1.nvarcharMAXColumn);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
        public void EventForAllColumnsTest()
        {
            SqlTableDependency <EventForAllColumnsTestSqlServerModel> tableDependency = null;
            string naming;

            try
            {
                var mapper = new ModelToTableMapper <EventForAllColumnsTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(ConnectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(500);

                var t = new Task(ModifyTableContent);
                t.Start();

                Thread.Sleep(1000 * 60 * 1);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 0);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
Ejemplo n.º 5
0
        public void DatabaseObjectCleanUpTest()
        {
            var mapper = new ModelToTableMapper <EventForAllColumnsTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

            var tableDependency = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(ConnectionString, TableName, mapper);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            _dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            Thread.Sleep(50);

            var t = new Task(BigModifyTableContent);

            t.Start();
            t.Wait(10000);

            Thread.Sleep(1000 * 30 * 1);
            tableDependency.Stop();

            SmalModifyTableContent();

            Thread.Sleep(4 * 60 * 1000);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(_dbObjectsNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(_dbObjectsNaming));
        }
        public void AfterThreeMinutesICanGetNotifications()
        {
            SqlTableDependency <MoChangModel2> tableDependency = null;
            string dataBaseObjectsNamingConvention             = null;

            try
            {
                tableDependency            = new SqlTableDependency <MoChangModel2>(ConnectionString);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                dataBaseObjectsNamingConvention = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(4 * 60 * 1000);
                Assert.IsFalse(SqlServerHelper.AreAllDbObjectDisposed(dataBaseObjectsNamingConvention));

                var t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(20000);

                Assert.AreEqual(_counter, 3);
                Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, "Pizza Funghi" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, "Pizza Funghi" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);

                Mal         = "Second round";
                _counter    = 0;
                CheckValues = new Dictionary <string, Tuple <MoChangModel2, MoChangModel2> >();

                Thread.Sleep(7 * 60 * 1000);
                t = new Task(ModifyTableContent);
                t.Start();
                Thread.Sleep(20000);

                Assert.AreEqual(_counter, 3);
                Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, "Pizza Funghi" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, "Pizza Funghi" + Mal);
                Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Surname, "Pizza Mergherita" + Mal);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Thread.Sleep(5000);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(dataBaseObjectsNamingConvention));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(dataBaseObjectsNamingConvention));
        }
Ejemplo n.º 7
0
        public void DatabaseObjectCleanUpTest()
        {
            var tableDependency = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(ConnectionString, TableName);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            _dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            Thread.Sleep(5000);

            tableDependency.StopWithoutDisposing();

            Thread.Sleep(4 * 60 * 1000);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(_dbObjectsNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(_dbObjectsNaming));
        }
Ejemplo n.º 8
0
        public void Issue27Tesst()
        {
            var mapper = new ModelToTableMapper <Issue55Model>();

            mapper.AddMapping(c => c.PaymentDiscount, "Payment Discount %");
            mapper.AddMapping(c => c.AllowQuantity, "Allow Quantity Disc_");
            mapper.AddMapping(c => c.DocNo, "Applies-to Doc_ No_");

            string objectNaming;
            var    tableDependency = new SqlTableDependency <Issue55Model>(ConnectionString, TableName, mapper);

            try
            {
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                objectNaming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency.Dispose();
            }

            Assert.AreEqual(_counter, 3);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.DocNo, _checkValues[ChangeType.Insert.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Insert.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Insert.ToString()].Item1.PaymentDiscount);

            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.DocNo, _checkValues[ChangeType.Update.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Update.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Update.ToString()].Item1.PaymentDiscount);

            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.DocNo, _checkValues[ChangeType.Delete.ToString()].Item1.DocNo);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.AllowQuantity, _checkValues[ChangeType.Delete.ToString()].Item1.AllowQuantity);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.PaymentDiscount, _checkValues[ChangeType.Delete.ToString()].Item1.PaymentDiscount);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(objectNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(objectNaming));
        }
Ejemplo n.º 9
0
        public void DatabaseObjectCleanUpTest()
        {
            var domaininfo = new AppDomainSetup();

            domaininfo.ApplicationBase = Environment.CurrentDirectory;
            var adevidence        = AppDomain.CurrentDomain.Evidence;
            var domain            = AppDomain.CreateDomain("RunsInAnotherAppDomain_Check_DatabaseObjectCleanUp", adevidence, domaininfo);
            var otherDomainObject = (RunsInAnotherAppDomain_Check_DatabaseObjectCleanUp)domain.CreateInstanceAndUnwrap(typeof(RunsInAnotherAppDomain_Check_DatabaseObjectCleanUp).Assembly.FullName, typeof(RunsInAnotherAppDomain_Check_DatabaseObjectCleanUp).FullName);

            _dbObjectsNaming = otherDomainObject.RunTableDependency(ConnectionString, TableName);
            Thread.Sleep(5000);
            AppDomain.Unload(domain);

            SmallModifyTableContent();

            Thread.Sleep(3 * 60 * 1000);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(_dbObjectsNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(_dbObjectsNaming));
        }
        public void Test()
        {
            SqlTableDependency <BinaryBitCharVarbinaryModel> tableDependency = null;
            string naming;

            try
            {
                tableDependency            = new SqlTableDependency <BinaryBitCharVarbinaryModel>(_connectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(GetString(_checkValues[ChangeType.Insert.ToString()].Item2.binary50Column), GetString(_checkValues[ChangeType.Insert.ToString()].Item1.binary50Column));
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.bitColumn, _checkValues[ChangeType.Insert.ToString()].Item1.bitColumn);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.char10Column, _checkValues[ChangeType.Insert.ToString()].Item1.char10Column);
            Assert.AreEqual(GetString(_checkValues[ChangeType.Insert.ToString()].Item2.varbinary50Column), GetString(_checkValues[ChangeType.Insert.ToString()].Item1.varbinary50Column));
            Assert.AreEqual(GetString(_checkValues[ChangeType.Insert.ToString()].Item2.varbinaryMAXColumn), GetString(_checkValues[ChangeType.Insert.ToString()].Item1.varbinaryMAXColumn));

            Assert.AreEqual(GetString(_checkValues[ChangeType.Update.ToString()].Item2.binary50Column), GetString(_checkValues[ChangeType.Update.ToString()].Item1.binary50Column));
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.bitColumn, _checkValues[ChangeType.Update.ToString()].Item1.bitColumn);
            Assert.AreEqual(new String(_checkValues[ChangeType.Update.ToString()].Item2.char10Column).Trim(), new String(_checkValues[ChangeType.Update.ToString()].Item1.char10Column).Trim());
            Assert.AreEqual(GetString(_checkValues[ChangeType.Update.ToString()].Item2.varbinary50Column), GetString(_checkValues[ChangeType.Update.ToString()].Item1.varbinary50Column));
            Assert.AreEqual(GetString(_checkValues[ChangeType.Update.ToString()].Item2.varbinaryMAXColumn), GetString(_checkValues[ChangeType.Update.ToString()].Item1.varbinaryMAXColumn));

            Assert.AreEqual(GetString(_checkValues[ChangeType.Delete.ToString()].Item2.binary50Column), GetString(_checkValues[ChangeType.Delete.ToString()].Item1.binary50Column));
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.bitColumn, _checkValues[ChangeType.Delete.ToString()].Item1.bitColumn);
            Assert.AreEqual(new String(_checkValues[ChangeType.Delete.ToString()].Item2.char10Column).Trim(), new String(_checkValues[ChangeType.Delete.ToString()].Item1.char10Column).Trim());
            Assert.AreEqual(GetString(_checkValues[ChangeType.Delete.ToString()].Item2.varbinary50Column), GetString(_checkValues[ChangeType.Delete.ToString()].Item1.varbinary50Column));
            Assert.AreEqual(GetString(_checkValues[ChangeType.Delete.ToString()].Item2.varbinaryMAXColumn), GetString(_checkValues[ChangeType.Delete.ToString()].Item1.varbinaryMAXColumn));

            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
Ejemplo n.º 11
0
        public void EventForAllColumnsTest()
        {
            SqlTableDependency <DataAnnotationTestSelServerModel4> tableDependency = null;
            string naming = null;


            var mapper = new ModelToTableMapper <DataAnnotationTestSelServerModel4>();

            mapper.AddMapping(c => c.Description, "Long Description");

            try
            {
                tableDependency            = new SqlTableDependency <DataAnnotationTestSelServerModel4>(ConnectionString, tableName: "ANItemsTableSQL4", mapper: mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Description, CheckValues[ChangeType.Insert.ToString()].Item1.Description);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Name, CheckValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.Description, CheckValues[ChangeType.Update.ToString()].Item1.Description);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Description, CheckValues[ChangeType.Delete.ToString()].Item1.Description);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
Ejemplo n.º 12
0
        public void Test()
        {
            SqlTableDependency <BigIntDecimalAndFloatModel> tableDependency = null;
            string naming;

            try
            {
                tableDependency            = new SqlTableDependency <BigIntDecimalAndFloatModel>(ConnectionString, TableName);
                tableDependency.OnChanged += this.TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.bigintColumn, CheckValues[ChangeType.Insert.ToString()].Item1.bigintColumn);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.decimal18Column, CheckValues[ChangeType.Insert.ToString()].Item1.decimal18Column);
            Assert.IsNull(CheckValues[ChangeType.Insert.ToString()].Item2.decimal54Column);
            Assert.IsNull(CheckValues[ChangeType.Insert.ToString()].Item2.floatColumn);

            Assert.IsNull(CheckValues[ChangeType.Update.ToString()].Item2.bigintColumn);
            Assert.IsNull(CheckValues[ChangeType.Update.ToString()].Item2.decimal18Column);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.decimal54Column, CheckValues[ChangeType.Update.ToString()].Item1.decimal54Column);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.floatColumn, CheckValues[ChangeType.Update.ToString()].Item1.floatColumn);

            Assert.IsNull(CheckValues[ChangeType.Delete.ToString()].Item2.bigintColumn);
            Assert.IsNull(CheckValues[ChangeType.Delete.ToString()].Item2.decimal18Column);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.decimal54Column, CheckValues[ChangeType.Delete.ToString()].Item1.decimal54Column);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.floatColumn, CheckValues[ChangeType.Delete.ToString()].Item1.floatColumn);

            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
        public void StatusTest()
        {
            try
            {
                var mapper = new ModelToTableMapper <StatusTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name");
                mapper.AddMapping(c => c.Surname, "Second Name");
                this._tableDependency                  = new SqlTableDependency <StatusTestSqlServerModel>(ConnectionString, TableName, mapper);
                this._tableDependency.OnChanged       += this.TableDependency_Changed;
                this._tableDependency.OnStatusChanged += this.TableDependency_OnStatusChanged;
                this._tableDependency.OnError         += this.TableDependency_OnError;
                var dataBaseObjectsNamingConvention = _tableDependency.DataBaseObjectsNamingConvention;

                this._tableDependency.Start();

                Thread.Sleep(1 * 60 * 1000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(5000);

                this._tableDependency.Stop();
                t.Wait(100);

                Assert.IsTrue(statuses[TableDependencyStatus.Starting]);
                Assert.IsTrue(statuses[TableDependencyStatus.Started]);
                Assert.IsTrue(statuses[TableDependencyStatus.WaitingForNotification]);
                Assert.IsTrue(statuses[TableDependencyStatus.StopDueToCancellation]);
                Assert.IsFalse(statuses[TableDependencyStatus.StopDueToError]);

                Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(dataBaseObjectsNamingConvention));
                Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(dataBaseObjectsNamingConvention));
            }
            finally
            {
                this._tableDependency?.Dispose();
            }
        }
Ejemplo n.º 14
0
        public void LoadAndCountTest()
        {
            var cts   = new CancellationTokenSource(TimeSpan.FromMinutes(10));
            var token = cts.Token;

            var counterUpTo = 1000;
            var mapper      = new ModelToTableMapper <LoadAndCountTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");
            var listenerTask = Task.Factory.StartNew(() => new ListenerSlq(ConnectionString, TableName, mapper).Run(counterUpTo, token), token);

            Thread.Sleep(3000);

            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                using (var sqlCommand = sqlConnection.CreateCommand())
                {
                    while (!listenerTask.IsCompleted)
                    {
                        if (this._counter <= counterUpTo)
                        {
                            sqlCommand.CommandText = $"INSERT INTO [{TableName}] ([First Name], [Second Name]) VALUES ('{DateTime.Now.Ticks}', '{this._counter}')";
                            sqlCommand.ExecuteNonQuery();
                            this._counter++;
                        }

                        Thread.Sleep(250);
                    }
                }
            }

            Assert.IsTrue(listenerTask.Result != null);
            Assert.IsTrue(listenerTask.Result.Counter == counterUpTo);
            Assert.IsTrue(!listenerTask.Result.SequentialNotificationFailed);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(listenerTask.Result.ObjectNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(listenerTask.Result.ObjectNaming));
        }
        public void Test()
        {
            SqlTableDependency <AAA_Item3> tableDependency = null;
            string naming = null;

            try
            {
                UpdateOfModel <AAA_Item3> updateOF = new UpdateOfModel <AAA_Item3>();
                updateOF.Add(model => model.FamilyName);

                tableDependency            = new SqlTableDependency <AAA_Item3>(ConnectionString, updateOf: updateOF);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(30000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 2);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.Name, CheckValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.FamilyName, CheckValues[ChangeType.Insert.ToString()].Item1.FamilyName);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.Name, CheckValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.FamilyName, CheckValues[ChangeType.Delete.ToString()].Item1.FamilyName);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
        public void DatabaseObjectCleanUpTest()
        {
            var mapper = new ModelToTableMapper <DatabaseObjectAutoCleanUpAfterHugeInsertsTestSqlServerModel>();

            mapper.AddMapping(c => c.Name, "First Name").AddMapping(c => c.Surname, "Second Name");

            var tableDependency = new SqlTableDependency <DatabaseObjectAutoCleanUpAfterHugeInsertsTestSqlServerModel>(ConnectionString, TableName, mapper);

            tableDependency.OnChanged += TableDependency_OnChanged;
            tableDependency.Start();
            var dbObjectsNaming = tableDependency.DataBaseObjectsNamingConvention;

            Thread.Sleep(5000);

            tableDependency.StopWithoutDisposing();

            Thread.Sleep(1000);

            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                using (var sqlCommand = sqlConnection.CreateCommand())
                {
                    for (var i = 0; i < 10000; i++)
                    {
                        sqlCommand.CommandText = $"INSERT INTO [{TableName}] ([First Name], [Second Name]) VALUES ('{i}', '{i}')";
                        sqlCommand.ExecuteNonQuery();
                    }
                }
                sqlConnection.Close();
            }

            Thread.Sleep(1000 * 60 * 3);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(dbObjectsNaming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(dbObjectsNaming));
        }
Ejemplo n.º 17
0
        public void EventForAllColumnsTest()
        {
            SqlTableDependency <ANItemsTableSQL8> tableDependency = null;
            string naming = null;

            try
            {
                tableDependency            = new SqlTableDependency <ANItemsTableSQL8>(ConnectionString);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);

            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.NameNotExist, CheckValues[ChangeType.Insert.ToString()].Item1.NameNotExist);
            Assert.AreEqual(CheckValues[ChangeType.Insert.ToString()].Item2.DescriptionNotExist, CheckValues[ChangeType.Insert.ToString()].Item1.DescriptionNotExist);

            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.NameNotExist, CheckValues[ChangeType.Update.ToString()].Item1.NameNotExist);
            Assert.AreEqual(CheckValues[ChangeType.Update.ToString()].Item2.DescriptionNotExist, CheckValues[ChangeType.Update.ToString()].Item1.DescriptionNotExist);

            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.NameNotExist, CheckValues[ChangeType.Delete.ToString()].Item1.NameNotExist);
            Assert.AreEqual(CheckValues[ChangeType.Delete.ToString()].Item2.DescriptionNotExist, CheckValues[ChangeType.Delete.ToString()].Item1.DescriptionNotExist);

            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
        public void TestForAllColumns()
        {
            SqlTableDependency <EventForAllColumnsTestSqlServerModel> tableDependency = null;
            string naming = null;

            try
            {
                var mapper = new ModelToTableMapper <EventForAllColumnsTestSqlServerModel>();
                mapper.AddMapping(c => c.Name, "FIRST name").AddMapping(c => c.Surname, "Second Name");

                tableDependency            = new SqlTableDependency <EventForAllColumnsTestSqlServerModel>(_connectionString, TableName, mapper);
                tableDependency.OnChanged += TableDependency_Changed;
                tableDependency.Start();
                naming = tableDependency.DataBaseObjectsNamingConvention;

                Thread.Sleep(5000);

                var t = new Task(ModifyTableContent);
                t.Start();
                t.Wait(20000);
            }
            finally
            {
                tableDependency?.Dispose();
            }

            Assert.AreEqual(_counter, 3);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Name, _checkValues[ChangeType.Insert.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Insert.ToString()].Item2.Surname, _checkValues[ChangeType.Insert.ToString()].Item1.Surname);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Name, _checkValues[ChangeType.Update.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Update.ToString()].Item2.Surname, _checkValues[ChangeType.Update.ToString()].Item1.Surname);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.Name, _checkValues[ChangeType.Delete.ToString()].Item1.Name);
            Assert.AreEqual(_checkValues[ChangeType.Delete.ToString()].Item2.Surname, _checkValues[ChangeType.Delete.ToString()].Item1.Surname);
            Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(naming));
            Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(naming));
        }
Ejemplo n.º 19
0
        public void Issue27Tesst()
        {
            try
            {
                string objectNaming;

                using (var tableDependency = new SqlTableDependency <Issue27Model>(ConnectionString, TableName))
                {
                    tableDependency.OnChanged += TableDependency_Changed;
                    tableDependency.Start();
                    objectNaming = tableDependency.DataBaseObjectsNamingConvention;

                    Thread.Sleep(5000);
                }

                Assert.IsTrue(SqlServerHelper.AreAllDbObjectDisposed(objectNaming));
                Assert.IsTrue(SqlServerHelper.AreAllEndpointDisposed(objectNaming));
            }
            catch (Exception exception)
            {
                TestContext.WriteLine(exception.Message);
                Assert.Fail();
            }
        }