Пример #1
0
        public List <Diamond> DiamondsBySearchParameters(DiamondSearchParameters mappedSearchParameters)
        {
            if (mappedSearchParameters.PriceFrom > mappedSearchParameters.PriceTo && mappedSearchParameters.PriceTo != 0)
            {
                var temp = mappedSearchParameters.PriceFrom;
                mappedSearchParameters.PriceFrom = mappedSearchParameters.PriceTo;
                mappedSearchParameters.PriceTo   = temp;
            }

            if (mappedSearchParameters.WeightFrom > mappedSearchParameters.WeightTo && mappedSearchParameters.WeightTo != 0)
            {
                decimal temp2 = mappedSearchParameters.WeightFrom;
                mappedSearchParameters.WeightFrom = mappedSearchParameters.WeightTo;
                mappedSearchParameters.WeightTo   = temp2;
            }

            using (var db = new JONEntities())
            {
                var dbdiamonds = db.v_jd_diamonds
                                 .ExtWhereIn(cond => cond.color, mappedSearchParameters.Color)
                                 .ExtWhereIn(cond => cond.clarity, mappedSearchParameters.Clarity)
                                 .ExtWhereIn(cond => cond.shape, mappedSearchParameters.Shape)
                                 .ExtWhereIn(cond => cond.report, mappedSearchParameters.Report)
                                 .ExtWhereIn(cond => cond.cut, mappedSearchParameters.Cut)
                                 .ExtWhereFromToRangeAndIgnoreZero(x => x.totalprice, mappedSearchParameters.PriceFrom, mappedSearchParameters.PriceTo)
                                 .ExtWhereFromToRangeAndIgnoreZero(x => x.weight, mappedSearchParameters.WeightFrom, mappedSearchParameters.WeightTo)
                ;



                if (mappedSearchParameters.ItemsPerPage == 0)
                {
                    mappedSearchParameters.ItemsPerPage = 10;
                }

                totalRecords = dbdiamonds.Count();
                if (TotalRecords % mappedSearchParameters.ItemsPerPage == 0)
                {
                    lastOporationTotalPages = TotalRecords / mappedSearchParameters.ItemsPerPage;
                }
                else
                {
                    lastOporationTotalPages = TotalRecords / mappedSearchParameters.ItemsPerPage + 1;
                }

                if (mappedSearchParameters.OrderBy != null)
                {
                    dbdiamonds = dbdiamonds.OrderBy(mappedSearchParameters.OrderBy.SQLString);
                }


                var dbdiamondslist = dbdiamonds.Skip((mappedSearchParameters.Page - 1) * mappedSearchParameters.ItemsPerPage).Take(mappedSearchParameters.ItemsPerPage).ToList();

                var diamonds = mapper.Map <IList <v_jd_diamonds>, List <Diamond> >(dbdiamondslist);

                return(diamonds);
            }
        }
