Example #1
0
		public void CreateParameter_CreateParameterWithValue_CheckThatCorrectValueIsSet() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var parameter = dataSource.CreateParameter("myparameter", "myvalue");
			Assert.AreEqual("myparameter", parameter.ParameterName);
			Assert.AreEqual("myvalue", parameter.Value);
		}
Example #2
0
		public void CreateSPCommand_CreateCommandWithName_ReturnsCommandWithCorrectSpName() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var command = dataSource.CreateSPCommand("command");
			Assert.AreEqual(CommandType.StoredProcedure, command.DbCommand.CommandType);
			Assert.AreEqual("command", command.DbCommand.CommandText);
		}
Example #3
0
		public void CreateParameter_CreateParameter_CheckThatCorrectParameterIsCreated() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var parameter = dataSource.CreateParameter("myparameter", DbType.Guid);
			Assert.AreEqual("myparameter", parameter.ParameterName);
			Assert.AreEqual(DbType.Guid, parameter.DbType);
		}
Example #4
0
		public void CreateSPCommand_CreateSpCommandWithTransaction_ReturnsCommandWithCorrectTransaction() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var trans = A.Fake<ITransaction>();
			var command = dataSource.CreateSPCommand("command", trans);
			Assert.AreEqual(CommandType.StoredProcedure, command.DbCommand.CommandType);
			Assert.AreEqual("command", command.DbCommand.CommandText);
			Assert.AreEqual(trans.DbTransaction, command.DbCommand.Transaction);
		}
Example #5
0
		public void OpenConnection_CreateProviderWithConnectionAndOpenIt_ReturnsUnderlyingOpenedConnection() {
			var provider = A.Fake<IProvider>();
			var underlyingConnection = A.Fake<IDbConnection>();
			A.CallTo(() => provider.CreateConnection()).Returns(underlyingConnection);
			var dataSource = new DataSource(provider);
			var connection = dataSource.OpenConnection();
			A.CallTo(() => underlyingConnection.Open()).MustHaveHappened(Repeated.Exactly.Once);
			Assert.AreEqual(underlyingConnection, connection);
		}
Example #6
0
		public void CreateCommand_CreateCommand_CheckThatCorrectCommandIsCreated() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var transaction = A.Fake<ITransaction>();
			var parameter = A.Fake<IDataParameter>();

			var command = dataSource.CreateCommand("commandSting", transaction, CommandType.TableDirect, parameter);
			Assert.AreEqual("commandSting", command.DbCommand.CommandText);
			Assert.AreEqual(transaction.Connection, command.DbCommand.Connection);
			Assert.AreEqual(transaction.DbTransaction, command.DbCommand.Transaction);
			Assert.AreEqual(CommandType.TableDirect, command.DbCommand.CommandType);
		}
Example #7
0
		public void ExecuteReader_PassingNullCommand_ThrowsArgumentNullException() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			Assert.Throws<ArgumentNullException>(() => dataSource.ExecuteReader(null));
		}
Example #8
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 #9
0
		public void CreateSPCommand_CreatePlainCommand_ReturnsCommandWithTypeStoredProcedure() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var command = dataSource.CreateSPCommand();
			Assert.AreEqual(CommandType.StoredProcedure, command.DbCommand.CommandType);
		}
Example #10
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 #11
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 #12
0
		public void CreateInputParameter_PassingAnsiStringValue_ReturnsImputParameterWithCorrectValue() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			const string dummyString = "myValue";
			var parameter = dataSource.CreateInputParameter("myParamter", DbType.AnsiString, dummyString);
			Assert.AreEqual("myParamter", parameter.ParameterName);
			Assert.AreEqual(dummyString, parameter.Value);
			Assert.AreEqual(ParameterDirection.Input, parameter.Direction);
			Assert.AreEqual(DbType.AnsiString, parameter.DbType);
		}
Example #13
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);
		}
Example #14
0
		public void ExecuteDataSet_ExecuteCommand_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var dataSet = dataSource.ExecuteDataSet("command", CommandType.StoredProcedure);
			
			Assert.IsNotNull(dataSet);
		}
Example #15
0
		public void UpdateDataSet_PassingNullDataSet_ThrowsArgumentNullExeption() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var insertCommand = A.Fake<ICommand>();
			var updateCommand = A.Fake<ICommand>();
			var deleteCommand = A.Fake<ICommand>();

			Assert.Throws<ArgumentNullException>(() => dataSource.UpdateDataSet(null, insertCommand, updateCommand, deleteCommand));

		}
Example #16
0
		public void ExecuteScalar_ExecuteSp_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			var dbCommand = A.Fake<IDbCommand>();
			var dummyObject = A.Fake<MyDummyClass>();

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

			var result = dataSource.ExecuteScalar("command");
			
			Assert.AreEqual(dummyObject, result);
		}
