コード例 #1
0
        public void EditAdWithWrongIdShouldRedturnNullReferenceException()
        {
            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 editAd  = new EditAddInputModel
            {
                Id               = "fakeId",
                Cc               = 0,
                Color            = Color.Beige,
                Door             = Doors.Five,
                EuroStandart     = EuroStandart.Euro5,
                Extras           = "asd",
                Fuel             = Fuel.Diesel,
                Gearbox          = Gearbox.Automatic,
                Hp               = 2,
                Km               = 2,
                Location         = Location.Sofia,
                Make             = Make.AstonMartin,
                Model            = "tesr",
                Modification     = "test",
                MoreInformation  = "test",
                Price            = 33,
                Type             = Types.Combi,
                Condition        = Condition.ForParts,
                YearOfProduction = "03.1999",
                TypeOfVeichle    = TypeOfVeichle.All,
            };

            Assert.ThrowsAsync <NullReferenceException>(async() => await service.EditAd(editAd));
        }
コード例 #2
0
        public async Task Edit()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Edit_Ad")
                          .Options;

            var user = new AgencyProfile {
                Id = "agencyId", Username = "******"
            };
            var ad = new Ad {
                Id = 1, Title = "AAAAAAAA"
            };
            var adTitle = ad.Title;
            int count;

            using (var db = new ApplicationDbContext(options))
            {
                db.AgenciesProfiles.Add(user);
                db.Ads.Add(ad);
                db.SaveChanges();
                AdService service = new AdService(db);

                await service.EditAd(1, "Titleeeeeeeeeeeeee", "Description", "Residental",
                                     "65", "Location", "20", "A");

                count = db.Ads.Count();
            }

            Assert.NotEqual(adTitle, ad.Title);
        }
コード例 #3
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);
        }