Exemple #1
0
        private static Dictionary<OrderingCriteria, Func<IEnumerable<Employee>>> CreateOrdersMapping(EmployeeOrderingService service)
        {
            var result = new Dictionary<OrderingCriteria, Func<IEnumerable<Employee>>>();

            result.Add(OrderingCriteria.Default, service.OrderByDefault);
            result.Add(OrderingCriteria.FirstName, () => service.OrderBy(x=>x.FirstName));
            result.Add(OrderingCriteria.LastName, () => service.OrderBy(x=>x.LastName));
            result.Add(OrderingCriteria.Position, () => service.OrderBy(x=>x.Position));
            result.Add(OrderingCriteria.SeparationDate, () => service.OrderBy(x=>x.SeparationDateToString));

            return result;
        }
        public void Service_OrderByCustomPosition_TwoEmployees_ReturnsOrderedByPosition()
        {
            var dataProvider = new Mock<IEmployeeData>();
            dataProvider.Setup(x => x.GetEmployees())
                .Returns(twoEmployeeList);

            var svc = new EmployeeOrderingService(dataProvider.Object);
            var result = svc.OrderBy(x=>x.Position);

            Assert.AreEqual(2, result.Count());
            Assert.AreEqual("DBA", result.ElementAt(0).Position);
            Assert.AreEqual("Manager", result.ElementAt(1).Position);
        }
        public void Service_OrderByCustomDate_ThreeEmployees_ReturnsOrderedByDate()
        {
            var dataProvider = new Mock<IEmployeeData>();
            dataProvider.Setup(x => x.GetEmployees())
                .Returns(threeEmployeeList);

            var svc = new EmployeeOrderingService(dataProvider.Object);
            var result = svc.OrderBy(x => x.Position);

            Assert.AreEqual(3, result.Count());
            Assert.AreEqual("Jacquelyn", result.ElementAt(0).FirstName);
            Assert.AreEqual("Michaela", result.ElementAt(1).FirstName);
        }