Esempio n. 1
0
        public void GetMunros_WhenCalledWithValidMinAndMaxHeightsEitherCategory_ReturnsOnlyMunrosWithinHeightRange()
        {
            var fakeMunros = FakeMunroDataContext.GenerateFakeMunros(10, 10, 5, 600, 1500);

            const int minimumHeight = 650;
            const int maximumHeight = 1250;


            var count = fakeMunros.Count(fm => !string.IsNullOrEmpty(fm.HillCategoryPost1997) &&
                                         fm.HeightInMetres >= minimumHeight &&
                                         fm.HeightInMetres <= maximumHeight);


            var fakeDataContext = new FakeMunroDataContext(fakeMunros);

            var service = new MunroService(fakeDataContext, testMapper);

            var result = service.GetMunros(new MunroQuery
            {
                MinHeightInMetres = minimumHeight,
                MaxHeightInMetres = maximumHeight
            }).ToList();

            Assert.Equal(count, result.Count);
            Assert.NotEqual(fakeMunros.Count, result.Count);

            Assert.All(result, munro => Assert.InRange(munro.HeightInMetres, minimumHeight, maximumHeight));
        }
Esempio n. 2
0
        public void GetMunros_WhenCalledWithDefaultMunroQuery_ReturnsAllMunrosWithAPost1997Category()
        {
            const int numberOfMuns = 10;
            const int numberOfTops = 10;
            var       fakeMunros   = FakeMunroDataContext.GenerateFakeMunros(numberOfMuns, numberOfTops, 20, 600, 1500);

            var fakeDataContext = new FakeMunroDataContext(fakeMunros);

            var service = new MunroService(fakeDataContext, testMapper);

            var result = service.GetMunros(new MunroQuery()).ToList();

            Assert.Equal(result.Count, numberOfMuns + numberOfTops);
            Assert.All(result, munro => Assert.NotEqual("", munro.HillCategory));
        }
Esempio n. 3
0
        public void GetMunros_WhenCalledWithLimit_ReturnsLimitNumberOfValidMunros(int limit, int numMuns, int numTops)
        {
            var fakeMunros = FakeMunroDataContext.GenerateFakeMunros(numMuns, numTops, 0, 600, 1500);

            var fakeDataContext = new FakeMunroDataContext(fakeMunros);

            var service = new MunroService(fakeDataContext, testMapper);

            var result = service.GetMunros(new MunroQuery
            {
                Limit = limit
            }).ToList();

            Assert.Equal(result.Count, Math.Min(limit, numMuns + numTops));
            Assert.All(result, munro => Assert.NotEqual("", munro.HillCategory));
        }
Esempio n. 4
0
        public void GetMunros_WhenCalledWithEitherCategorySortByNameDescThenByNameAsc_ReturnsMunrosInCorrectDescendingOrder()
        {
            var fakeMunros = FakeMunroDataContext.GenerateFakeMunros(20, 15, 10, 500, 2000);

            var orderedFakeMunros = fakeMunros.Where(m => !string.IsNullOrEmpty(m.HillCategoryPost1997))
                                    .OrderByDescending(m => m.Name).ToList();

            var fakeDataContext = new FakeMunroDataContext(fakeMunros);

            var service = new MunroService(fakeDataContext, testMapper);

            var result = service.GetMunros(new MunroQuery
            {
                SortBy = "desc(name),asc(name)"
            }).ToList();

            Assert.Equal(orderedFakeMunros.Count, result.Count);

            Assert.Equal(orderedFakeMunros.Select(m => m.Name), result.Select(m => m.Name));
        }
Esempio n. 5
0
        public void GetMunros_WhenCalledSortByWithEmptyStringBetweenCriteria_ReturnsMunrosInCorrectOrder()
        {
            var fakeMunros = FakeMunroDataContext.GenerateFakeMunros(20, 15, 10, 500, 2000);

            var orderedFakeMunros = fakeMunros.Where(m => !string.IsNullOrEmpty(m.HillCategoryPost1997))
                                    .OrderByDescending(m => m.Name).ToList();

            var fakeDataContext = new FakeMunroDataContext(fakeMunros);

            var service = new MunroService(fakeDataContext, testMapper);

            var query = new MunroQuery
            {
                SortBy = "desc(name),,asc(name)"
            };

            var result = service.GetMunros(query).ToList();

            Assert.Equal(2, query.SortingCriterias.Count);

            Assert.Equal(orderedFakeMunros.Count, result.Count);

            Assert.Equal(orderedFakeMunros.Select(m => m.Name), result.Select(m => m.Name));
        }