예제 #1
0
        public void ReadSingleRowWithInParameters()
        {
            var dataContainer = new TestDataContainer();
            var dataReader    = MockDatabaseFactory.CreateDbDataReader(dataContainer);
            var query         = new SQLQuery(sqlInString, SQLQueryType.DataReader)
            {
                ProcessRow = dataContainer.ProcessRow
            };

            query.Parameters.Add("param1", "value1");
            query.Parameters.Add("param2", "value2");
            query.Parameters.Add("param3", 333);
            var inList = new List <object>();

            inList.AddRange(new string[] { "val1", "val2", "val3", "val4" });
            query.InParameters.Add("inParam", inList);
            queryHelper.RunQuery(query);

            dataContainer.AssertData();
            VerifyLogging(sqlInStringAfterProcessing);

            Assert.AreEqual(sqlInStringAfterProcessing, MockDatabaseFactory.DbCommand.Object.CommandText);
            MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1));
            MockDatabaseFactory.Parameters.Verify(p => p.Add(It.IsAny <DbParameter>()), Times.Exactly(7));
            MockDatabaseFactory.DbCommand.Protected()
            .Verify <Task <DbDataReader> >("ExecuteDbDataReaderAsync", Times.Exactly(1), It.IsAny <CommandBehavior>(), It.IsAny <System.Threading.CancellationToken>());
            Assert.AreEqual(1, query.RowCount);
            dataReader.Verify(dr => dr.Read(), Times.Exactly(2));
        }
예제 #2
0
        public void ReadSingleRowWithParametersAsync()
        {
            var dataContainer = new TestDataContainer();
            var dataReader    = MockDatabaseFactory.CreateDbDataReader(dataContainer);
            var query         = new SQLQuery(sqlString, SQLQueryType.DataReader)
            {
                ProcessRow = dataContainer.ProcessRow
            };

            query.Parameters.Add("param1", "value1");
            query.Parameters.Add("param2", "value2");
            query.Parameters.Add("param3", 333);
            var task = queryHelper.RunQueryAsync(query);

            task.Wait();

            dataContainer.AssertData();
            VerifyLogging(sqlString);
            Assert.AreEqual(sqlString, MockDatabaseFactory.DbCommand.Object.CommandText);
            MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1));
            MockDatabaseFactory.Parameters.Verify(p => p.Add(It.IsAny <DbParameter>()), Times.Exactly(3));
            MockDatabaseFactory.DbCommand.Protected()
            .Verify <Task <DbDataReader> >("ExecuteDbDataReaderAsync", Times.Exactly(1), It.IsAny <CommandBehavior>(), It.IsAny <System.Threading.CancellationToken>());
            MockDatabaseFactory.DbCommand.Protected()
            .VerifyGet <DbParameterCollection>("DbParameterCollection", Times.Exactly(3));
            Assert.AreEqual(1, query.RowCount);
            dataReader.Verify(dr => dr.Read(), Times.Exactly(2));
        }
예제 #3
0
        public static Mock <MoqDataReader> CreateDbDataReader(TestDataContainer dataContainer)
        {
            var dataReader = new Mock <MoqDataReader>(dataContainer.dataRow);

            dataReader.CallBase = true;
            dataReader.Setup(dr => dr.Close());
            MockDatabaseFactory.DbCommand = MockDatabaseFactory.CreateDbCommand(dataReader.Object);
            return(dataReader);
        }
예제 #4
0
        public void ReadSingleRowNoParameters()
        {
            var dataContainer = new TestDataContainer();
            var dataReader    = MockDatabaseFactory.CreateDbDataReader(dataContainer);
            var query         = new SQLQuery(sqlString, SQLQueryType.DataReader)
            {
                ProcessRow = dataContainer.ProcessRow
            };

            queryHelper.RunQuery(query);

            dataContainer.AssertData();
            VerifyLogging(sqlString);
            MockDatabaseFactory.DbConnection.VerifySet(dbc => dbc.ConnectionString = connectionString, Times.Exactly(1));
            MockDatabaseFactory.Parameters.Verify(p => p.Add(It.IsAny <DbParameter>()), Times.Exactly(0));
            MockDatabaseFactory.DbCommand.Protected()
            .Verify <Task <DbDataReader> >("ExecuteDbDataReaderAsync", Times.Exactly(1), It.IsAny <CommandBehavior>(), It.IsAny <System.Threading.CancellationToken>());
            Assert.AreEqual(1, query.RowCount);
            dataReader.Verify(dr => dr.Read(), Times.Exactly(2));
        }