예제 #1
0
        public async Task GetCurrentCarAsyncTest()
        {
            var options       = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));

            var service = new AdService(carRepository);

            var inputModel = new CreateAdInputModel
            {
                Cc               = 1,
                Color            = 0,
                Condition        = Condition.New,
                Door             = Doors.Three,
                EuroStandart     = EuroStandart.Euro1,
                Extras           = "4x4",
                Fuel             = Fuel.Diesel,
                Gearbox          = Gearbox.Automatic,
                Hp               = 1,
                ImgsPaths        = GlobalConstants.DefaultImgCar,
                Km               = 100,
                Location         = Location.Sofia,
                Make             = Make.Audi,
                Model            = "test",
                Modification     = "test",
                MoreInformation  = "test test",
                Price            = 100,
                Type             = Types.Convertible,
                TypeOfVeichle    = TypeOfVeichle.Car,
                YearOfProduction = "01.1999",
            };

            await service.CreateAdAsync(inputModel, "1");

            var car = await carRepository.All().FirstOrDefaultAsync(x => x.Model == "test");

            var carId        = car.Id;
            var carByService = await service.GetCurrentCarAsync(carId);

            Assert.Same(car, carByService);
            Assert.Equal(car.Id, carByService.Id);
        }
예제 #2
0
        public async Task EditAdTests()
        {
            var options       = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString());
            var carRepository = new EfDeletableEntityRepository <Car>(new ApplicationDbContext(options.Options));

            var service = new AdService(carRepository);

            var inputModel = new CreateAdInputModel
            {
                Cc               = 1,
                Color            = 0,
                Condition        = Condition.New,
                Door             = Doors.Three,
                EuroStandart     = EuroStandart.Euro1,
                Extras           = "4x4",
                Fuel             = Fuel.Diesel,
                Gearbox          = Gearbox.Automatic,
                Hp               = 1,
                ImgsPaths        = GlobalConstants.DefaultImgCar,
                Km               = 100,
                Location         = Location.Sofia,
                Make             = Make.Audi,
                Model            = "test",
                Modification     = "test",
                MoreInformation  = "test test",
                Price            = 100,
                Type             = Types.Convertible,
                TypeOfVeichle    = TypeOfVeichle.Car,
                YearOfProduction = "01.1999",
            };
            await service.CreateAdAsync(inputModel, "1");

            var car = await carRepository.All().FirstOrDefaultAsync(x => x.Model == "test");

            var oldMake      = car.Make;
            var oldMoreInfo  = car.MoreInformation;
            var oldCc        = car.Cc;
            var editCC       = 3;
            var editMake     = Make.Bmw;
            var editMoreInfo = "edit test";
            var editAd       = new EditAddInputModel
            {
                Id               = car.Id,
                Cc               = editCC,
                Color            = car.Color,
                Door             = car.Door,
                EuroStandart     = car.EuroStandart,
                Extras           = car.Extras,
                Fuel             = car.Fuel,
                Gearbox          = car.Gearbox,
                Hp               = car.Horsepowers,
                Km               = car.Km,
                Location         = car.Location,
                Make             = editMake,
                Model            = car.Model,
                Modification     = car.Modification,
                MoreInformation  = editMoreInfo,
                Price            = car.Price,
                Type             = car.Type,
                Condition        = car.Condition,
                YearOfProduction = car.YearOfProduction.ToString("mm.yyyy"),
                TypeOfVeichle    = car.TypeOfVeichle,
            };
            var edittedCar = await service.EditAd(editAd);

            Assert.Equal(edittedCar.Make, editMake);
            Assert.Equal(edittedCar.Cc, editCC);
            Assert.Equal(edittedCar.MoreInformation, editMoreInfo);
            Assert.NotEqual(edittedCar.Make, oldMake);
            Assert.NotEqual(edittedCar.Cc, oldCc);
            Assert.NotEqual(edittedCar.MoreInformation, oldMoreInfo);
        }