public async Task <VerifyOrganizationViewModel> Handle(VerifyOrganizationCommand request, CancellationToken cancellationToken) { var employeeEntities = await context.Employees .Include(e => e.PaidTimeOffPolicy) .Include(e => e.Subordinates) .ThenInclude(em => em.Employee) .OrderByDescending(e => e.EmployeeLevel) .ToListAsync(); Employee buildTree(EmployeeEntity employeeEntity) => employeeDomainToDbEntityMapper .MapToDomainEntity(employeeEntity) .WithSubordinates(from s in employeeEntity.Subordinates select buildTree(s.Employee)) .WithPaidTimeOffPolicy(ptoPolicyDomainToDbEntityMapper.MapToDomainEntity(employeeEntity.PaidTimeOffPolicy)); var trees = (from emp in employeeEntities where !emp.Managers.Any() select buildTree(emp)).ToList(); var stats = organizationVerifier.VerifyOrg(trees); return(new VerifyOrganizationViewModel { Stats = (from s in stats select new OrgStats { NumEmployees = s.Item1, OrgComplexity = s.Item2 }).ToList() }); }
public void VerifyOrg_MultipleTrees_ReturnsExpectedStats() { var trees = (from n in Enumerable.Range(1, 4) select UnitTestEmployeeGenerator.GenerateEmployee(n)).ToList(); var results = organizationVerifier.VerifyOrg(trees); Assert.Equal(1, results[0].Item1); Assert.Equal(1, results[0].Item2); Assert.Equal(3, results[1].Item1); Assert.Equal(4, results[1].Item2); Assert.Equal(10, results[2].Item1); Assert.Equal(15, results[2].Item2); Assert.Equal(41, results[3].Item1); Assert.Equal(64, results[3].Item2); }