Example #1
0
		public void ExecuteReader_ExecuteCommandWithoutTransaction_TransactionCreatedAfterExecute() {
			var provider = A.Fake<IProvider>();
			var command = A.Fake<ICommand>();
			var conn = A.Fake<IDbConnection>();
			var dataSource = new DataSource(provider);
			command.DbCommand.Connection = null;

			A.CallTo(() => provider.CreateConnection()).Returns(conn);

			dataSource.ExecuteReader(command);

			Assert.AreEqual(conn, command.DbCommand.Connection);
			A.CallTo(() => conn.Open()).MustHaveHappened(Repeated.Exactly.Once);
		}
Example #2
0
		public void ExecuteReader_PassingNullCommand_ThrowsArgumentNullException() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			Assert.Throws<ArgumentNullException>(() => dataSource.ExecuteReader(null));
		}
Example #3
0
		public void ExecuteReader_Passingnull() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var trans = A.Fake<ITransaction>();

			dataSource.ExecuteReader(null, trans, CommandBehavior.KeyInfo);
		}
Example #4
0
		public void ExecuteReader_ExecuteTextCommandPassingTransaction_TransactionSetOnCommand() {
			var provider = A.Fake<IProvider>();
			var dbCommand = A.Fake<IDbCommand>();
			var dataSource = new DataSource(provider);
			var trans = A.Fake<ITransaction>();

			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);

			dataSource.ExecuteReader("command", CommandType.Text, trans, CommandBehavior.KeyInfo);
			
			Assert.AreEqual("command", dbCommand.CommandText);
			Assert.AreEqual(trans.DbTransaction, dbCommand.Transaction);
		}
Example #5
0
		public void ExecuteReader_ExecuteCommandWithTransaction_TransactionNotCommited() {
			var provider = A.Fake<IProvider>();
			var command = A.Fake<ICommand>();
			var dataSource = new DataSource(provider);
			var trans = A.Fake<ITransaction>();

			command.Transaction = trans;

			dataSource.ExecuteReader(command);
			
			A.CallTo(() => trans.Commit()).MustNotHaveHappened();
		}
Example #6
0
		public void ExecuteReader_ExecuteSp_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var dbCommand = A.Fake<IDbCommand>();
			var dummyObject = A.Fake<IDataReader>();

			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);
			A.CallTo(() => dbCommand.ExecuteReader(CommandBehavior.KeyInfo)).Returns(dummyObject);

			var result = dataSource.ExecuteReader("command", CommandBehavior.KeyInfo);
			
			Assert.AreEqual(dummyObject, result);
			A.CallTo(() => dbCommand.ExecuteReader(CommandBehavior.KeyInfo)).MustHaveHappened(Repeated.Exactly.Once);
		}
Example #7
0
		public void ExecuteReader_ExecuteSpWithParameters_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataAdapter = A.Fake<IDbDataAdapter>();
			var dataSource = new DataSource(provider);
			var dbCommand = A.Fake<IDbCommand>();

			A.CallTo(() => provider.CreateDataAdapter()).Returns(dataAdapter);
			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);

			var parameters = A.CollectionOfFake<IDataParameter>(12).ToArray();

			dataSource.ExecuteReader("spname", CommandBehavior.Default, parameters);

			A.CallTo(() => dbCommand.Parameters.Add(A<object>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(12));
			A.CallTo(() => dbCommand.ExecuteReader(CommandBehavior.Default)).MustHaveHappened(Repeated.Exactly.Once);
			
		}