C/C++教程

ABP框架使用(版本3.3.1) - Test Project

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!