Я получаю какое -то странное поведение при попытке проверить запрос, который изменяет некоторые данные сотрудников из моей базы данных. Запрос функционирует, как и ожидалось на реальных данных, но при попытке использовать автофиктерий для создания интеграционного теста, Groupby отказывается агрегировать на идентичные приспособления сотрудников. < /P>
Groupby немного нечетно в ощущение, что я пытаюсь сгруппировать по всей сущности, а также некоторые другие области. Это происходит в памяти, потому что невозможно преобразовать его в SQL. < /P>
, поскольку выход верен при тестировании на API с реальным БД, проблема должна быть где -то в тесте , но я потратил впустую часы, пытаясь выяснить, где. < /p>
Ожидаемый результат ниже должен быть длина списка 2, но вместо этого он возвращается 3. < /p>
усеченные объекты < /p>
public class EmployeeEntity
{
public string EmployeeId { get; set; } = null!;
public string FirstName { get; set; } = null!;
public string LastName { get; set; } = null!;
public ICollection? SupportRoles { get; set; }
}
public class SupportRoleEntity : AuditableEntity
{
public string SupportId { get; set; } = null!;
public string EmployeeId { get; set; } = null!;
public string SupportRolePropertyId { get; set; } = null!;
public string SupportEmployeeId { get; set; } = null!;
public SupportRolePropertiesEntity SupportRoleProperties { get; set; } = null!;
public EmployeeEntity EmployeeInfo { get; set; } = null!;
public EmployeeEntity SupportEmployeeInfo { get; set; } = null!;
}
public class SupportRolePropertiesEntity
{
public string SupportRolePropertyId { get; set; } = null!;
public string RoleType { get; set; }
public ICollection? SupportRoles { get; set; }
}
< /code>
Query < /p>
public List GetSupportRoles(string employeeId)
{
return _dbContext.SupportRoles
.Include(s => s.SupportRoleProperties)
.Include(s => s.SupportEmployeeInfo)
.Include(s => s.EmployeeInfo)
.Where(s => s.EmployeeId == employeeId)
.AsEnumerable()
.GroupBy(s => new SupportRoleKey
{
EmployeeInfo = s.EmployeeInfo,
SupportRolePropertyId = s.SupportRolePropertyId,
RoleType = s.SupportRoleProperties.RoleType
})
.Select(group => new
{
group.Key,
SupportXEmployee = group.Select(x => _supportRoleEntityConverter.ConvertToSupportRoleDTO(x)).ToList()
})
.Select(group => _supportRoleEntityConverter.ConvertToSupportRoleEmployeeDTO(
group.Key,
group.SupportXEmployee))
.ToList();
}
public class SupportRoleKey
{
public EmployeeEntity EmployeeInfo { get; set; } = null!;
public string SupportRolePropertyId { get; set; } = null!;
public string RoleType { get; set; }
}
< /code>
test < /p>
EmployeeEntity employeeEntity = _fixture.Build()
.Create();
EmployeeEntity supportEmployeeEntityOne = _fixture.Build()
.Create();
EmployeeEntity supportEmployeeEntityTwo = _fixture.Build()
.Create();
EmployeeEntity supportEmployeeEntityThree = _fixture.Build()
.Create();
SupportRolePropertiesEntity hrBP = _fixture.Build()
.With(sr => sr.RoleType, "HRPartner")
.Without(sr => sr.SupportRoles)
.Create();
SupportRolePropertiesEntity hrRep = _fixture.Build()
.With(sr => sr.RoleType, "HrSupport")
.Without(sr => sr.SupportRoles)
.Create();
SupportRoleEntity supportRoleBusinessEntityOne = _fixture.Build()
.With(sr => sr.SupportRoleProperties, hrBP)
.With(sr => sr.SupportRolePropertyId, hrBP.SupportRolePropertyId)
.With(sr => sr.EmployeeInfo, employeeEntity)
.With(sr => sr.XEmployeeId, employeeEntity.EmployeeId)
.With(sr => sr.SupportEmployeeInfo, supportEmployeeEntityOne)
.With(sr => sr.SupportXEmployeeId, supportEmployeeEntityOne.EmployeeId)
.Create();
SupportRoleEntity supportRoleBusinessEntityTwo = _fixture.Build()
.With(sr => sr.SupportRoleProperties, hrBP)
.With(sr => sr.SupportRolePropertyId, hrBP.SupportRolePropertyId)
.With(sr => sr.EmployeeInfo, employeeEntity)
.With(sr => sr.XEmployeeId, employeeEntity.EmployeeId)
.With(sr => sr.SupportEmployeeInfo, supportEmployeeEntityTwo)
.With(sr => sr.SupportXEmployeeId, supportEmployeeEntityTwo.EmployeeId)
.Create();
SupportRoleEntity supportRoleSupportEntity = _fixture.Build()
.With(sr => sr.SupportRoleProperties, hrRep)
.With(sr => sr.SupportRolePropertyId, hrRep.SupportRolePropertyId)
.With(sr => sr.EmployeeInfo, employeeEntity)
.With(sr => sr.XEmployeeId, employeeEntity.EmployeeId)
.With(sr => sr.SupportEmployeeInfo, supportEmployeeEntityThree)
.With(sr => sr.SupportXEmployeeId, supportEmployeeEntityThree.EmployeeId)
.Create();
await DbContext.AddAsync(employeeEntity);
await DbContext.AddAsync(employeeEntityNotReturned);
await DbContext.AddAsync(supportEmployeeEntityOne);
await DbContext.AddAsync(supportEmployeeEntityTwo);
await DbContext.AddAsync(supportEmployeeEntityThree);
await DbContext.AddAsync(hrBP);
await DbContext.AddAsync(hrRep);
await DbContext.AddAsync(supportRoleBusinessEntityOne);
await DbContext.AddAsync(supportRoleBusinessEntityTwo);
await DbContext.AddAsync(supportRoleSupportEntity);
await DbContext.SaveChangesAsync();
// Act
List supportRoleEmployeeDto =
_service.GetSupportRoles(employeeEntity.Id);
// Assert
supportRoleEmployeeDto.Count().Should().Be(2); # But is 3
Подробнее здесь: https://stackoverflow.com/questions/794 ... tofixtures
Организация объекта Groupby не ведет себя, как и ожидалось при тестировании с помощью автофиксов [дублировать] ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Короткий код для Bishop+Knight, который ведет себя не так, как ожидалось [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 22 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Короткий код для Bishop+Knight, который ведет себя не так, как ожидалось [закрыто]
Anonymous » » в форуме Python - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Tkinter after функция ведет себя не так, как ожидалось. В чем причина?
Anonymous » » в форуме Python - 0 Ответы
- 18 Просмотры
-
Последнее сообщение Anonymous
-