示例#1
0
        public void SelectMultipleTablesWithSingleRowWithSpecifiedIds()
        {
            //ARRANGE
            const string queryText = @"select * 
                                 from dbo.TestDbType 
                                 where id = @id1;
                                 
                                 select * 
                                 from dbo.TestDbType 
                                 where id = @id2;";
            //ACT
            var result = Query.Select <DataSet>(queryText, new { id1 = TestData.Item1.Id, id2 = TestData.Item2.Id });

            //ASSERT
            Assert.AreEqual(2, result.Tables.Count);
            Assert.AreEqual(1, result.Tables[0].Rows.Count);
            Assert.AreEqual(1, result.Tables[1].Rows.Count);

            var expected = new[] { TestData.Item1Dictionary, TestData.Item2Dictionary };

            var actual = new[]
            {
                DictionaryConverter.ConvertToDictionary(result.Tables[0].Rows[0]),
                DictionaryConverter.ConvertToDictionary(result.Tables[1].Rows[0])
            };

            DictionaryComparator.Compare(expected, actual);
        }
示例#2
0
        private void SelectMultipleRowWithSpecifiedIds <T>()
            where T : IEnumerable <Tuple <string, bool, int, TestDataItemToFill> >
        {
            //ARRANGE
            const string queryText = @"select NVarchar50, Bit, Int, *
                                 from dbo.TestDbType 
                                 where id = @id1 or id = @id2
                                 order by id asc";

            //ACT
            var result      = Query.Select <T>(queryText, new { id1 = TestData.Item1.Id, id2 = TestData.Item2.Id });
            var resultArray = result.ToArray();

            //ASSERT
            Assert.AreEqual(2, resultArray.Length);

            Assert.AreEqual(resultArray[0].Item1, TestData.Item1.NVarchar50);
            Assert.AreEqual(resultArray[0].Item2, TestData.Item1.Bit);
            Assert.AreEqual(resultArray[0].Item3, TestData.Item1.Int);

            var actualDictionary1 = DictionaryConverter.ConvertToDictionary(resultArray[0].Item4);

            DictionaryComparator.Compare(TestData.Item1Dictionary, actualDictionary1);

            Assert.AreEqual(resultArray[1].Item1, TestData.Item2.NVarchar50);
            Assert.AreEqual(resultArray[1].Item2, TestData.Item2.Bit);
            Assert.AreEqual(resultArray[1].Item3, TestData.Item2.Int);

            var actualDictionary2 = DictionaryConverter.ConvertToDictionary(resultArray[1].Item4);

            DictionaryComparator.Compare(TestData.Item2Dictionary, actualDictionary2);
        }
        private void SelectMultipleRowWithSpecifiedIds <T>()
            where T : IEnumerable <TestDataItemToFill>
        {
            //ARRANGE
            const string queryText = @"select * 
                                 from dbo.TestDbType 
                                 where id = @id1 or id = @id2
                                 order by id asc";

            //ACT
            var result      = Query.Select <T>(queryText, new { id1 = TestData.Item1.Id, id2 = TestData.Item2.Id });
            var resultArray = result.ToArray();

            //ASSERT
            Assert.IsInstanceOf <T>(result);
            Assert.AreEqual(2, resultArray.Length);

            var dictionaryResult = new[]
            {
                DictionaryConverter.ConvertToDictionary(resultArray[0]),
                DictionaryConverter.ConvertToDictionary(resultArray[1])
            };

            var expectedResult = new[] { TestData.Item1Dictionary, TestData.Item2Dictionary };

            DictionaryComparator.Compare(expectedResult, dictionaryResult);
        }
        public void SelectSingleNullRow()
        {
            //ARRANGE
            const string queryText = @"select * 
                                 from dbo.TestDbType 
                                 where id = @id";

            //ACT
            var result = Query.Select <TestDataItemToFill>(queryText, new { id = TestData.NullItem.Id });

            //ASSERT
            var dictionaryResult = DictionaryConverter.ConvertToDictionary(result);

            DictionaryComparator.Compare(TestData.NullItemDictionary, dictionaryResult);
        }
示例#5
0
        public void SelectSingleNullRow()
        {
            //ARRANGE
            const string queryText = @"select * 
                                 from dbo.TestDbType 
                                 where id = @id";

            //ACT
            var result = Query.Select <DataTable>(queryText, new { id = TestData.NullItem.Id });


            //ASSERT
            Assert.AreEqual(1, result.Rows.Count);
            var actual = DictionaryConverter.ConvertToDictionary(result.Rows[0]);

            DictionaryComparator.Compare(TestData.DbNullItemDictionary, actual);
        }
