PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Rhino.Etl.Tests/LoadTest/LoadTestFixture.cs

http://github.com/ayende/rhino-etl
C# | 79 lines | 63 code | 12 blank | 4 comment | 2 complexity | f5591c88b175fcd3b4ae18902f6cdb6d MD5 | raw file
 1using Rhino.Etl.Core.Infrastructure;
 2
 3namespace Rhino.Etl.Tests.LoadTest
 4{
 5    using System.Data;
 6    using Core;
 7    using Xunit;
 8    using Rhino.Etl.Core.Operations;
 9
10    /// <summary>
11    /// This fixture is here to verify that we can handle large amount of data
12    /// without consuming too much memory or crashing
13    /// </summary>
14    public class LoadTestFixture : BaseUserToPeopleTest
15    {
16        private const int expectedCount = 5000;
17        private int currentUserCount;
18
19        public LoadTestFixture()
20        {
21            currentUserCount = GetUserCount("1 = 1");
22            using (PushDataToDatabase push = new PushDataToDatabase(expectedCount))
23                push.Execute();
24        }
25
26        public void AssertUpdatedAllRows()
27        {
28            Assert.Equal(expectedCount + currentUserCount, GetUserCount("testMsg is not null"));
29
30        }
31
32        private static int GetUserCount(string where)
33        {
34            return Use.Transaction<int>("test", delegate(IDbCommand command)
35            {
36                command.CommandText = "select count(*) from users where " + where;
37                return (int)command.ExecuteScalar();
38            });
39        }
40
41        [Fact]
42        public void CanUpdateAllUsersToUpperCase()
43        {
44            using (UpperCaseUserNames update = new UpperCaseUserNames())
45            {
46                update.RegisterLast(new UpdateUserNames());
47                update.Execute();
48            }
49            AssertUpdatedAllRows();
50        }
51
52        [Fact]
53        public void CanBatchUpdateAllUsersToUpperCase()
54        {
55            using (UpperCaseUserNames update = new UpperCaseUserNames())
56            {
57                update.RegisterLast(new BatchUpdateUserNames());
58                update.Execute();
59            }
60
61            AssertUpdatedAllRows();
62        }
63
64        [Fact]
65        public void BulkInsertUpdatedRows()
66        {
67            if(expectedCount != GetUserCount("1 = 1"))
68                return;//ignoring test
69
70            using (UpperCaseUserNames update = new UpperCaseUserNames())
71            {
72                update.RegisterLast(new BulkInsertUsers());
73                update.Execute();
74            }
75
76            AssertUpdatedAllRows();
77        }
78    }
79}