Вам нужно будет смоделировать вывод из репозитория следующим образом, основываясь на методе, который вы пытаетесь проверить:
@MockBean
private ProductRepo repo;
А затем
Mockito.when(this.repo.findById("PR-123")
.get())
.thenReturn(this.product);
this.mvc.perform(MockMvcRequestBuilders.get("/products/{id}", "PR-123")
.contentType(MediaType.APPLICATION_JSON_VALUE))
.andReturn();
Кроме того, удалите сервер -context-path при вызове API в методе execute ().
Хотя это, вероятно, лучше подходит для join, вы можете использовать это:
List<Personnel> query =
(from p in this.Database.Personnels
where OrgIds.Contains(p.OrgID) select p).ToList();
Это переведет в SQL что-то вроде ..
where OrgID in (1,2,...,n)
Я хотел поблагодарить Адама за ответ, но я также хотел поделиться кодом, который использовал для этой работы:
List<int> OrgIds= (from oh in this.Database.OrganizationsHierarchies
join o in this.Database.Organizations on oh.OrganizationsId equals o.Id
where (oh.Hierarchy.Contains(@OrgId))
|| (oh.OrganizationsId == Id)
select o.Id).ToList();
List<Personnel> query = (from p in this.Database.Personnels
where (OrgIds.Contains(p.OrganizationId))
select p).ToList();
-Matt
Здесь должна работать проверка с использованием метода Содержит
.
var query = (from p in this.Database.Personnels
where OrgIds.Contains(p.OrganisationId)
select p).ToList();
Это будет примерно так, OrgIds.ToList.Contains (p.OrginizationID)
Хотя на самом деле я бы сделал это примерно так:
var OrgIds = (from oh in this.Database.OrganizationsHierarchies
join o in this.Database.Organizations on oh.OrganizationsId equals o.Id
where (oh.Hierarchy.Contains(@OrgId))
|| (oh.OrganizationsId == Id)
select o.Id);
List<Personnel> query = (from p in this.Database.Personnels
where (OrgIds.Contains(p.OrigizationID)
select p).ToList();
Таким образом, будет выполняться последний запрос на получение персонала, содержащий комбинированный запрос от обоих.