Beispiel #1
0
        public void DeleteLocationShould_ReturnFalseIfTheLocationIsReturnPlaceForOrder()
        {
            var options = new DbContextOptionsBuilder <CarRentalDbContext>()
                          .UseInMemoryDatabase(databaseName: "CarRental_Database_DeleteLocationWithOrders")
                          .Options;
            var dbContext = new CarRentalDbContext(options);

            var locationsService = new LocationsService(dbContext);

            var location = new Location
            {
                Name = locationNameOne
            };

            locationsService.CreateLocation(location);

            var order = new Order
            {
                CarId             = 1,
                ApplicationUserId = Guid.NewGuid().ToString(),
                PickUpLocationId  = 1,
                ReturnLocationId  = 1,
                Price             = 100,
                RentStart         = DateTime.UtcNow.Date,
                RentEnd           = DateTime.UtcNow.Date.AddDays(2)
            };

            dbContext.Orders.Add(order);

            var result = locationsService.DeleteLocation(locationNameTwo).GetAwaiter().GetResult();

            Assert.False(result);
        }
Beispiel #2
0
        public void DeleteLocationShould_ReturnFalseIfTheLocationIsTheDefaultForTheSite()
        {
            var options = new DbContextOptionsBuilder <CarRentalDbContext>()
                          .UseInMemoryDatabase(databaseName: "CarRental_Database_DeleteLocationDefault")
                          .Options;
            var dbContext = new CarRentalDbContext(options);

            var locationsService = new LocationsService(dbContext);

            var location = new Location
            {
                Name = locationNameOne
            };

            locationsService.CreateLocation(location);

            var result = locationsService.DeleteLocation(locationNameTwo).GetAwaiter().GetResult();

            Assert.False(result);
        }
Beispiel #3
0
        public void DeleteLocationShould_DeleteEmptyLocation()
        {
            var options = new DbContextOptionsBuilder <CarRentalDbContext>()
                          .UseInMemoryDatabase(databaseName: "CarRental_Database_DeleteLocation")
                          .Options;
            var dbContext = new CarRentalDbContext(options);

            var locationsService = new LocationsService(dbContext);

            var location = new Location
            {
                Name = locationNameTwo
            };

            locationsService.CreateLocation(location);

            locationsService.DeleteLocation(locationNameTwo);

            var result = dbContext.Locations.FirstOrDefault(x => x.Name == locationNameOne);

            Assert.Null(result);
        }