标签:ABP adminUser await settingProvider Project Returns 3.3 new currentUser
1. foreign key constraint failed
在TestDataBuilder 中已经加了IdentityUser,但测试Application的时候,还是会报错
TestDataBuilder
private async Task AddUsers() { var adminUser = new IdentityUser(_guidGenerator.Create(), "administrator", "admin@abp.io"); adminUser.AddRole(_adminRole.Id); adminUser.AddClaim(_guidGenerator, new Claim("TestClaimType", "42")); await _userRepository.InsertAsync(adminUser); }
protected override void AfterAddApplication(IServiceCollection services) { _currentUser = Substitute.For<ICurrentUser>(); _currentUser.Id.Returns(_testData.UserJohnId); _currentUser.IsAuthenticated.Returns(true); services.AddSingleton(_currentUser); }
这种方法不起作用
optionsBuilder.UseSqlite($"Filename={databaseName}", x => x.SuppressForeignKeyEnforcement());
可以在连接字符串里指定不用Foreign Keys参数
AbpIdentityEntityFrameworkCoreTestModule
var connection = new SqliteConnection("Data Source=:memory:;Foreign Keys=False");
2. 测试的application方法disable了UOW,会报错Context已经displose
await WithUnitOfWorkAsync(async () => { ... });
3.Substitue 其它
ISettingProvider _settingProvider = Substitute.For<ISettingProvider>(); _settingProvider.GetOrNullAsync(Arg.Any<string>()).Returns((string) null); _settingProvider.GetOrNullAsync(IdentitySettingNames.Password.RequiredLength).Returns(Task.FromResult("42")); services.Replace(ServiceDescriptor.Singleton(_settingProvider));
4.判断报某种Exception
var exception = await Assert.ThrowsAsync<UserFriendlyException>( async () => await _testAppService.UpdateAsync(beforeEntity.Id, testDto) ); exception.Code.Contains("Unique").Should().BeTrue();
5.NSubstitute.Exceptions.CouldNotSetReturnDueToNoLastCallException: Could not find a call to return from.
Make sure you called Returns() after calling your substitute (for example: mySub.SomeMethod().Returns(value)), and that you are not configuring other substitutes within Returns() (for example, avoid this: mySub.SomeMethod().Returns(ConfigOtherSub())).
If you substituted for a class rather than an interface, check that the call to your substitute was on a virtual/abstract member. Return values cannot be configured for non-virtual/non-abstract members.
标签:ABP,adminUser,await,settingProvider,Project,Returns,3.3,new,currentUser 来源: https://www.cnblogs.com/sui84/p/15171111.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。