ABP框架使用(版本3.3.1) - Test Project
2021/8/22 6:37:32
本文主要是介绍ABP框架使用(版本3.3.1) - Test Project,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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框架使用(版本3.3.1) - Test Project的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-23增量更新怎么做?-icode9专业技术文章分享
- 2024-11-23压缩包加密方案有哪些?-icode9专业技术文章分享
- 2024-11-23用shell怎么写一个开机时自动同步远程仓库的代码?-icode9专业技术文章分享
- 2024-11-23webman可以同步自己的仓库吗?-icode9专业技术文章分享
- 2024-11-23在 Webman 中怎么判断是否有某命令进程正在运行?-icode9专业技术文章分享
- 2024-11-23如何重置new Swiper?-icode9专业技术文章分享
- 2024-11-23oss直传有什么好处?-icode9专业技术文章分享
- 2024-11-23如何将oss直传封装成一个组件在其他页面调用时都可以使用?-icode9专业技术文章分享
- 2024-11-23怎么使用laravel 11在代码里获取路由列表?-icode9专业技术文章分享
- 2024-11-22怎么实现ansible playbook 备份代码中命名包含时间戳功能?-icode9专业技术文章分享