问题描述
我有以下服务方式
public async Task<IResultList<IEnrichedContentEntity>> QueryAsync(Context context,string schemaIdOrName,Q q)
{
Guard.NotNull(context,nameof(context));
if (q == null)
{
return EmptyContents;
}
var schema = await GetSchemaOrThrowAsync(context,schemaIdOrName);
var permissionReadOwn = Permissions.ForApp(Permissions.AppContentReadOwn,context.App.Name,schemaIdOrName);
if (context.Permissions.Allows(permissionReadOwn))
{
q.CreatedBy = context.User.Token();
}
using (Profiler.TraceMethod<ContentQueryService>())
{
q = await queryParser.ParseAsync(context,q,schema);
var contents = await contentRepository.QueryAsync(context.App,schema,context.Scope());
if (q.Ids != null && q.Ids.Count > 0)
{
contents = contents.sortSet(x => x.Id,q.Ids);
}
return await TransformAsync(context,contents);
}
}
如果权限正确,q.CreatedBy 必须设置值。 我如何测试 q.CreatedBy 是否不为空并且具有正确的值。
我实现了以下测试,但不知道如何检查此参数?
public async Task QueryAll_should_return_own_user_contents(int isFrontend,int unpublished,SearchScope scope)
{
var ctx = CreateContextWithOwnReadPermission(isFrontend: isFrontend == 1,allowSchema: true)
.WithUnpublished(unpublished == 1);
var content = CreateContent(contentId);
var q = Q.Empty.WithReference(DomainId.NewGuid());
A.CallTo(() => contentRepository.QueryAsync(ctx.App,scope))
.Returns(ResultList.CreateFrom(5,content));
//A.CallTo(() => contentRepository.QueryAsync(ctx.App,A<Q>.That.Matches(x => x.CreatedBy == null),scope))
// .MustHaveHappened();
//A.CallTo(() => contentRepository.QueryAsync(ctx.App,A<Q>.That.Matches(x => x.CreatedBy == ctx.User.Token()),scope))
// .MustHaveHappened();
//q.CreatedBy = ctx.User.Token();
var result = await sut.QueryAsync(ctx,schemaId.Name,q);
Assert.Equal(contentData,result[0].Data);
Assert.Equal(contentId,result[0].Id);
Assert.Equal(5,result.Total);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)