public async Task DeletesEntity(bool supplyTransactions, bool rollback) { SqlRepositoryTest sqlRepository = new SqlRepositoryTest(_connectionFactory.Object, _sqlPolicyFactory.Object); TestEntity testEntity = new TestEntity { name = "TestEntity" }; SetupCommandAsync(_connection); _command.Setup(_ => _.ExecuteNonQueryAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(rollback ? 0 : 1); bool success; success = await sqlRepository.DeleteOne(testEntity, supplyTransactions); if (rollback) { _transaction.Verify(_ => _.Rollback(), Times.Once); } success .Should() .Be(rollback ? false : true); }
public async Task InsertsEntity(bool supplyTransactions, bool rollback) { int identity = rollback ? -1 : 1; SqlRepositoryTest sqlRepository = new SqlRepositoryTest(_connectionFactory.Object, _sqlPolicyFactory.Object); TestEntity testEntity = new TestEntity { name = "TestEntity" }; TestEntity expectedEntity = new TestEntity { id = identity, name = "TestEntity" }; SetupCommandAsync(_connection); _command.Protected() .Setup <Task <DbDataReader> >("ExecuteDbDataReaderAsync", ItExpr.IsAny <CommandBehavior>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(() => (new[] { expectedEntity }).ToDataTable(typeof(TestEntity)).ToDataTableReader()); IEnumerable <TestEntity> entities = null; int retValue = 0; retValue = await sqlRepository.InsertOne(testEntity, supplyTransactions); if (rollback) { _transaction.Verify(_ => _.Rollback(), Times.Once); } retValue .Should() .Be(identity); }