Пример #2
0
        public List<Diamond> DiamondsBySearchParameters(DiamondSearchParameters mappedSearchParameters)
        {
            if (mappedSearchParameters.PriceFrom > mappedSearchParameters.PriceTo && mappedSearchParameters.PriceTo != 0)
            {
                var temp = mappedSearchParameters.PriceFrom;
                mappedSearchParameters.PriceFrom = mappedSearchParameters.PriceTo;
                mappedSearchParameters.PriceTo = temp;
            }

            if (mappedSearchParameters.WeightFrom > mappedSearchParameters.WeightTo && mappedSearchParameters.WeightTo != 0)
            {
                decimal temp2 = mappedSearchParameters.WeightFrom;
                mappedSearchParameters.WeightFrom = mappedSearchParameters.WeightTo;
                mappedSearchParameters.WeightTo = temp2;
            }

            using (var db = new JONEntities())
            {
                var dbdiamonds = db.v_jd_diamonds
                .ExtWhereIn(cond => cond.color, mappedSearchParameters.Color)
                .ExtWhereIn(cond => cond.clarity, mappedSearchParameters.Clarity)
                .ExtWhereIn(cond => cond.shape, mappedSearchParameters.Shape)
                .ExtWhereIn(cond => cond.report, mappedSearchParameters.Report)
                .ExtWhereIn(cond => cond.cut, mappedSearchParameters.Cut)
                .ExtWhereFromToRangeAndIgnoreZero(x => x.totalprice,mappedSearchParameters.PriceFrom,mappedSearchParameters.PriceTo)
                .ExtWhereFromToRangeAndIgnoreZero(x => x.weight, mappedSearchParameters.WeightFrom, mappedSearchParameters.WeightTo)
                ;

                if (mappedSearchParameters.ItemsPerPage == 0)
                {
                    mappedSearchParameters.ItemsPerPage = 10;
                }

                totalRecords = dbdiamonds.Count();
                if (TotalRecords % mappedSearchParameters.ItemsPerPage == 0)
                {
                    lastOporationTotalPages = TotalRecords / mappedSearchParameters.ItemsPerPage;
                }
                else
                {
                    lastOporationTotalPages = TotalRecords / mappedSearchParameters.ItemsPerPage + 1;
                }

                if (mappedSearchParameters.OrderBy != null)
                {
                    dbdiamonds = dbdiamonds.OrderBy(mappedSearchParameters.OrderBy.SQLString);
                }

            var dbdiamondslist = dbdiamonds.Skip((mappedSearchParameters.Page - 1) * mappedSearchParameters.ItemsPerPage).Take(mappedSearchParameters.ItemsPerPage).ToList();

            var diamonds = mapper.Map<IList<v_jd_diamonds>, List<Diamond>>(dbdiamondslist);

            return diamonds;

            }
        }
Пример #3
0
        public void DiamondsBySearchParameters_ShouldFilterResultsByColorButMoreThenOneColorSelected()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;
            searchParameters.Color = new List<string>() { "H","G" };

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(4);
        }
Пример #4
0
        public List<Diamond> DiamondsBySearchParameters(DiamondSearchParameters mappedSearchParameters)
        {
            if (mappedSearchParameters.PriceFrom > mappedSearchParameters.PriceTo && mappedSearchParameters.PriceTo != 0)
            {
                var temp = mappedSearchParameters.PriceFrom;
                mappedSearchParameters.PriceFrom = mappedSearchParameters.PriceTo;
                mappedSearchParameters.PriceTo = temp;
            }

            if (mappedSearchParameters.WeightFrom > mappedSearchParameters.WeightTo && mappedSearchParameters.WeightTo != 0)
            {
                decimal temp2 = mappedSearchParameters.WeightFrom;
                mappedSearchParameters.WeightFrom = mappedSearchParameters.WeightTo;
                mappedSearchParameters.WeightTo = temp2;
            }

            var dbdiamonds = dbmock
                .Where(cond => MakeEmptyListActLikeAnAllFilter(cond.color, mappedSearchParameters.Color))
                .Where(cond => MakeEmptyListActLikeAnAllFilter(cond.clarity, mappedSearchParameters.Clarity))
                .Where(cond => MakeEmptyListActLikeAnAllFilter(cond.shape, mappedSearchParameters.Shape))
                .Where(cond => MakeEmptyListActLikeAnAllFilter(cond.report, mappedSearchParameters.Report))
                .Where(cond => MakeEmptyListActLikeAnAllFilter(cond.cut, mappedSearchParameters.Cut))
                .Where(x => MakeZeroActAsIgnoreParameter(p => p.totalprice >= mappedSearchParameters.PriceFrom, x, mappedSearchParameters.PriceFrom) && MakeZeroActAsIgnoreParameter(p => p.totalprice <= mappedSearchParameters.PriceTo, x, mappedSearchParameters.PriceTo))
                .Where(x => MakeZeroActAsIgnoreParameter(p => p.weight >= mappedSearchParameters.WeightFrom, x, mappedSearchParameters.WeightFrom) && MakeZeroActAsIgnoreParameter(p => p.weight <= mappedSearchParameters.WeightTo, x, mappedSearchParameters.WeightTo))
                ;

            if (mappedSearchParameters.ItemsPerPage == 0)
            {
                mappedSearchParameters.ItemsPerPage = 10;
            }

            totalRecords = dbdiamonds.Count();
            if (TotalRecords % mappedSearchParameters.ItemsPerPage == 0)
            {
                lastOporationTotalPages = TotalRecords/mappedSearchParameters.ItemsPerPage;
            } else
            {
                lastOporationTotalPages = TotalRecords/mappedSearchParameters.ItemsPerPage + 1;
            }

            if (mappedSearchParameters.OrderBy != null)
            {
                dbdiamonds = dbdiamonds.OrderBy(mappedSearchParameters.OrderBy.SQLString);
            }

            var dbdiamondslist  = dbdiamonds.Skip((mappedSearchParameters.Page-1)*mappedSearchParameters.ItemsPerPage).Take(mappedSearchParameters.ItemsPerPage).ToList();

            var diamonds = mapper.Map<IList<v_jd_diamonds>, List<Diamond>>(dbdiamondslist);

            return diamonds;
        }
