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

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

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

            Assert.IsNotNull(user);
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 6
0
 public void TestIntegrationSingleResultFailManyResultMapperQuery()
 {
     Assert.ThrowsException <InvalidOperationException>(() =>
     {
         var queryRunner = QueryRunner.CreateHelper(dataAccessSettings);
         queryRunner.Execute <SimpleDto>(new QueryUsers()).ToSingle();
     });
 }
Exemplo 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));
        }
Exemplo 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);
            }
        }
Exemplo 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"]));
        }
Exemplo 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"]));
            }
        }
Exemplo 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"]));
            }
        }
Exemplo 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);
            }
        }
Exemplo 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);
            }
        }
Exemplo 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());
        }
Exemplo 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));
        }
Exemplo 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));
        }