UnitOfWorkManager.Current
(nullreference异常)。这个
_unitOfWorkManager
类型:
IUnitOfWorkManager
我正在测试以下web api代码:
[HttpPost]
public async Task<IHttpActionResult> Subscription(SubscriptionInputDto model)
{
if (!await VendorHasAccess(model.OrganizationId))
return StatusCode(HttpStatusCode.Forbidden);
var input = new Subscription
{
...
};
var data = await _subscriptionRepository.InsertAsync(input);
await _unitOfWorkManager.Current.SaveChangesAsync();
return Ok(data.MapTo<SubscriptionDto>());
}
[Fact]
public async Task Should_Create_New_Subscription()
{
//Arrange
var organization = await UsingDbContextAsync(async context => await context.VendorOrganizations.FirstOrDefaultAsync());
var input = new SubscriptionInputDto { OrganizationId = organization.Id };
//Act
var actionResult = await _vendorController.Subscription(input);
var response = actionResult as OkNegotiatedContentResult<SubscriptionDto>;
//Assert
Assert.NotNull(response);
Assert.Equal(organization.Id, response.Content.OrganizationId);
}
我不知道或找不到任何关于如何解决问题的文档
UnitOfWorkManager。现在的
web API代码本身在生产中工作。