Example #1
0
		public void ExecuteNonQuery_PassingNullCommand_ThrowsArgumentNullException() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			Assert.Throws<ArgumentNullException>(() => dataSource.ExecuteNonQuery((ICommand)null));
		}
Example #2
0
		public void ExecuteNonQuery_ExecuteCommandWithoutTransaction_TransactionCreatedAfterExecute() {
			var provider = A.Fake<IProvider>();
			var command = A.Fake<ICommand>();
			var dataSource = new DataSource(provider);
			command.Transaction = null;

			dataSource.ExecuteNonQuery(command);

			Assert.IsNotNull(command.Transaction);
		}
Example #3
0
		public void ExecuteNonQuery_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.ExecuteNonQuery("spname", parameters);

			A.CallTo(() => dbCommand.Parameters.Add(A<object>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(12));
			
		}
Example #4
0
		public void ExecuteNonQuery_ExecuteSp_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var dbCommand = A.Fake<IDbCommand>();
			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);
			A.CallTo(() => dbCommand.ExecuteNonQuery()).Returns(242);

			var result = dataSource.ExecuteNonQuery("command");
			
			Assert.AreEqual(242, result);
		}
Example #5
0
		public void ExecuteNonQuery_ExecuteCommand_ReturnsInt() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var dbCommand = A.Fake<IDbCommand>();
			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);
			A.CallTo(() => dbCommand.ExecuteNonQuery()).Returns(12);

			var result = dataSource.ExecuteNonQuery("command", CommandType.StoredProcedure);
			
			Assert.AreEqual(12, result);
		}