Beispiel #1
0
        public void TestMultipleDispose()
        {
            var connectionString = new SqlServerDatabaseConnectionString(
                Instance.DatabasePath,
                TestDatabaseName,
                true
                );

            using (var itemSaver = new SqlBatchItemSaverFactory(
                new EmptyLoggerAdapter(), 
                connectionString.ConnectionString,
                TrnHelper.MainDatabaseName,
                TableName,
                1000000L
                ))
            {
                using (var ebSaver = new BatchBasedSaver(
                    itemSaver,
                    new EmptyLoggerAdapter(),
                    false
                    ))
                {
                    ebSaver.Dispose();
                }
            }

        }
Beispiel #2
0
        public void TestSaveItem1()
        {
            var connectionString = new SqlServerDatabaseConnectionString(
                Instance.DatabasePath,
                TestDatabaseName,
                true
                );

            var record = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName"),
                StringGenerator.GetString("MethodName"),
                DateTime.Now,
                100,
                StringGenerator.GetString("CreationStack"),
                new Exception(StringGenerator.GetString("ExceptionMessage"))
                );

            using (var itemSaver = new SqlBatchItemSaverFactory(
                new EmptyLoggerAdapter(), 
                connectionString.ConnectionString,
                TrnHelper.MainDatabaseName,
                TableName,
                1000000L
                ))
            {
                using (var ebSaver = new BatchBasedSaver(
                    itemSaver,
                    new EmptyLoggerAdapter(),
                    false
                    ))
                {
                    ebSaver.Save(record);
                }
            }

            var dataExists = false;

            using (var connection = new SqlConnection(connectionString.ConnectionString))
            {
                connection.Open();

                var commandText = string.Format(@"
select top(1)
    *
from [{0}].dbo.[{1}] l
join [{0}].dbo.[{1}Stack] s on l.id_stack = s.id
order by
    l.id desc", TrnHelper.MainDatabaseName, TableName);

                using (var command = new SqlCommand(commandText, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Assert.IsTrue(record.CheckEqualityFor(0, reader));

                            dataExists = true;
                        }
                    }
                }
            }

            Assert.IsTrue(dataExists);
        }
Beispiel #3
0
        public void TestSaveItem2()
        {
            var connectionString = new SqlServerDatabaseConnectionString(
                Instance.DatabasePath,
                TestDatabaseName,
                true
                );


            var child0 = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName:Inner0"),
                StringGenerator.GetString("MethodName:Inner0"),
                DateTime.Now.AddSeconds(1),
                10,
                StringGenerator.GetString("CreationStack:Inner0")
                );

            var child1 = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName:Inner1"),
                StringGenerator.GetString("MethodName:Inner1"),
                DateTime.Now.AddSeconds(2),
                50,
                StringGenerator.GetString("CreationStack:Inner1")
                );

            var record = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName"),
                StringGenerator.GetString("MethodName"),
                DateTime.Now,
                100,
                StringGenerator.GetString("CreationStack"),
                new List<IPerformanceRecordData>
                {
                    child0,
                    child1
                }
                );

            var dataExists0 = false;
            var dataExists1 = false;
            var dataExists2 = false;

            using (var itemSaver = new SqlBatchItemSaverFactory(
                new EmptyLoggerAdapter(), 
                connectionString.ConnectionString,
                TrnHelper.MainDatabaseName,
                TableName,
                1000000L
                ))
            {
                using (var ebSaver = new BatchBasedSaver(
                    itemSaver,
                    new EmptyLoggerAdapter(),
                    false
                    ))
                {
                    ebSaver.Save(record);
                }
            }

            using (var connection = new SqlConnection(connectionString.ConnectionString))
            {
                connection.Open();

                var commandText = string.Format(@"
select
    *
from [{0}].dbo.[{1}] l
join [{0}].dbo.[{1}Stack] s on l.id_stack = s.id
order by
    l.id asc", TrnHelper.MainDatabaseName, TableName);

                using (var command = new SqlCommand(commandText, connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        var index = 0;

                        while (reader.Read())
                        {
                            switch (index)
                            {
                                case 0:
                                    Assert.IsTrue(record.CheckEqualityFor(0, reader));
                                    dataExists0 = true;
                                    break;
                                case 1:
                                    Assert.IsTrue(child0.CheckEqualityFor(1, reader));
                                    dataExists1 = true;
                                    break;
                                case 2:
                                    Assert.IsTrue(child1.CheckEqualityFor(1, reader));
                                    dataExists2 = true;
                                    break;
                                default:
                                    Assert.Fail();
                                    break;
                            }

                            index++;
                        }
                    }
                }
            }

            Assert.IsTrue(dataExists0);
            Assert.IsTrue(dataExists1);
            Assert.IsTrue(dataExists2);
        }
Beispiel #4
0
        public void TwoTestWithSameDatabase()
        {
            var connectionString = new SqlServerDatabaseConnectionString(
                Instance.DatabasePath,
                TestDatabaseName,
                true
                );

            var record0 = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName0"),
                StringGenerator.GetString("MethodName0"),
                DateTime.Now,
                100,
                StringGenerator.GetString("CreationStack0")
                );

            var record1 = new TestPerformanceRecordData(
                StringGenerator.GetString("ClassName1"),
                StringGenerator.GetString("MethodName1"),
                DateTime.Now,
                200,
                StringGenerator.GetString("CreationStack1")
                );

            using (var itemSaver = new SqlBatchItemSaverFactory(
                new EmptyLoggerAdapter(),
                connectionString.ConnectionString,
                TrnHelper.MainDatabaseName,
                TableName,
                1000000L
                ))
            {
                using (var ebSaver = new BatchBasedSaver(
                    itemSaver,
                    new EmptyLoggerAdapter(),
                    false
                    ))
                {
                }

            }

            using (var itemSaver = new SqlBatchItemSaverFactory(
                new EmptyLoggerAdapter(),
                connectionString.ConnectionString,
                TrnHelper.MainDatabaseName,
                TableName,
                1000000L
                ))
            {
                using (var ebSaver = new BatchBasedSaver(
                    itemSaver,
                    new EmptyLoggerAdapter(),
                    false
                    ))
                {
                    ebSaver.Save(record1);
                }

            }
        }