I hava a UnitTest, using DbContext directly is success, using IRepository always failed. My code is
[Fact]
public async Task Should_Get_EnterpriseAccounts()
{
//Success
var tenantId = AbpSession.TenantId.Value;
await UsingDbContext(async context =>
{
var items1 = await context.WechatEnterpriseAccounts.Where(
o => o.TenantId == tenantId).ToListAsync();
items1.Count.ShouldBeGreaterThan(0);
});
//Failed
var items2 = await _wechatAppService.GetEnterpriseAccounts();
items2.Items.Count.ShouldBeGreaterThan(0);
}
public async Task<ListResultOutput<EnterpriseAccountListDto>> GetEnterpriseAccounts()
{
var items = await _enterpriseAccountRepository.GetAll().ToListAsync();
return new ListResultOutput<EnterpriseAccountListDto>(
items.MapTo<List<EnterpriseAccountListDto>>());
}
public class EnterpriseAccount : FullAuditedEntity<Guid>, IMustHaveTenant
{
public EnterpriseAccount()
{
}
public EnterpriseAccount(string displayName)
{
DisplayName = displayName;
}
public virtual int TenantId { get; set; }
[Required]
[StringLength(64)]
public virtual string DisplayName { get; set; }
}
But my GetEnterpriseAccounts method is work when test via swagger.