Esempio n. 1
0
        public void TestIntegrationScalarQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper");
            var id          = queryRunner.ExecuteScalar <int>(new QueryUsers());

            Assert.AreEqual(1, id);
        }
Esempio n. 2
0
        public void TestIntegrationScalarQuery()
        {
            var queryRunner = QueryRunner.CreateHelper(dataAccessSettings);
            var id          = queryRunner.ExecuteScalar <int>(new QueryUsers());

            Assert.AreEqual(1, id);
        }
Esempio n. 3
0
        public void TestIntegrationSingleResultMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper(dataAccessSettings);
            var user        = queryRunner.Execute <SimpleDto>(new QueryUsers(1)).ToSingle();

            Assert.IsNotNull(user);
        }
Esempio n. 4
0
        public void TestIntegrationFirstOrDefaultWithoutResultMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());
            var user        = queryRunner.Execute <SimpleDto>(new QueryUsers(99)).ToFirstOrDefault();

            Assert.IsNull(user);
        }
Esempio n. 5
0
        public void TestIntegrationSingleResultMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());
            var user        = queryRunner.Execute <SimpleDto>(new QueryUsers(1)).ToSingle();

            Assert.IsNotNull(user);
        }
Esempio n. 6
0
 public void TestIntegrationSingleResultFailManyResultMapperQuery()
 {
     Assert.ThrowsException <InvalidOperationException>(() =>
     {
         var queryRunner = QueryRunner.CreateHelper(dataAccessSettings);
         queryRunner.Execute <SimpleDto>(new QueryUsers()).ToSingle();
     });
 }
Esempio n. 7
0
        public void TestIntegrationFirstOrDefaultWithResultMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());
            var user        = queryRunner.Execute <SimpleDto>(new QueryUsers()).ToFirstOrDefault();

            Assert.IsNotNull(user);

            Assert.AreEqual(1, user.Id);
            Assert.AreEqual("User 1", user.Name);
        }
        public void TestDependencyInjectionCreateHelper()
        {
            var container = new UnityContainer();

            container.RegisterType <IQueryRunner>(new InjectionFactory(c => QueryRunner.CreateHelper("MockAdoHelper")));

            var mockAdo = container.Resolve <IQueryRunner>();

            Assert.IsInstanceOfType(mockAdo, typeof(MockQueryRunner));
        }
Esempio n. 9
0
        public void TestIntegrationWhithoutGlobalCacheResultOneToManyMapperQuery()
        {
            using (var queryMapper = new QueryMapper())
            {
                var queryRunner = QueryRunner.CreateHelper(dataAccessSettings, queryMapper);

                var user = queryRunner.Execute <NameValue>(new QueryOneToManyMapObject(1)).ToFirstOrDefault();

                Assert.AreEqual("123456", user.Phones.FirstOrDefault(p => p.Id == 1).Name);
                Assert.AreEqual("*****@*****.**", user.Emails.FirstOrDefault(e => e.Id == 1).Name);
            }
        }
Esempio n. 10
0
        public void TestIntegrationDataTableQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper");
            var dt          = queryRunner.ExecuteDataTable(new QueryUsers());

            Assert.IsNotNull(dt);
            Assert.IsNotNull(dt.Rows);

            Assert.AreEqual(2, dt.Rows.Count);
            Assert.AreEqual(1, Convert.ToInt32(dt.Rows[0]["Id"]));
            Assert.AreEqual("User 1", Convert.ToString(dt.Rows[0]["Name"]));
        }
Esempio n. 11
0
        public void TestIntegrationDataReaderQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper");

            using (var dr = queryRunner.ExecuteReader(new QueryUsers()))
            {
                Assert.IsNotNull(dr);
                Assert.IsTrue(dr.Read());

                Assert.AreEqual(1, Convert.ToInt32(dr["Id"]));
                Assert.AreEqual("User 1", Convert.ToString(dr["Name"]));
            }
        }
Esempio n. 12
0
        public void TestIntegrationDataReaderQuery()
        {
            var queryRunner = QueryRunner.CreateHelper(dataAccessSettings);

            using (var dr = queryRunner.ExecuteReader(new QueryUsers()))
            {
                Assert.IsNotNull(dr);
                Assert.IsTrue(dr.Read());

                Assert.AreEqual(1, Convert.ToInt32(dr["Id"]));
                Assert.AreEqual("Diana Hendrix", Convert.ToString(dr["Name"]));
            }
        }
Esempio n. 13
0
        public void TestIntegrationFirstOrDefaultWithResultMapperQuery()
        {
            using (var queryMapper = new QueryMapper())
            {
                var queryRunner = QueryRunner.CreateHelper(dataAccessSettings, queryMapper);
                var user        = queryRunner.Execute(new QueryUsers()).ToFirstOrDefault();

                Assert.IsNotNull(user);

                Assert.AreEqual(1, user.Id);
                Assert.AreEqual("Diana Hendrix", user.Name);
            }
        }
Esempio n. 14
0
        public void TestIntegrationWhithoutExecuteCacheResultMapperQuery()
        {
            QueryMapper.RemoveCacheAfterExecuteQuery = false;

            using (var queryMapper = new QueryMapper())
            {
                var queryRunner = QueryRunner.CreateHelper(dataAccessSettings, queryMapper);

                var user  = queryRunner.Execute(new QueryUsers(1), keepCache: false).ToSingle();
                var phone = queryRunner.Execute(new QueryPhone(1), keepCache: false).ToSingle();

                Assert.AreEqual(1, phone.Id);
                Assert.AreNotEqual(user.Name, phone.Name);
            }
        }
Esempio n. 15
0
        public void TestIntegrationOneToManyMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());
            var users       = queryRunner.Execute <SimpleDto>(new QueryOneToMany()).ToList();

            Assert.IsNotNull(users);
            // ReSharper disable PossibleMultipleEnumeration
            Assert.AreEqual(2, users.Count());

            var user = users.First();

            // ReSharper restore PossibleMultipleEnumeration

            Assert.IsNotNull(user.Phones);
            Assert.AreEqual(2, user.Phones.Count());
        }
Esempio n. 16
0
        public void TestIntegrationPerformanceOneToManyMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());
            var iterations  = 50000;

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < iterations; i++)
            {
                var users = queryRunner.Execute <SimpleDto>(new QueryOneToMany()).ToList();

                Assert.IsNotNull(users);
                // ReSharper disable PossibleMultipleEnumeration
                Assert.AreEqual(2, users.Count());

                var user = users.First();
                // ReSharper restore PossibleMultipleEnumeration

                Assert.IsNotNull(user.Phones);
                Assert.AreEqual(2, user.Phones.Count());
            }

            Trace.WriteLine(string.Format("Mapped {0} objects in {1} ms.", iterations, stopwatch.ElapsedMilliseconds));
        }
Esempio n. 17
0
        public void TestIntegrationSingleResultFailManyResultMapperQuery()
        {
            var queryRunner = QueryRunner.CreateHelper("SqlAdoHelper", new QueryMapper());

            queryRunner.Execute <SimpleDto>(new QueryUsers()).ToSingle();
        }
        public void TestCreateHelper()
        {
            var mockAdo = QueryRunner.CreateHelper("MockAdoHelper");

            Assert.IsInstanceOfType(mockAdo, typeof(MockQueryRunner));
        }