public DtoContractsPage GetAllContracts(IEnumerable<ColumnFilterInfo> filterCriteria, int page, int pageSize)
        {
            var filter = new ContractFilter();
            var items = filter.Filter(this.contractRepository.Items, filterCriteria);
            var contracts = items
                .OrderBy(c => c.Id)
                .Skip((page - 1) * pageSize)
                .Take(pageSize)
                .ToList();

            var dtoContracts = contracts.Select(c => Mapper.Map<DtoContract>(c));
            return new DtoContractsPage { Contracts = dtoContracts, TotalRecords = items.Count() };
        }
        public void GivenContractsListWhenFilterByTestersAndExperienceThenTestersContractsWithExperienceEqualToFilterCriteriaAreReturned()
        {
            var contracts = new List<Contract>
            {
                new Contract { Name = "C1", Type = ContractType.Tester, Experience = 4, Salary = 5000 },
                new Contract { Name = "C2", Type = ContractType.Developer, Experience = 4, Salary = 8000 },
                new Contract { Name = "C3", Type = ContractType.Tester, Experience = 5, Salary = 5500 }
            }.AsQueryable();
            var filterCriteria = new List<ColumnFilterInfo>
            {
                new ColumnFilterInfo { Type = ColumnFilterType.ContractType, Value = ContractType.Tester },
                new ColumnFilterInfo { Type = ColumnFilterType.ContractExperience, Value = 4 }
            };
            var contractFilter = new ContractFilter();

            var expected = "C1";
            var actual = contractFilter.Filter(contracts, filterCriteria);

            Assert.AreEqual(1, actual.Count());
            Assert.AreEqual(expected, actual.Single().Name, true);
        }
        public void GivenContractsListWhenFilterBySalaryThenContractsWithSalaryEqualToFilterCriteriaAreReturned()
        {
            var contracts = new List<Contract>
            {
                new Contract { Name = "C1", Type = ContractType.Developer, Experience = 3, Salary = 5000 },
                new Contract { Name = "C2", Type = ContractType.Developer, Experience = 5, Salary = 8000 },
                new Contract { Name = "C3", Type = ContractType.Tester, Experience = 5, Salary = 5000 }
            }.AsQueryable();
            var filterCriteria = new List<ColumnFilterInfo>
            {
                new ColumnFilterInfo { Type = ColumnFilterType.ContractSalaryEqualTo, Value = 5000m }
            };
            var contractFilter = new ContractFilter();

            var expected1 = "C1";
            var expected2 = "C3";
            var actual = contractFilter.Filter(contracts, filterCriteria);

            Assert.AreEqual(2, actual.Count());
            Assert.AreEqual(expected1, actual.ElementAt(0).Name, true);
            Assert.AreEqual(expected2, actual.ElementAt(1).Name, true);
        }
        public void GivenListOfContractsWhenFilteringByNullNameThenAllItemsAreReturned()
        {
            var contracts = new List<Contract>
            {
                new Contract { Name = "C1", Type = ContractType.Tester, Experience = 4, Salary = 5000 },
                new Contract { Name = "C2", Type = ContractType.Developer, Experience = 4, Salary = 8000 },
                new Contract { Name = "C3", Type = ContractType.Tester, Experience = 4, Salary = 5500 }
            }.AsQueryable();
            var filterCriteria = new List<ColumnFilterInfo>
            {
                new ColumnFilterInfo { Type = ColumnFilterType.ContractName }
            };
            var contractFilter = new ContractFilter();

            var actual = contractFilter.Filter(contracts, filterCriteria);

            Assert.AreEqual(3, actual.Count());
            Assert.AreEqual("C1", actual.ElementAt(0).Name, true);
            Assert.AreEqual("C2", actual.ElementAt(1).Name, true);
            Assert.AreEqual("C3", actual.ElementAt(2).Name, true);
        }