Exemple #1
0
        public async Task EditShouldDoNothingOnEmptyCollection()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb6")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id = 1,
            };
            await service.Edit(inputModel);

            Assert.Equal(0, service.GetAll().Count);
        }
Exemple #2
0
        public async Task EditShouldUpdateEntityWithExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb8")
                          .Options;
            var dbContext  = new ApplicationDbContext(options);
            var newVehicle = new Vehicle
            {
                Id                = 1,
                Make              = "Mercedes",
                Model             = "S500",
                VIN               = "WDB2221KZ8N654321",
                NumberPlate       = "CA1111PA",
                FirstRegistration = new DateTime(2019, 1, 1),
                Type              = VehicleType.Truck,
            };

            dbContext.Vehicles.Add(newVehicle);
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id                = 1,
                Make              = "BMW",
                Model             = "760Li",
                VIN               = "WBNX6X6D30300G980",
                NumberPlate       = "CA2222PA",
                FirstRegistration = "31-12-2018",
                Type              = "Car",
            };
            await service.Edit(inputModel);

            Assert.Equal("BMW", service.GetById(1).Make);
            Assert.Equal("760Li", service.GetById(1).Model);
            Assert.Equal("WBNX6X6D30300G980", service.GetById(1).VIN);
            Assert.Equal("CA2222PA", service.GetById(1).NumberPlate);
            var expectedDate = new DateTime(2018, 12, 31);

            Assert.Equal <DateTime>(expectedDate, service.GetById(1).FirstRegistration);
            Assert.Equal <VehicleType>(VehicleType.Car, service.GetById(1).Type);
        }
Exemple #3
0
        public async Task EditShouldDoNothingWithNonExistingId()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "MyTestDb7")
                          .Options;
            var dbContext = new ApplicationDbContext(options);

            dbContext.Vehicles.Add(new Vehicle {
                Id = 1, Make = "Mercedes"
            });
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Vehicle>(dbContext);
            var service    = new VehiclesService(repository);
            var inputModel = new VehicleEditViewModel
            {
                Id   = 2,
                Make = "BMW",
            };
            await service.Edit(inputModel);

            Assert.Equal("Mercedes", service.GetById(1).Make);
        }