public void CountAllWithTransactionInitiated() { var provider = new IProvider(); var command = new ICommand(); var schema = new TypeTable(typeof(Customer)); var transaction = new Mock<ITransaction>(); provider.Setup(p => p.GetSchema(typeof(Customer))).Returns(schema); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>()).Returns(command.Object); provider.CommandExecutor.Setup(c => c.InitiateTransaction()).Returns(transaction.Object); provider.CommandExecutor.Setup(c => c.ExecuteCount(command.Object, transaction.Object)).Returns(10); var target = new DataSession(provider.Object); target.BeginTransaction(); var result = target.Count<Customer>(); target.CommitTransaction(); Assert.IsTrue(result == 10); }
public void CountAll() { var provider = new IProvider(); var command = new ICommand(); var schema = new TypeTable(typeof(Customer)); provider.Setup(p => p.GetSchema(typeof(Customer))).Returns(schema); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>()).Returns(command.Object); provider.CommandExecutor.Setup(c => c.ExecuteCount(command.Object)).Returns(10); var target = new DataSession(provider.Object); var result = target.Count<Customer>(); Assert.IsTrue(result == 10); }
public void CountUsingExpressionThrowsArgumentNullException() { var provider = new IProvider(); var command = new ICommand(); var schema = new TypeTable(typeof(Customer)); Expression expression = null; provider.Setup(p => p.GetSchema(typeof(Customer))).Returns(schema); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>(expression)).Returns(command.Object); provider.CommandExecutor.Setup(c => c.ExecuteCount(command.Object)).Returns(10); try { var target = new DataSession(provider.Object); target.Count<Customer>(expression); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentNullException); } }
public void CountUsingExpressionThrowsUnableToCreateCommandException() { Expression<Func<Customer, bool>> expression = e => e.ID < 4; var provider = new IProvider(); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>(expression)).Returns(default(Data.ICommand)); try { var target = new DataSession(provider.Object); target.Count<Customer>(expression as Expression); } catch (Exception ex) { Assert.IsTrue(ex is UnableToCreateCommandException); } }
public void CountUsingLambda() { var provider = new IProvider(); var command = new ICommand(); var schema = new TypeTable(typeof(Customer)); Expression<Func<Customer, bool>> expression = x => x.ID < 10; provider.Setup(p => p.GetSchema(typeof(Customer))).Returns(schema); provider.CommandBuilder.Setup(c => c.CreateCountCommand<Customer>(expression.Body)).Returns(command.Object); provider.CommandExecutor.Setup(c => c.ExecuteCount(command.Object)).Returns(10); var target = new DataSession(provider.Object); var result = target.Count(expression); Assert.IsTrue(result == 10); }