示例#6
0
        public void SelectSingleRowWithSpecifiedId()
        {
            //ARRANGE
            const string queryText = @"select NVarchar50, Bit, Int, *
                                 from dbo.TestDbType 
                                 where id = @id";
            //ACT
            var result = Query.Select <Tuple <string, bool, int, TestDataItemToFill> >(queryText, new { id = TestData.Item1.Id });

            //ASSERT
            Assert.AreEqual(result.Item1, TestData.Item1.NVarchar50);
            Assert.AreEqual(result.Item2, TestData.Item1.Bit);
            Assert.AreEqual(result.Item3, TestData.Item1.Int);

            var actualDictionary = DictionaryConverter.ConvertToDictionary(result.Item4);

            DictionaryComparator.Compare(TestData.Item1Dictionary, actualDictionary);
        }
示例#7
0
        public void SelectSingleRowWithSpecifiedId()
        {
            //ARRANGE
            const string queryText = @"select * 
                                 from dbo.TestDbType 
                                 where id = @id";

            //ACT
            var result = Query.Select <DataSet>(queryText, new { id = TestData.Item1.Id });


            //ASSERT
            Assert.AreEqual(1, result.Tables.Count);
            Assert.AreEqual(1, result.Tables[0].Rows.Count);

            var actual = DictionaryConverter.ConvertToDictionary(result.Tables[0].Rows[0]);

            DictionaryComparator.Compare(TestData.Item1Dictionary, actual);
        }
        public void SelectMultipleRowsOfType()
        {
            //ARRANGE
            const string queryText = @"select NVarchar50
                                 from dbo.TestDbType 
                                 where id = @id1 or id = @id2;

                                select *
                                from dbo.TestDbType 
                                where id = @id1 or id = @id2
                                order by id asc;

                                select *
                                from dbo.TestDbType 
                                where id = @id1

                                select NVarchar50 
                                from dbo.TestDbType
                                where id = @id1

                                select *
                                from dbo.TestDbType 
                                where id = @id1

                                select *
                                from dbo.TestDbType 
                                where id = @id1 or id = @id2
                                order by id asc

                                select *
                                from dbo.TestDbType 
                                where id = @id1 or id = @id2
                                order by id asc";

            //ACT
            var result = Query.Select <MultipleResultSet <string[], DataTable, Dictionary <string, object>, string, Tuple <TestDataItemToFill>,
                                                          dynamic[], TestDataItemToFill[]> >(queryText, new { id1 = TestData.Item1.Id, id2 = TestData.Item2.Id });

            //Assert Item 1
            var item1 = result.Item1;

            Assert.AreEqual(2, item1.Length);
            Assert.AreEqual(TestData.Item1.NVarchar50, item1[0]);
            Assert.AreEqual(TestData.Item2.NVarchar50, item1[1]);

            //Assert Item 2
            var item2 = result.Item2;

            var actualItem2 = new[]
            {
                DictionaryConverter.ConvertToDictionary(item2.Rows[0]),
                DictionaryConverter.ConvertToDictionary(item2.Rows[1]),
            };

            DictionaryComparator.Compare(new[] { TestData.Item1Dictionary, TestData.Item2Dictionary }, actualItem2);

            //Assert Item 3
            var item3 = result.Item3;

            DictionaryComparator.Compare(TestData.Item1Dictionary, item3);

            //Assert Item 4
            var item4 = result.Item4;

            Assert.AreEqual(TestData.Item1.NVarchar50, item4);

            //Assert Item 5
            var item5 = result.Item5;

            DictionaryComparator.Compare(TestData.Item1Dictionary, DictionaryConverter.ConvertToDictionary(item5.Item1));

            //Assert Item 6
            var item6 = result.Item6;

            var actualItem6 = new IDictionary <string, object>[]
            {
                (ExpandoObject)item6[0],
                (ExpandoObject)item6[1],
            };

            DictionaryComparator.Compare(new[] { TestData.Item1Dictionary, TestData.Item2Dictionary }, actualItem6);

            //Assert Item 7
            var item7 = result.Item7;

            var actualItem7 = new[]
            {
                DictionaryConverter.ConvertToDictionary(item7[0]),
                DictionaryConverter.ConvertToDictionary(item7[1])
            };

            DictionaryComparator.Compare(new[] { TestData.Item1Dictionary, TestData.Item2Dictionary }, actualItem7);
        }