コード例 #1
0
        public void TestMapperQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    },
                    new Dictionary <string, object>
                    {
                        { "Id", 2 },
                        { "Name", "Test 2" }
                    }
                }
            };

            var result = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToList();

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

            var simpleDto = result.First();

            // ReSharper restore PossibleMultipleEnumeration

            Assert.AreEqual(1, simpleDto.Id);
            Assert.AreEqual("Test", simpleDto.Name);
        }
コード例 #2
0
        public void TestPageQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", (long)6 },
                        { "Name", "Test" }
                    },
                    new Dictionary <string, object>
                    {
                        { "Id", 2 },
                        { "Name", "Test 2" }
                    }
                }
            };

            var pagedList = queryRunner.Execute <SimpleDto>(new QueryPageSpecification(page: 1, itemsPerPages: 2));

            Assert.IsNotNull(pagedList);
            Assert.AreEqual(2, pagedList.Result.Count());
            Assert.AreEqual(6, pagedList.TotalItems);
            Assert.AreEqual(3, pagedList.TotalPages);
        }
コード例 #3
0
        public void TestFirstOrDefaultQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    },
                    new Dictionary <string, object>
                    {
                        { "Id", 2 },
                        { "Name", "Test 2" }
                    }
                }
            };

            var singleDto = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToFirstOrDefault();

            Assert.IsNotNull(singleDto);
            Assert.AreEqual(1, singleDto.Id);
            Assert.AreEqual("Test", singleDto.Name);
        }
コード例 #4
0
        public void TestParametersInQuery()
        {
            var queryRunner = new MockQueryRunner
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    }
                }
            };

            queryRunner.ExecuteScalar <int>(new QueryWithParameters(1, "Test"));

            Assert.IsNotNull(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "id"));
            Assert.IsNotNull(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "name"));


            // ReSharper disable PossibleNullReferenceException
            var id   = Convert.ToInt32(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "id").Value);
            var name = Convert.ToString(queryRunner.Parameters.SingleOrDefault(p => p.ParameterName == "name").Value);

            // ReSharper restore PossibleNullReferenceException

            Assert.AreEqual(1, id);
            Assert.AreEqual("Test", name);
        }
コード例 #5
0
        public void TestFirstOrDefaultEmptyQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >()
            };

            var singleDto = queryRunner.Execute <SimpleDto>(new QuerySimple()).ToFirstOrDefault();

            Assert.IsNull(singleDto);
        }
コード例 #6
0
        public void TestScalarQuery()
        {
            var queryRunner = new MockQueryRunner
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    }
                }
            };

            var id = queryRunner.ExecuteScalar <int>(new QuerySimple());

            Assert.AreEqual(1, id);
        }
コード例 #7
0
        public void TestPageFailureCountQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", "Execute scalar to return count, is not numeric" },
                        { "Name", "Test" }
                    },
                    new Dictionary <string, object>
                    {
                        { "Id", "Other" },
                        { "Name", "Test 2" }
                    }
                }
            };

            queryRunner.Execute <SimpleDto>(new QueryPageSpecification(page: 1, itemsPerPages: 2));
        }
コード例 #8
0
        public void TestSingleMapperFailureWithMorethanOneElementQuery()
        {
            var queryRunner = new MockQueryRunner(new QueryMapper())
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    },
                    new Dictionary <string, object>
                    {
                        { "Id", 2 },
                        { "Name", "Test 2" }
                    }
                }
            };

            queryRunner.Execute <SimpleDto>(new QuerySimple()).ToSingle();
        }
コード例 #9
0
        public void TestDataReaderQuery()
        {
            var queryRunner = new MockQueryRunner
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    }
                }
            };

            var dr = queryRunner.ExecuteReader(new QuerySimple());

            Assert.IsNotNull(dr);
            Assert.IsTrue(dr.Read());

            Assert.AreEqual(1, Convert.ToInt32(dr["Id"]));
            Assert.AreEqual("Test", Convert.ToString(dr["Name"]));
        }
コード例 #10
0
        public void TestDataTableQuery()
        {
            var queryRunner = new MockQueryRunner
            {
                ReturnValues = new List <IDictionary <string, object> >
                {
                    new Dictionary <string, object>
                    {
                        { "Id", 1 },
                        { "Name", "Test" }
                    }
                }
            };

            var dt = queryRunner.ExecuteDataTable(new QuerySimple());

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

            Assert.AreEqual(1, dt.Rows.Count);
            Assert.AreEqual(1, Convert.ToInt32(dt.Rows[0]["Id"]));
            Assert.AreEqual("Test", Convert.ToString(dt.Rows[0]["Name"]));
        }