public void ShouldReadDataFromCommitedTransaction()
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest ([ID] int, [Value] varchar(32));");
            var insertQuery      = new QueryObject("insert into ##TransactionsTest ([ID], [Value]) values (1, '123');");
            var countQuery       = new QueryObject("select count(*) from ##TransactionsTest;");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            using (var connection = ConnectionsFactory.Create())
                try
                {
                    // When
                    connection.Execute(createTableQuery);
                    using (var session = _sessionsFactory.Create())
                    {
                        session.Execute(insertQuery);
                        session.Commit();
                    }

                    // Then
                    int actualRecordsCount;
                    using (var session = _sessionsFactory.Create())
                        actualRecordsCount = session.Query <int>(countQuery).Single();
                    Assert.Equal(1, actualRecordsCount);
                }
                finally
                {
                    connection.Execute(dropTableQuery);
                }
        }
        public void ShouldUseDecimalValuesListInQuery(ValuesListUsageTestCase <decimal> testCase)
        {
            // When
            decimal[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(@"
if type_id (N'[dbo].[DecimalValuesList]') is null
    create type [dbo].[DecimalValuesList] as table([Value] [numeric](6,3) not null)");

                actual = connection.Query <decimal>(@"
select [Value] from @Param",
                                                    new
                {
                    Param = PrimitiveValuesList.Create(
                        "DecimalValuesList",
                        testCase.Source,
                        new MetaDataCreationOptions {
                        Precision = 6, Scale = 3
                    }
                        )
                })
                         .ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
        public async Task ShouldReadNoDataFromNotCommitedTransaction()
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest ([ID] int, [Value] varchar(32));");
            var insertQuery      = new QueryObject("insert into ##TransactionsTest ([ID], [Value]) values (1, '123');");
            var countQuery       = new QueryObject("select count(*) from ##TransactionsTest;");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            using (var connection = ConnectionsFactory.Create())
                try
                {
                    // When
                    await connection.ExecuteAsync(createTableQuery);

                    using (var session = _sessionsFactory.Create())
                        await session.ExecuteAsync(insertQuery);

                    // Then
                    int actualRecordsCount;
                    using (var session = _sessionsFactory.Create())
                        actualRecordsCount = (await session.QueryAsync <int>(countQuery)).Single();
                    Assert.Equal(0, actualRecordsCount);
                }
                finally
                {
                    await connection.ExecuteAsync(dropTableQuery);
                }
        }
示例#4
0
        public void ShouldPerformBulkInsert(TestEntity[] expected)
        {
            // Given
            var createTableQuery = new QueryObject("create table ##TransactionsTest (Id int identity(1, 1) not null, Name nvarchar(max) not null, Value int not null);");
            var selectAllQuery   = new QueryObject("select * from ##TransactionsTest");
            var dropTableQuery   = new QueryObject("drop table ##TransactionsTest;");

            // When
            TestEntity[] actual;
            using (var connection = ConnectionsFactory.Create())
                try
                {
                    connection.Execute(createTableQuery);

                    using (var session = _sessionsFactory.Create())
                    {
                        session.BulkInsert("##TransactionsTest", expected);
                        session.Commit();
                    }

                    actual = connection.Query <TestEntity>(selectAllQuery).ToArray();
                }
                finally
                {
                    connection.Execute(dropTableQuery);
                }

            // Then
            Assert.Equal(expected, actual);
        }
 public StoredProcedureExecutor(ConnectionsFactory connectionPoolManager, CancellationTokenSource globalCts, IDataBaseSettings settings) :
     base(settings.StartWritingInterval, globalCts)
 {
     this.connectionPoolManager = connectionPoolManager;
     this.globalCts             = globalCts;
     this.settings = settings;
     SetAction(ActionWrapper);
 }
示例#6
0
 public CommonWriter(IWriterCore <T> writerCore, IDataBaseSettings settings, ConnectionsFactory manager, CancellationTokenSource globaCts) :
     base(settings.StartWritingInterval, globaCts)
 {
     this.writerCore = writerCore;
     this.manager    = manager;
     this.settings   = settings;
     this.SetAction(WritingActionWrapper);
     Start();
 }
        public async Task ShouldUseInt32ValuesListInQuery(ValuesListUsageTestCase <int> testCase)
        {
            // When
            int[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = (await connection.QueryAsync <int>(GetAllValuesQuery(testCase.Source))).ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
示例#8
0
        public async Task ShouldUseInt32ValuesListInQuery(int[] expected)
        {
            // When
            int[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = (await connection.QueryAsync <int>(GetAllValuesQuery(expected))).ToArray();
            }

            // Then
            Assert.Equal(expected, actual);
        }
        public void ShouldUseTvpInQueryWithAllTypes(TestEntityWithAllTypes[] expected)
        {
            // When
            TestEntityWithAllTypes[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = connection.Query <TestEntityWithAllTypes>(GetAllValuesQuery(expected)).ToArray();
            }

            // Then
            Assert.Equal(expected, actual);
        }
        public void ShouldUseTvpInQueryWithAllTypes(TvpUsageTestCase <TestEntityWithAllTypes> testCase)
        {
            // When
            TestEntityWithAllTypes[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(CreateTableQuery());
                actual = connection.Query <TestEntityWithAllTypes>(GetAllValuesQuery(testCase.Source)).ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
        public void ShouldUseInt64ValuesListInQuery(ValuesListUsageTestCase <long> testCase)
        {
            // When
            long[] actual;
            using (var connection = ConnectionsFactory.Create())
            {
                connection.Execute(@"
if type_id (N'[dbo].[Int64ValuesList]') is null
    create type [dbo].[Int64ValuesList] as table([Value] [bigint] not null)");

                actual = connection.Query <long>(@"
select [Value] from @Param",
                                                 new { Param = new Int64ValuesList("Int64ValuesList", testCase.Source) })
                         .ToArray();
            }

            // Then
            Assert.Equal(testCase.Source, actual);
        }
示例#12
0
 public OrdersGenerator(State state, ConnectionsFactory connectionsFactory, ISettings settings)
 {
     this.state = state;
     this.connectionsFactory = connectionsFactory;
     this.settings           = settings;
 }
示例#13
0
 public MediaAndFormattingProcessor(DataPreparator dataPreparator, ConnectionsFactory connectionPoolManager)
 {
     this.dataPreparator        = dataPreparator;
     this.connectionPoolManager = connectionPoolManager;
 }
示例#14
0
 public ChatInfoLoader(ConnectionsFactory connectionsFactory)
 {
     this.connectionsFactory = connectionsFactory;
 }
示例#15
0
 public UserChecker(ConnectionsFactory connectionsFactory, IDataStorage <GateKeeperBot> dataStorage)
 {
     this.connectionsFactory = connectionsFactory;
     this.dataStorage        = dataStorage;
 }
示例#16
0
        public StateReport(State state, ICommonWriter <Message> commonWriter, ICommonWriter <Entity> commonWriter2, ConnectionsFactory connectionsFactory)
        {
            ConsistanceOrders = state.ConsistanceOrders.Count;
            foreach (string key in state.Collectors.Keys.ToArray())
            {
                if (state.Collectors.TryGetValue(key, out var val))
                {
                    CollectorsCount += val.Count;
                    foreach (var coll in val)
                    {
                        Collectors.Add(new CollectorReport()
                        {
                            Phone = coll.Phone, Group = key
                        });
                    }
                }
            }
            Messages               = commonWriter.GetQueueCount();
            TotalConnections       = connectionsFactory.TotalConnections;
            ConnectionsHotReserve  = connectionsFactory.HotReserve;
            ExecutingOrdersJournal = state.ExecutingOrdersJournal;

            Orders       = state.CountOrders();
            TargetOrders = state.CountTargetOrders();
        }