using System; using System.Threading.Tasks; using MyCompanyName.MyProjectName.Users; using MongoDB.Driver.Linq; using Shouldly; using Volo.Abp.Domain.Repositories; using Xunit; namespace MyCompanyName.MyProjectName.MongoDB.Samples { /* This is just an example test class. * Normally, you don't test ABP framework code * (like default AppUser repository IRepository here). * Only test your custom repository methods. */ public class SampleRepositoryTests : MyProjectNameMongoDbTestBase { private readonly IRepository _appUserRepository; public SampleRepositoryTests() { _appUserRepository = GetRequiredService>(); } [Fact] public async Task Should_Query_AppUser() { /* Need to manually start Unit Of Work because * FirstOrDefaultAsync should be executed while db connection / context is available. */ await WithUnitOfWorkAsync(async () => { //Act var adminUser = await _appUserRepository .GetMongoQueryable() .FirstOrDefaultAsync(u => u.UserName == "admin"); //Assert adminUser.ShouldNotBeNull(); }); } } }