public void FetchExecutesAndReturnsResults() { var mockSqlDialect = new Mock <ISqlDialect>(); var mockReader = new Mock <IDataReader>(); mockReader.Setup(x => x.Read()).Returns(new Queue <bool>(new[] { true, false }).Dequeue); mockReader.As <IDisposable>().Setup(x => x.Dispose()); var mockCommand = new Mock <IDbCommand>(); mockCommand.Setup(x => x.ExecuteReader()).Returns(mockReader.Object); var mockConnection = new Mock <IDbConnection>(); mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object); var mockDbDriver = new Mock <IDbDriver>(); mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object); var session = new ReadOnlySession( ConnectionScope.PerTransaction, mockSqlDialect.Object, mockDbDriver.Object); var customers = session.Fetch <Customer>(new SqlQuery("")); Assert.Equal(1, customers.Count); mockReader.VerifyAll(); mockCommand.VerifyAll(); mockConnection.VerifyAll(); mockSqlDialect.VerifyAll(); }
public void FetchThrowsArgumentNullExceptionForNullSqlQuery() { var session = new ReadOnlySession( ConnectionScope.PerTransaction, new Mock <ISqlDialect>().Object, new Mock <IDbDriver>().Object); var exception = Assert.Throws <ArgumentNullException>( () => session.Fetch <Customer>(null)); Assert.Equal("sqlQuery", exception.ParamName); }
public void FetchThrowsObjectDisposedExceptionIfDisposed() { var session = new ReadOnlySession( ConnectionScope.PerTransaction, new Mock <ISqlDialect>().Object, new Mock <IDbDriver>().Object); using (session) { } Assert.Throws <ObjectDisposedException>( () => session.Fetch <Customer>(null)); }
public void FetchExecutesAndReturnsResults() { var mockSqlDialect = new Mock<ISqlDialect>(); var mockReader = new Mock<IDataReader>(); mockReader.Setup(x => x.Read()).Returns(new Queue<bool>(new[] { true, false }).Dequeue); mockReader.As<IDisposable>().Setup(x => x.Dispose()); var mockCommand = new Mock<IDbCommand>(); mockCommand.Setup(x => x.ExecuteReader()).Returns(mockReader.Object); var mockConnection = new Mock<IDbConnection>(); mockConnection.Setup(x => x.CreateCommand()).Returns(mockCommand.Object); var mockDbDriver = new Mock<IDbDriver>(); mockDbDriver.Setup(x => x.CreateConnection()).Returns(mockConnection.Object); var session = new ReadOnlySession( ConnectionScope.PerTransaction, mockSqlDialect.Object, mockDbDriver.Object); var customers = session.Fetch<Customer>(new SqlQuery("")); Assert.Equal(1, customers.Count); mockReader.VerifyAll(); mockCommand.VerifyAll(); mockConnection.VerifyAll(); mockSqlDialect.VerifyAll(); }
public void FetchThrowsObjectDisposedExceptionIfDisposed() { var session = new ReadOnlySession( ConnectionScope.PerTransaction, new Mock<ISqlDialect>().Object, new Mock<IDbDriver>().Object); using (session) { } Assert.Throws<ObjectDisposedException>( () => session.Fetch<Customer>(null)); }
public void FetchThrowsArgumentNullExceptionForNullSqlQuery() { var session = new ReadOnlySession( ConnectionScope.PerTransaction, new Mock<ISqlDialect>().Object, new Mock<IDbDriver>().Object); var exception = Assert.Throws<ArgumentNullException>( () => session.Fetch<Customer>(null)); Assert.Equal("sqlQuery", exception.ParamName); }