Пример #1
0
		public void ShouldExecuteReaderCloseConnectionSprocWithParametersTest()
		{
			IAdoNetYieldingFascade adoNetYieldingFascade;
			MockFactory mockFactory;
			DbConnection mockDbConnection;
			DbCommand mockDbCommand;
			DbParameterCollection mockDbParameterCollection;
			DbParameter[] mockDbParameters;
			DbParameter mockDbParameter0;
			DbParameter mockDbParameter1;
			DbDataReader mockDbDataReader;
			IReflectionFascade mockReflectionFascade;

			DbDataReader dbDataReader;

			CommandBehavior _unusedCommandBehavior = CommandBehavior.Default;
			DbParameter _unusedDbParameter = null;

			mockFactory = new MockFactory();
			mockDbConnection = mockFactory.CreateInstance<DbConnection>();
			mockDbCommand = mockFactory.CreateInstance<DbCommand>();
			mockDbParameterCollection = mockFactory.CreateInstance<DbParameterCollection>();
			mockDbParameter0 = mockFactory.CreateInstance<DbParameter>();
			mockDbParameter1 = mockFactory.CreateInstance<DbParameter>();
			mockDbParameters = new DbParameter[] { mockDbParameter0, mockDbParameter1 };
			mockDbDataReader = mockFactory.CreateInstance<DbDataReader>();
			mockReflectionFascade = mockFactory.CreateInstance<IReflectionFascade>();

			Expect.On(mockDbConnection).One.Method(x => x.CreateCommand()).Will(Return.Value(mockDbCommand));
			Expect.On(mockDbCommand).Exactly(2).GetProperty(x => x.Parameters).Will(Return.Value(mockDbParameterCollection));
			Expect.On(mockDbCommand).One.Method(x => x.Dispose());
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandType).To(CommandType.StoredProcedure);
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandText).To("blah blah blah");
			Expect.On(mockDbCommand).One.SetProperty(x => x.Transaction).To(null);
			Expect.On(mockDbCommand).One.Method(x => x.ExecuteReader(_unusedCommandBehavior)).With(CommandBehavior.CloseConnection).Will(Return.Value(mockDbDataReader));
			Expect.On(mockDbParameter0).One.GetProperty(x => x.Value).Will(Return.Value(1));
			Expect.On(mockDbParameter1).One.GetProperty(x => x.Value).Will(Return.Value(null));
			Expect.On(mockDbParameter1).One.SetProperty(x => x.Value).To(DBNull.Value);
			Expect.On(mockDbParameterCollection).One.Method(x => x.Add(_unusedDbParameter)).With(mockDbParameter0).Will(Return.Value(0));
			Expect.On(mockDbParameterCollection).One.Method(x => x.Add(_unusedDbParameter)).With(mockDbParameter1).Will(Return.Value(0));
			Expect.On(mockDbDataReader).One.Method(x => x.Dispose());

			adoNetYieldingFascade = new AdoNetYieldingFascade(mockReflectionFascade);

			dbDataReader = adoNetYieldingFascade.ExecuteReader(mockDbConnection, null, CommandType.StoredProcedure, "blah blah blah", mockDbParameters, CommandBehavior.CloseConnection, null, false);

			Assert.IsNotNull(dbDataReader);

			dbDataReader.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
Пример #2
0
		public void ShouldExecuteReaderCloseConnectionTextNoParametersTest()
		{
			IAdoNetYieldingFascade adoNetYieldingFascade;
			MockFactory mockFactory;
			DbConnection mockDbConnection;
			DbCommand mockDbCommand;
			DbDataReader mockDbDataReader;
			IReflectionFascade mockReflectionFascade;

			DbDataReader dbDataReader;

			CommandBehavior _unusedCommandBehavior = CommandBehavior.Default;

			mockFactory = new MockFactory();
			mockDbConnection = mockFactory.CreateInstance<DbConnection>();
			mockDbCommand = mockFactory.CreateInstance<DbCommand>();
			mockDbDataReader = mockFactory.CreateInstance<DbDataReader>();
			mockReflectionFascade = mockFactory.CreateInstance<IReflectionFascade>();

			Expect.On(mockDbConnection).One.Method(x => x.CreateCommand()).Will(Return.Value(mockDbCommand));
			Expect.On(mockDbCommand).One.Method(x => x.Dispose());
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandType).To(CommandType.Text);
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandText).To("blah blah blah");
			Expect.On(mockDbCommand).One.SetProperty(x => x.Transaction).To(null);
			Expect.On(mockDbCommand).One.Method(x => x.ExecuteReader(_unusedCommandBehavior)).With(CommandBehavior.CloseConnection).Will(Return.Value(mockDbDataReader));
			Expect.On(mockDbDataReader).One.Method(x => x.Dispose());
			Expect.On(mockDbCommand).One.SetProperty(x => x.CommandTimeout).To(15);
			Expect.On(mockDbCommand).One.Method(x => x.Prepare());

			adoNetYieldingFascade = new AdoNetYieldingFascade(mockReflectionFascade);

			dbDataReader = adoNetYieldingFascade.ExecuteReader(mockDbConnection, null, CommandType.Text, "blah blah blah", null, CommandBehavior.CloseConnection, 15, true);

			Assert.IsNotNull(dbDataReader);

			dbDataReader.Dispose();

			mockFactory.VerifyAllExpectationsHaveBeenMet();
		}
Пример #3
0
		public void ShouldFailOnNullConnectionStaticExecuteReaderTest()
		{
			IAdoNetYieldingFascade adoNetYieldingFascade;
			MockFactory mockFactory;
			IReflectionFascade mockReflectionFascade;

			mockFactory = new MockFactory();
			mockReflectionFascade = mockFactory.CreateInstance<IReflectionFascade>();

			adoNetYieldingFascade = new AdoNetYieldingFascade(mockReflectionFascade);

			adoNetYieldingFascade.ExecuteReader(null, null, CommandType.StoredProcedure, null, null, CommandBehavior.CloseConnection, null, false);
		}