Example #1
0
        public async Task EditShouldEditEvent()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Event_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var _event = new Event()
            {
                Name        = "Formula 1",
                Description = "asd",
                Id          = Guid.NewGuid().ToString(),
                Date        = DateTime.Now
            };

            var eventService = new Services.GeneralService.EventService(dbContext);
            await eventService.CreateEvent(_event, "");

            await dbContext.SaveChangesAsync();

            _event.Name = "Formula";

            await eventService.EditEvent(_event);

            await dbContext.SaveChangesAsync();

            var result = dbContext.Events.ToList();

            Assert.AreEqual("Formula", result.First().Name);
        }
        public async Task DeleteRoomShouldDeleteRoom()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Hotel_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var room = new Room()
            {
                Bed           = "test bed",
                Id            = Guid.NewGuid().ToString(),
                Floor         = 1,
                MaximumGuests = 1,
                PicturePath   = "",
                PricePerNight = 1,
                RoomNumber    = 1,
                RoomType      = Models.Enums.RoomType.Double,
                View          = "test view"
            };

            var hotelService = new Services.HotelService.HotelService(dbContext);
            await hotelService.CreateRoom(room, "");

            await dbContext.SaveChangesAsync();

            await hotelService.DeleteRoom(room.Id);

            await dbContext.SaveChangesAsync();

            var result = dbContext.Rooms.ToList();

            Assert.AreEqual(0, result.Count);
        }
        public async Task GetBookingByIdShouldGetCorrectBooking()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Hotel_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var booking = new Booking()
            {
                Arrival    = DateTime.Now,
                CheckOut   = DateTime.Now,
                Breakfast  = true,
                BookTime   = DateTime.Now,
                Comment    = "",
                CustomerId = Guid.NewGuid().ToString(),
                Id         = Guid.NewGuid().ToString(),
                Nights     = 0,
                People     = 1,
                RoomNumber = 1,
                RoomType   = Models.Enums.RoomType.Double
            };

            var hotelService = new Services.HotelService.HotelService(dbContext);
            await hotelService.CreateNewBooking(booking, booking.CustomerId);

            await dbContext.SaveChangesAsync();

            var result = hotelService.GetBookingById(booking.Id).Result;

            Assert.AreEqual(booking.Id, result.Id);
        }
        public async Task GetAllDishesShouldReturnAllDishes()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Restaurant_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var dishOne = new Dish()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "test1"
            };

            var dishTwo = new Dish()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "test2"
            };


            var restaurantService = new Services.RestaurantServices.RestaurantService(dbContext);
            await restaurantService.AddDish(dishOne, "", "");

            await restaurantService.AddDish(dishTwo, "", "");

            await dbContext.SaveChangesAsync();

            var result = dbContext.Dishes.ToList();

            Assert.AreEqual(2, result.Count);
        }
        public async Task DeleteIngredientShouldDeleteIngredient()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Restaurant_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var ingredient = new Ingredient()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = "test"
            };


            var restaurantService = new Services.RestaurantServices.RestaurantService(dbContext);
            await restaurantService.AddIngredient(ingredient);

            await dbContext.SaveChangesAsync();

            await restaurantService.DeleteIngredient(ingredient.Id);

            var result = dbContext.Ingredients.ToList();

            Assert.AreEqual(0, result.Count);
        }
        public async Task UpdateBookingShouldUpdateBookingCorrectly()
        {
            var options = new DbContextOptionsBuilder <AspHolidayAndSpaDbContext>()
                          .UseInMemoryDatabase(databaseName: "Hotel_Database")
                          .Options;

            var dbContext = new AspHolidayAndSpaDbContext(options);

            var booking = new Booking()
            {
                Arrival    = DateTime.Now,
                CheckOut   = DateTime.Now,
                Breakfast  = true,
                BookTime   = DateTime.Now,
                Comment    = "",
                CustomerId = Guid.NewGuid().ToString(),
                Id         = Guid.NewGuid().ToString(),
                Nights     = 0,
                People     = 1,
                RoomNumber = 1,
                RoomType   = Models.Enums.RoomType.Double
            };

            var room = new Room()
            {
                Bed           = "test bed",
                Id            = Guid.NewGuid().ToString(),
                Floor         = 1,
                MaximumGuests = 1,
                PicturePath   = "",
                PricePerNight = 1,
                RoomNumber    = 1,
                RoomType      = Models.Enums.RoomType.Double,
                View          = "test view"
            };

            var hotelService = new Services.HotelService.HotelService(dbContext);
            await hotelService.CreateNewBooking(booking, booking.CustomerId);

            await dbContext.SaveChangesAsync();

            booking.People = 2;
            await hotelService.CreateRoom(room, "");

            await hotelService.UpdateBooking(booking);

            await dbContext.SaveChangesAsync();

            var result = dbContext.Bookings.ToList();

            Assert.AreEqual(booking.People, result.First().People);
        }
Example #7
0
 public HotelService(
     AspHolidayAndSpaDbContext db
     )
 {
     this.db = db;
 }
 public EventService(
     AspHolidayAndSpaDbContext db
     )
 {
     this.db = db;
 }
 public RestaurantService(
     AspHolidayAndSpaDbContext db
     )
 {
     this.db = db;
 }