public void ShouldCreateParameterTest() { Mockery mockery; AdoNetDataSource dataSource; IConnectionFactory mockConnectionFactory; IDbConnection mockDbConnection; IDbCommand mockDbCommand; IDataParameter p; IDbDataParameter mockDbParameter; mockery = new Mockery(); mockConnectionFactory = mockery.NewMock<IConnectionFactory>(); mockDbConnection = mockery.NewMock<IDbConnection>(); mockDbCommand = mockery.NewMock<IDbCommand>(); mockDbParameter = mockery.NewMock<IDbDataParameter>(); Expect.Once.On(mockConnectionFactory).Method("GetConnection").Will(Return.Value(mockDbConnection)); Expect.Once.On(mockDbConnection).Method("CreateCommand").Will(Return.Value(mockDbCommand)); Expect.Once.On(mockDbConnection).Method("Dispose"); Expect.Once.On(mockDbCommand).Method("CreateParameter").Will(Return.Value(mockDbParameter)); Expect.Once.On(mockDbCommand).Method("Dispose"); Expect.Once.On(mockDbParameter).SetProperty("ParameterName").To("@bob"); Expect.Once.On(mockDbParameter).SetProperty("Size").To(1); Expect.Once.On(mockDbParameter).SetProperty("Value").To("test"); Expect.Once.On(mockDbParameter).SetProperty("Direction").To(ParameterDirection.Input); Expect.Once.On(mockDbParameter).SetProperty("DbType").To(DbType.String); Expect.Once.On(mockDbParameter).SetProperty("Precision").To((byte)2); Expect.Once.On(mockDbParameter).SetProperty("Scale").To((byte)3); //Expect.Once.On(mockDbParameter).SetProperty("IsNullable").To(true); Expect.Once.On(mockDbParameter).GetProperty("ParameterName").Will(Return.Value("@bob")); Expect.Once.On(mockDbParameter).GetProperty("Size").Will(Return.Value(1)); Expect.Once.On(mockDbParameter).GetProperty("Value").Will(Return.Value("test")); Expect.Once.On(mockDbParameter).GetProperty("Direction").Will(Return.Value(ParameterDirection.Input)); Expect.Once.On(mockDbParameter).GetProperty("DbType").Will(Return.Value(DbType.String)); Expect.Once.On(mockDbParameter).GetProperty("Precision").Will(Return.Value((byte)2)); Expect.Once.On(mockDbParameter).GetProperty("Scale").Will(Return.Value((byte)3)); //Expect.Once.On(mockDbParameter).GetProperty("IsNullable").Will(Return.Value(true)); dataSource = new AdoNetDataSource(MOCK_CONNECTION_STRING, mockConnectionFactory); p = dataSource.CreateParameter(null, ParameterDirection.Input, DbType.String, 1, 2, 3, true, "@bob", "test"); Assert.IsNotNull(p); Assert.AreEqual(ParameterDirection.Input, p.Direction); Assert.AreEqual("@bob", p.ParameterName); Assert.AreEqual("test", p.Value); Assert.AreEqual(1, ((IDbDataParameter)p).Size); Assert.AreEqual(DbType.String, p.DbType); Assert.AreEqual((byte)2, ((IDbDataParameter)p).Precision); Assert.AreEqual((byte)3, ((IDbDataParameter)p).Scale); //Assert.AreEqual(true, ((IDbDataParameter)p).IsNullable); mockery.VerifyAllExpectationsHaveBeenMet(); }
public void ShouldFailOnNullConnectionGetConnectionFromFactoryTest() { Mockery mockery; AdoNetDataSource dataSource; IConnectionFactory mockConnectionFactory; mockery = new Mockery(); mockConnectionFactory = mockery.NewMock<IConnectionFactory>(); Expect.Once.On(mockConnectionFactory).Method("GetConnection").Will(Return.Value(null)); dataSource = new AdoNetDataSource(MOCK_CONNECTION_STRING, mockConnectionFactory); dataSource.CreateParameter(null, ParameterDirection.Input, DbType.String, 1, 2, 3, true, "@bob", "test"); }