我有此代码:
[Fact]
public async Task CorrectlyBakesACake()
{
// create user
var userdto = await CreateFakeUserAsync();
// create Cake
var cakedto = await CreateBasicCakeForUserAsync(userdto);
}
public async Task<UserDto> CreateFakeUserAsync()
{
var _userAppService = LocalIocManager.Resolve<UserAppService>();
return await _userAppService.Create(
new CreateUserDto
{
EmailAddress = "cakejohn@gmail.com",
IsActive = true,
Name = "John",
Surname = "Nash",
Password = "caker123",
UserName = "cakejohn"
});
}
public async Task<OwnerCakeDto> CreateBasicCakeForUserAsync(UserDto user)
{
LoginAsHost(user.UserName);
var _cakeAppService = LocalIocManager.Resolve<CakeAppService>();
await _cakeAppService.BakeCake(new BakeCakeInput()
{
sprinkles = true,
color ="aqua",
Yum = 5
});
return _cakeAppService.GetCakes()[0];
}
为什么上下文对象被处置? DI在离开服务方法时会处理对象吗? DI何时确切决定处理上下文? 做这些测试的“正确”方法是什么?我想尽可能地使用我的服务/域服务方法。
尝试_cakeAppService.BakeCake
时出错。