Example #17
0
		public void ExecuteScalar_ExecuteCommandWithoutTransaction_TransactionCreatedAfterExecute() {
			var provider = A.Fake<IProvider>();
			var command = A.Fake<ICommand>();
			var dataSource = new DataSource(provider);
			command.Transaction = null;

			dataSource.ExecuteScalar(command);

			Assert.IsNotNull(command.Transaction);
		}
Example #18
0
		public void ExecuteDataSet_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();

			var result = dataSource.ExecuteDataSet("spname", parameters);

			A.CallTo(() => dbCommand.Parameters.Add(A<object>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(12));
			
			Assert.IsNotNull(result);
		}
Example #19
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 #20
0
		public void ExecuteNonQuery_ExecuteCommandWithParameters_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("command", CommandType.Text, parameters);

			A.CallTo(() => dbCommand.Parameters.Add(A<object>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(12));
			
		}
Example #21
0
		public void CreateInputParameter_PassingDateTimeMinValue_ReturnsImputParameterWithDbNullAsValue() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var parameter = dataSource.CreateInputParameter("myParamter", DateTime.MinValue);
			Assert.AreEqual("myParamter", parameter.ParameterName);
			Assert.AreEqual(DBNull.Value, parameter.Value);
			Assert.AreEqual(ParameterDirection.Input, parameter.Direction);
		}
Example #22
0
		public void UpdateDataSet_PassingNullTransaction_ThrowsArgumentNullExeption() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var insertCommand = A.Fake<ICommand>();
			var updateCommand = A.Fake<ICommand>();
			var deleteCommand = A.Fake<ICommand>();

			var dataset = new DataSet();
			Assert.Throws<ArgumentNullException>(() => dataSource.UpdateDataSet(dataset, insertCommand, updateCommand, deleteCommand, "myTable", null));

		}
Example #23
0
		public void CreateInputParameter_PassingDummyObjectNullValue_ReturnsImputParameterWithDbNullAsValue() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);
			
			MyDummyClass myDummyObject = null;
			var parameter = dataSource.CreateInputParameter("myParamter", DbType.AnsiString, myDummyObject);
			Assert.AreEqual("myParamter", parameter.ParameterName);
			Assert.AreEqual(DBNull.Value, parameter.Value);
			Assert.AreEqual(ParameterDirection.Input, parameter.Direction);
			Assert.AreEqual(DbType.AnsiString, parameter.DbType);
		}
Example #24
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 #25
0
		public void CreateStringInputParameter_PassingAnsiStringEmptyValueAndUseNullIfEmpty_ReturnsImputParameterWithDbNullValue() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			string dummyString = string.Empty;
			var parameter = dataSource.CreateStringInputParameter("myParamter", DbType.AnsiString, dummyString, true);
			Assert.AreEqual("myParamter", parameter.ParameterName);
			Assert.AreEqual(DBNull.Value, parameter.Value);
			Assert.AreEqual(ParameterDirection.Input, parameter.Direction);
			Assert.AreEqual(DbType.AnsiString, parameter.DbType);
		}
Example #26
0
		public void ExecuteDataSet_ExecuteSp_ReturnsDataset() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var dataSet = dataSource.ExecuteDataSet("command");
			
			Assert.IsNotNull(dataSet);
		}
Example #27
0
		public void CreateReturnParameter_PassingType_ReturnsOutputParameterWithCorrectType() {
			var provider = A.Fake<IProvider>();
			var dataSource = new DataSource(provider);

			var parameter = dataSource.CreateReturnParameter("myParamter", DbType.UInt32);
			Assert.AreEqual("myParamter", parameter.ParameterName);
			Assert.AreEqual(DbType.UInt32, parameter.DbType);
			Assert.AreEqual(ParameterDirection.ReturnValue, parameter.Direction);
		}
Example #28
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);
			
		}
Example #29
0
		public void CreateSPCommand_CreateSpCommandWithParameters_ReturnsCommandWithCorrectParameters() {
			var provider = A.Fake<IProvider>();
			var dbCommand = A.Fake<IDbCommand>();
			var parameterCollection = A.Fake<IDataParameterCollection>();
			
			A.CallTo(() => provider.CreateCommand()).Returns(dbCommand);
			A.CallTo(() => dbCommand.Parameters).Returns(parameterCollection);


			var dataSource = new DataSource(provider);
			var parameters = A.CollectionOfFake<IDataParameter>(12).ToArray();
			var command = dataSource.CreateSPCommand("command", parameters);

			A.CallTo(() => command.DbCommand.Parameters).Returns(parameterCollection);
			Assert.AreEqual(dbCommand, command.DbCommand);
			Assert.AreEqual(CommandType.StoredProcedure, command.DbCommand.CommandType);
			Assert.AreEqual("command", command.DbCommand.CommandText);
			A.CallTo(() => parameterCollection.Add(A<object>.Ignored)).MustHaveHappened(Repeated.Exactly.Times(12));
		}
Example #30
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);
		}