Ejemplo n.º 1
0
        public void Given_ManagerHasSubordinates_When_Retrieved_Then_ExistWithinTheManagersSubordinateList(
            int managerId, int[] subordinateIds)
        {
            #region  Arrange

            var query = new GetEmployeeHierarchyQuery();
            this._employeeRepository.All().Returns(GetMockedEmployees().AsQueryable());

            #endregion
            #region Act

            var result  = _handler.Handle(query);
            var manager = FindEmployeeTO(result.RootEmployees, managerId);

            #endregion
            #region Assert

            // Make sure the manager is exist
            Assert.NotNull(manager);

            // Make sure the manager only has the right amount of subordinates
            Assert.Equal(manager.Subordinates.Count, subordinateIds.Length);

            // Make sure the manager has subordinate-id within his/her subordinate-list
            foreach (var id in subordinateIds)
            {
                Assert.Contains(manager.Subordinates, x => x.Id == id);
            }

            #endregion
        }
Ejemplo n.º 2
0
        public void Given_NoEmployeeExist_When_Retrieved_Then_ReturnsNothing()
        {
            #region  Arrange

            var query = new GetEmployeeHierarchyQuery();
            this._employeeRepository.All().Returns(new List <Employee>().AsQueryable());

            #endregion
            #region Act

            var result = _handler.Handle(query);

            #endregion
            #region Assert

            Assert.Empty(result.RootEmployees);

            #endregion
        }
Ejemplo n.º 3
0
        public void Given_EmployeeExist_When_Retrieved_Then_ReturnsOnlyTopManagerAtItsRootLevel()
        {
            #region  Arrange

            var query = new GetEmployeeHierarchyQuery();
            this._employeeRepository.All().Returns(GetMockedEmployees().AsQueryable());

            #endregion
            #region Act

            var result = _handler.Handle(query);

            #endregion
            #region Assert

            Assert.All(result.RootEmployees, x => Assert.False(x.ManagerId.HasValue));

            #endregion
        }
Ejemplo n.º 4
0
        public void Given_EmployeeHasNoManager_When_Retrieved_Then_ShouldAppearAtTheRootLevel(int employeeId)
        {
            #region  Arrange

            var query = new GetEmployeeHierarchyQuery();
            this._employeeRepository.All().Returns(GetMockedEmployees().AsQueryable());

            #endregion
            #region Act

            var result = _handler.Handle(query);
            var king   = result.RootEmployees.FirstOrDefault(x => x.Id == employeeId);

            #endregion
            #region Assert

            // Make sure employee is exist
            Assert.NotNull(king);

            #endregion
        }
Ejemplo n.º 5
0
        public void Given_EmployeeHasInvalidManagerId_When_Retrieved_Then_InvalidManagerWillBeStoredAtRootAsUnknown(int unknownManagerId)
        {
            #region  Arrange

            var query = new GetEmployeeHierarchyQuery();
            this._employeeRepository.All().Returns(GetMockedEmployees().AsQueryable());

            #endregion
            #region Act

            var result         = _handler.Handle(query);
            var unknownManager = result.RootEmployees.FirstOrDefault(x => x.Id == unknownManagerId);

            #endregion
            #region Assert

            // Make sure 'unknown-manager' is exist
            Assert.NotNull(unknownManager);

            #endregion
        }