public void Ctor_ThrowsAnException_WhenOptionsValueIsNull()
        {
            var exception = Assert.Throws <ArgumentNullException>(
                () => new SqlServerJobQueue(new SqlServerStorage(ConnectionUtils.GetConnectionString()), null));

            Assert.Equal("options", exception.ParamName);
        }
        public override void Before(MethodInfo methodUnderTest)
        {
            Monitor.Enter(GlobalLock);

            if (!_sqlObjectInstalled)
            {
                CreateAndInitializeDatabaseIfNotExists();
                _sqlObjectInstalled = true;
            }

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetConnectionString()))
            {
                connection.Execute(@"
truncate table [HangFire].[AggregatedCounter];
truncate table [HangFire].[Counter];
truncate table [HangFire].[Hash];
delete from [HangFire].[Job];
dbcc checkident('HangFire.Job', RESEED, 0);
truncate table [HangFire].[List];
truncate table [HangFire].[JobQueue];
truncate table [HangFire].[Set];
truncate table [HangFire].[Server];
");
            }
        }
示例#3
0
 private static SqlServerStorage CreateStorage()
 {
     return(new SqlServerStorage(
                ConnectionUtils.GetConnectionString(),
                new SqlServerStorageOptions {
         PrepareSchemaIfNecessary = false
     }));
 }
示例#4
0
        public void DistributedLocks_AreReEntrant_FromTheSameThread_OnTheSameResource()
        {
            var storage = new SqlServerStorage(ConnectionUtils.GetConnectionString());

            using (new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5)))
                using (new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5)))
                {
                    Assert.True(true);
                }
        }
        private static void CreateAndInitializeDatabaseIfNotExists()
        {
            var recreateDatabaseSql = String.Format(
                @"if db_id('{0}') is null create database [{0}] COLLATE SQL_Latin1_General_CP1_CS_AS",
                ConnectionUtils.GetDatabaseName());

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetMasterConnectionString()))
            {
                connection.Execute(recreateDatabaseSql);
            }

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetConnectionString()))
            {
                SqlServerObjectsInstaller.Install(connection, null, true);
            }
        }
示例#6
0
        public void InnerDistributedLock_DoesNotConsumeADatabaseConnection()
        {
            // Arrange
            var storage = new SqlServerStorage(ConnectionUtils.GetConnectionString());

            // Act
            using (var outer = new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5)))
                using (var inner = new SqlServerDistributedLock(storage, "hello", TimeSpan.FromMinutes(5)))
                {
                    // Assert
                    var field = typeof(SqlServerDistributedLock).GetField("_connection",
                                                                          BindingFlags.Instance | BindingFlags.NonPublic);
                    Assert.NotNull(field);

                    Assert.NotNull(field.GetValue(outer));
                    Assert.Null(field.GetValue(inner));
                }
        }
        private static void RecreateDatabaseAndInstallObjects()
        {
            var recreateDatabaseSql = String.Format(
                @"if db_id('{0}') is null create database [{0}]",
                ConnectionUtils.GetDatabaseName());

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetMasterConnectionString()))
            {
                connection.Execute(recreateDatabaseSql);
            }

            using (var connection = new SqlConnection(
                       ConnectionUtils.GetConnectionString()))
            {
                SqlServerObjectsInstaller.Install(connection);
            }
        }
示例#8
0
 public ExpirationManagerFacts()
 {
     _storage = new SqlServerStorage(ConnectionUtils.GetConnectionString());
     _token   = new CancellationToken(true);
 }
 public SqlServerTransactionJobFacts()
 {
     _connection  = new Mock <IDbConnection>();
     _transaction = new Mock <IDbTransaction>();
     _storage     = new Mock <SqlServerStorage>(ConnectionUtils.GetConnectionString());
 }
示例#10
0
 private SqlServerStorage CreateStorage()
 {
     return(new SqlServerStorage(
                ConnectionUtils.GetConnectionString(),
                _options));
 }