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(It.IsAny <CommandBehavior>())).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(new MockDbConnectionWrapper(mockConnection.Object)); var session = new ReadOnlySession( ConnectionScope.PerTransaction, mockSqlDialect.Object, mockDbDriver.Object); var customers = session.FetchAsync <Customer>(new SqlQuery("")).Result; 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.FetchAsync <Customer>(null).Result); 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.FetchAsync <Customer>(null).Result); }