Пример #5
0
        public void TotalPagesNumber_ShouldSortByWeightInDescOrderWhenCalledAsPartOFTheSearchParams()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.OrderBy = new DynamicOrderBy("totalprice", "desc");

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);

            //Assert
            var unsortedCollectio = GetDiamondCollectionUnSorted();
            diamonds.Should().ContainInOrder(unsortedCollectio.OrderByDescending(x => x.Price).ToList());
        }
Пример #6
0
        private List<Diamond> GetDiamondCollectionUnSorted()
        {
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            return diamondRepository.DiamondsBySearchParameters(searchParameters);
        }
Пример #7
0
        public void DiamondsBySearchParameters_ShouldReturnZeroItemsIfThePageRequestedDoesntExists()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 3;
            searchParameters.ItemsPerPage = 3;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(0);
        }
Пример #8
0
        public void TotalPagesNumber_ShouldReturnTheTotalNumberOfPagesCorrectly()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 2;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            diamondRepository.DiamondsBySearchParameters(searchParameters);
            var totalPages = diamondRepository.LastOporationTotalPages;
            //Assert
            totalPages.Should().Be(3);
        }
Пример #9
0
        public void DiamondsBySearchParameters_ShouldReturnAllTheItemsInTheRepostoryWhenNoFiltersAreAskedForAndWeWantTheFirstPage()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(THE_TOTAL_NUMBER_OF_ITEMS);
        }
Пример #10
0
        public void DiamondsBySearchParameters_ShouldReturnOnly3ItemsOnPage2AsRequestedBySearchParams()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 2;
            searchParameters.ItemsPerPage = 3;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(3);
        }
Пример #11
0
        public void DiamondsBySearchParameters_ShouldReturn1ItemOnPage2WhenPageSizeIs5()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 2;
            searchParameters.ItemsPerPage = 5;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(1);
        }
Пример #12
0
        public void DiamondsBySearchParameters_ShouldFilterResultsByWeightMarginsWhenOnlyToWeightIsSpecified()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;
            searchParameters.WeightFrom = 0;
            searchParameters.WeightTo = (decimal) 1.35;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(3);
        }
Пример #13
0
        public void DiamondsBySearchParameters_ShouldFilterResultsByWeightMarginsWhenBothAreSpecifiedEvenIfTheFromFieldIBiggerThenTheToField()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;
            searchParameters.WeightFrom = (decimal) 1.35;
            searchParameters.WeightTo = 1;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(3);
        }
Пример #14
0
        public void DiamondsBySearchParameters_ShouldFilterResultsByShapeWhenOneShapeSelected()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;
            searchParameters.Shape = new List<string>() { "Round" };

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(2);
        }
Пример #15
0
        public void DiamondsBySearchParameters_ShouldFilterResultsByPriceMarginsWhenOnlyToPriceIsSpecified()
        {
            //Arrange
            var searchParameters = new DiamondSearchParameters();
            searchParameters.Page = 1;
            searchParameters.ItemsPerPage = 10;
            searchParameters.PriceFrom = 0;
            searchParameters.PriceTo = 26000;

            var diamondRepository = new FakeDiamondRepository(mapper);
            //Act
            var diamonds = diamondRepository.DiamondsBySearchParameters(searchParameters);
            //Assert
            diamonds.Should().HaveCount(3);
        }