public void SqlExecutor_ConnectionFactory_Test()
        {
            var sqlExecutor = Substitute.For<ISqlExecutor>();

            var db = new DefaultDb(sqlExecutor, x => Substitute.For<ISqlGenerator>(), () => Substitute.For<IDbConnection>());
            Assert.Equal(sqlExecutor, db.GetSqlExecutor());
        }
예제 #2
0
        [SetUp] public void Init()
        {
            string url =
                @"$CaseID=cooling & $DbType=Access & $DataSource=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\topics\org.opencbr.core\db\casebase.mdb & $DictionaryTable=tbl_dic & $DataTable=tbl_data";

            _db = new DefaultDb(url);
        }
예제 #3
0
        public static void Main(string[] args)
        {
            IWebHost webHost = CreateWebHostBuilder(args).Build();

            using (IServiceScope serviceScope = webHost.Services.CreateScope())
            {
                using (JobstoreDbContext jobstoreDbContext = serviceScope.ServiceProvider.GetRequiredService <JobstoreDbContext>())
                {
                    var roleManager = serviceScope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                    DefaultDb.Seed(jobstoreDbContext, roleManager);
                }
            }
            webHost.Run();
        }
        public void SqlGenerator_ConnectionFactory_Test()
        {
            var g = new Dictionary<Type, ISqlGenerator>();
            g.Add(typeof(Models.SqlEntity), Substitute.For<ISqlGenerator>());
            g.Add(typeof(Models.SqlEntityId), Substitute.For<ISqlGenerator>());

            Assert.NotEqual(g[typeof(Models.SqlEntity)], g[typeof(Models.SqlEntityId)]); // insure that there different mocks

            var db = new DefaultDb(Substitute.For<ISqlExecutor>(), x => g[x], () => Substitute.For<IDbConnection>());
            Assert.Equal(g[typeof(Models.SqlEntity)], db.GetSqlGenerator<Models.SqlEntity>());
            Assert.Equal(g[typeof(Models.SqlEntityId)], db.GetSqlGenerator<Models.SqlEntityId>());
            Assert.Equal(g[typeof(Models.SqlEntity)], db.GetSqlGenerator<Models.SqlEntity>());
            Assert.Equal(g[typeof(Models.SqlEntityId)], db.GetSqlGenerator<Models.SqlEntityId>());
        }
예제 #5
0
        internal void Normalize(string key)
        {
            Master = null;
            if (Queue != null)
            {
                Queue = Queue.Trim();
                if (Defines.OperationSystem == tagOperationSystem.osWin || Defines.OperationSystem == tagOperationSystem.osWinCE)
                {
                    Queue = Queue.ToLower();
                }
                if (Queue.Length == 0)
                {
                    AutoMerge = false;
                }
            }
            else
            {
                AutoMerge = false;
            }
            if (Threads == 0)
            {
                Threads = 1;
            }
            if (ConnTimeout == 0)
            {
                ConnTimeout = CClientSocket.DEFAULT_CONN_TIMEOUT;
            }
            if (RecvTimeout == 0)
            {
                RecvTimeout = CClientSocket.DEFAULT_RECV_TIMEOUT;
            }
            if (DefaultDb != null)
            {
                DefaultDb = DefaultDb.Trim();
            }
            if (DefaultDb != null && DefaultDb.Length > 0)
            {
                PoolType = tagPoolType.Master;
            }
            else
            {
                PoolType = tagPoolType.Regular;
                if (m_Slaves != null && m_Slaves.Count > 0)
                {
                    throw new Exception("Regular pool cannot contain any slave pool");
                }
            }
            switch (SvsId)
            {
            case BaseServiceID.sidHTTP:
                throw new Exception("Client side does not support HTTP/websocket service");

            case BaseServiceID.sidQueue:
                if ((DefaultDb != null && DefaultDb.Length > 0) || m_Slaves != null)
                {
                    throw new Exception("Server queue service does not support master or slave pool");
                }
                break;

            case BaseServiceID.sidFile:
                if ((DefaultDb != null && DefaultDb.Length > 0) || m_Slaves != null)
                {
                    throw new Exception("Remote file service does not support master or slave pool");
                }
                break;

            case BaseServiceID.sidODBC:
                break;

            default:
                if (SvsId <= BaseServiceID.sidReserved)
                {
                    throw new Exception("User defined service id must be larger than " + BaseServiceID.sidReserved);
                }
                break;
            }
            if ((DefaultDb == null || DefaultDb.Length == 0) && m_Slaves != null)
            {
                throw new Exception("Slave array is not empty but DefaultDb string is empty");
            }
            if (m_Slaves != null && PoolType == tagPoolType.Master)
            {
                NormalizeSlaves(SvsId, DefaultDb, key);
            }
        }
        public void CloseConnection_Test()
        {
            var dbConnection = Substitute.For<IDbConnection>();
            dbConnection.State.Returns(ConnectionState.Open);

            var db = new DefaultDb(Substitute.For<ISqlExecutor>(), x => Substitute.For<ISqlGenerator>(), dbConnection);

            db.CloseConnection(dbConnection);
            dbConnection.Received(0).Close();
        }
        public void OpenConnection_Test()
        {
            var dbConnection = Substitute.For<IDbConnection>();
            dbConnection.State.Returns(ConnectionState.Closed);

            var db = new DefaultDb(Substitute.For<ISqlExecutor>(), x => Substitute.For<ISqlGenerator>(), dbConnection);

            var execResult = db.OpenConnection();
            Assert.Equal(dbConnection, execResult);

            dbConnection.Received(0).Open();
        }
        public void CloseNullConnection_Factory_Test()
        {
            var db = new DefaultDb(Substitute.For<ISqlExecutor>(), x => Substitute.For<ISqlGenerator>(), () => Substitute.For<IDbConnection>());

            db.CloseConnection(null);
        }
        public void OpenConnection_Factory_Test()
        {
            var dbConnection = Substitute.For<IDbConnection>();
            var factory = Substitute.For<Func<IDbConnection>>();
            factory.Invoke().Returns(dbConnection);

            var db = new DefaultDb(Substitute.For<ISqlExecutor>(), x => Substitute.For<ISqlGenerator>(), factory);

            var execResult = db.OpenConnection();
            Assert.Equal(dbConnection, execResult);

            factory.Received(1).Invoke();
            dbConnection.Received(1).Open();
        }