예제 #1
0
        public void CheckIfGetOnlyUserScootersBySortingReturnsTheCorrectScootersForThatParticularUser()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new ElectricScootersService(dbContext);

            var serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "UploadDate");

            var dbOnlyUserScooters = dbContext.ElectricScooterOffers.Where(x => x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d").OrderByDescending(x => x.CreatedOn).ToList();

            if (serviceOnlyUserScooters.Count == 0 && dbOnlyUserScooters.Count == 0)
            {
                Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count());
                return;
            }

            Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title);

            serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "LowestPrice");


            dbOnlyUserScooters = dbOnlyUserScooters
                                 .OrderBy(x => x.Price).ToList();

            Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title);


            serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "HighestPrice");

            dbOnlyUserScooters = dbOnlyUserScooters
                                 .OrderByDescending(x => x.Price).ToList();


            Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title);

            serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "OldestYear");


            dbOnlyUserScooters = dbOnlyUserScooters
                                 .OrderBy(x => x.Year).ToList();

            Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title);


            serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", "NewestYear");

            dbOnlyUserScooters = dbOnlyUserScooters
                                 .OrderByDescending(x => x.Year).ToList();


            Assert.Equal(serviceOnlyUserScooters.FirstOrDefault().Title, dbOnlyUserScooters.FirstOrDefault().Title);

            Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count());
        }
예제 #2
0
        public void CheckIfGetOnlyUserScootersByFiltersReturnsTheCorrectScootersForThatParticularUser()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new ElectricScootersService(dbContext);

            FiltersInputModel filtersInputModel = new FiltersInputModel()
            {
                Condition     = Condition.New,
                MinPrice      = 100,
                Make          = "All",
                Model         = "-- All --",
                MaxPrice      = 1000000,
                MinKilometers = 0,
                MaxKilometers = 1000000,
                MinMotorPower = 0,
                MaxMotorPower = 5000
            };

            var scootersCollection = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d", filtersInputModel);

            var scootersAvailableInDb = dbContext.ElectricScooterOffers.Where(x =>
                                                                              x.Condition == Condition.New &&
                                                                              x.Price >= 100 && x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d");

            Assert.Equal(scootersCollection.Count(), scootersAvailableInDb.Count());
        }
예제 #3
0
        public void CheckIfGetOnlyUserScootersReturnsTheScootersForThatParticularUserOnly()
        {
            var dbContext = new AutomobileDbContext();
            var service   = new ElectricScootersService(dbContext);

            var serviceOnlyUserScooters = service.GetOnlyUserScooters("b97261dd-b5c7-4c89-ab32-5d3934b2c85d");

            var dbOnlyUserScooters = dbContext.ElectricScooterOffers.Where(x => x.UserId == "b97261dd-b5c7-4c89-ab32-5d3934b2c85d");

            Assert.Equal(dbOnlyUserScooters.Count(), serviceOnlyUserScooters.Count());
        }