Ejemplo n.º 1
0
        public async void HotelRoomUpdateTest()
        {
            using (AsyncInnDbContext context = new AsyncInnDbContext(optionsHR))
            {
                await context.Database.EnsureDeletedAsync();

                hr = new HotelRoom
                {
                    Hotel = new Hotel()
                    {
                        Name = "Everett"
                    },
                    Room = new Room()
                    {
                        Name = "Ocean View"
                    }
                };

                context.HotelRooms.Add(hr);
                await context.SaveChangesAsync();

                HotelRoom hotelRoom = await context.HotelRooms.FirstOrDefaultAsync(x => x.Hotel.Name == "Everett");

                hotelRoom.Hotel.Name = "Bellevue";
                context.HotelRooms.Update(hotelRoom);
                await context.SaveChangesAsync();

                hotelRoom = await context.HotelRooms.FirstOrDefaultAsync(x => x.Hotel.Name == "Bellevue");

                Assert.True(hotelRoom.Hotel.Name == "Bellevue");
            }
        }
Ejemplo n.º 2
0
        public async void CreateHotelWorksAgain()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("CreateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // arrange
                Hotel hotel = new Hotel();
                hotel.ID      = 2;
                hotel.Name    = "quillers";
                hotel.Address = "Seattle";
                hotel.Phone   = "206-555-5551";

                // Act
                HotelManagementService service = new HotelManagementService(context);

                await service.CreateHotel(hotel);

                var created = context.Hotels.FirstOrDefault(h => h.ID == hotel.ID);

                // Assert
                Assert.Equal(hotel, created);
            }
        }
Ejemplo n.º 3
0
        public async void CanDeleteHotel()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("DeleteHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // Arrange
                Hotel hotel = new Hotel();
                hotel.ID        = 1;
                hotel.Name      = "test";
                hotel.Address   = "123 fake st";
                hotel.Phone     = "555-555-5555";
                hotel.RoomCount = 0;

                //Act
                HotelManagementService hotelServ = new HotelManagementService(context);

                await hotelServ.CreateHotel(hotel);

                hotelServ.DeleteHotel(hotel.ID);

                var result = context.Hotels.FirstOrDefault(c => c.ID == hotel.ID);
                //Assert
                Assert.Null(result);
            }
        }
Ejemplo n.º 4
0
        public async void CanDeleteAmenity()
        {
            Microsoft.EntityFrameworkCore.DbContextOptions <AsyncInnDbContext> options = new
                                                                                         DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase
                                                                                             ("CreateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext
                                                   (options))
            {
                //Arrange
                Amenities amenities = new Amenities();
                amenities.ID   = 1;
                amenities.Name = "Iron";

                //Act
                AmenityManagerService amenityService = new AmenityManagerService(context);
                await amenityService.CreateAmenity(amenities);

                await amenityService.DeleteAmenity(1);

                var result = await context.Amenities.FirstOrDefaultAsync(h => h.ID == amenities.ID);

                Assert.Null(result);
            }
        }
Ejemplo n.º 5
0
        public async void DeleteHotelWorksAgain()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("DeleteHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                Hotel hotel = new Hotel();
                hotel.ID      = 1;
                hotel.Name    = "quillers";
                hotel.Address = "Seattle";
                hotel.Phone   = "206-555-5552";

                // Act
                HotelManagementService service = new HotelManagementService(context);

                await service.CreateHotel(hotel);

                await service.DeleteHotel(1);

                var deleted = context.Hotels.FirstOrDefault(r => r.ID == hotel.ID);

                // Assert
                Assert.Null(deleted);
            }
        }
Ejemplo n.º 6
0
        public async void CanCreateAmenityAndSaveToDatabase()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>()
                                                           .UseInMemoryDatabase("CanCreateAmenityAndSaveToDatabase")
                                                           .Options;

            using AsyncInnDbContext context = new AsyncInnDbContext(options);

            AmenityManager service = new AmenityManager(context);

            var dto = new AmenityDto()
            {
                Name = "Test"
            };

            Assert.Equal(0, context.Amenities.CountAsync().Result);

            var result = await service.CreateAmenity(dto);

            var actual = context.Amenities.FindAsync(result.Id).Result;

            Assert.Equal(1, await context.Amenities.CountAsync());
            Assert.IsType <Amenity>(actual);
            Assert.Equal(1, actual.Id);
            Assert.Equal("Test", actual.Name);
        }
Ejemplo n.º 7
0
        public async void CanCreateAmenityAndSaveMultipleToDatabase()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>()
                                                           .UseInMemoryDatabase("CanCreateAmenityAndSaveMultipleToDatabase")
                                                           .Options;

            using AsyncInnDbContext context = new AsyncInnDbContext(options);

            AmenityManager service = new AmenityManager(context);

            Assert.Equal(0, context.Amenities.CountAsync().Result);

            var resultOne = await service.CreateAmenity(new AmenityDto()
            {
                Name = "Test One"
            });

            var resultTwo = await service.CreateAmenity(new AmenityDto()
            {
                Name = "Test Two"
            });

            var actualOne = await context.Amenities.FindAsync(resultOne.Id);

            var actualTwo = await context.Amenities.FindAsync(resultTwo.Id);

            Assert.Equal(2, await context.Amenities.CountAsync());
            Assert.IsType <Amenity>(actualOne);
            Assert.Equal(1, actualOne.Id);
            Assert.Equal("Test One", actualOne.Name);
            Assert.IsType <Amenity>(actualTwo);
            Assert.Equal(2, actualTwo.Id);
            Assert.Equal("Test Two", actualTwo.Name);
        }
Ejemplo n.º 8
0
        public async void CanEdiAmenity()
        {
            /// Can edit an existing amenity
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("UpdateAemnity").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                Amenities amen = new Amenities();
                amen.ID   = 72;
                amen.Name = "Poker";

                AmenitiesManagementServices amenServices = new AmenitiesManagementServices(context);
                await amenServices.CreateAmenity(amen);

                Amenities upAmen = await amenServices.GetAmenities(amen.ID);

                upAmen.Name = "Black-jack";

                await amenServices.UpdateAmenity(upAmen);

                var result = context.Amenities.FirstOrDefault(ho => ho.ID == amen.ID);

                Assert.Equal("Black-jack", result.Name);
            }
        }
Ejemplo n.º 9
0
        public async void CanUpdateHotelRoom()
        {
            /// Can update an existing hotel room
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("UpdateHotelRoom").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                HotelRoom hoRoom = new HotelRoom();
                hoRoom.HotelID     = 90;
                hoRoom.RoomNumber  = 87;
                hoRoom.RoomID      = 81;
                hoRoom.Rate        = 350;
                hoRoom.PetFriendly = true;

                HotelRoomController hotController = new HotelRoomController(context);
                await hotController.Create(hoRoom);

                HotelRoom upRoom = hoRoom;
                upRoom.HotelID     = 90;
                upRoom.RoomNumber  = 87;
                upRoom.RoomID      = 81;
                upRoom.Rate        = 250;
                upRoom.PetFriendly = true;

                await hotController.Edit(90, 87, upRoom);

                var result = await context.HotelRoom.FirstOrDefaultAsync(ho => ho.HotelID == hoRoom.HotelID && ho.RoomNumber == hoRoom.RoomNumber);

                Assert.Equal(250, result.Rate);
            }
        }
Ejemplo n.º 10
0
        public async void CanGetAmenitys()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("GetAmenitys").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                Amenities amenity = new Amenities();
                amenity.ID   = 1;
                amenity.Name = "test";

                Amenities amenity2 = new Amenities();
                amenity2.ID   = 2;
                amenity2.Name = "test";

                AmenitiesService amenitiesService = new AmenitiesService(context);



                await amenitiesService.CreateAmenity(amenity);

                await amenitiesService.CreateAmenity(amenity2);

                var roomsList = await amenitiesService.GetAmenities();

                var rooms = roomsList.ToString();

                List <Amenities> resultsList = new List <Amenities>();
                resultsList.Add(amenity);
                resultsList.Add(amenity2);
                var results = resultsList.ToString();

                Assert.Equal(results, rooms);
            }
        }
Ejemplo n.º 11
0
        public UserService(UserManager <ApplicationUser> userManager, SignInManager <ApplicationUser> signInManager, AsyncInnDbContext context)

        {
            _context       = context;
            _userManager   = userManager;
            _signInManager = signInManager;
        }
Ejemplo n.º 12
0
        public async void RoomAmenitiesDeleteTest()
        {
            using (AsyncInnDbContext context = new AsyncInnDbContext(optionsRA))
            {
                await context.Database.EnsureDeletedAsync();

                ra = new RoomAmenities
                {
                    Amenities = new Amenities()
                    {
                        Name = "Microwave"
                    },
                    Room = new Room()
                    {
                        Name = "Ocean View"
                    }
                };

                context.RoomAmenities.Add(ra);
                await context.SaveChangesAsync();

                RoomAmenities roomAmenities = await context.RoomAmenities.FirstOrDefaultAsync(x => x.Amenities.Name == "Microwave");

                context.RoomAmenities.Remove(roomAmenities);
                await context.SaveChangesAsync();

                var allRoomAmenities = await context.RoomAmenities.ToListAsync();

                Assert.DoesNotContain(roomAmenities, allRoomAmenities);
            }
        }
Ejemplo n.º 13
0
        public async void RoomAmenitiesUpdateTest()
        {
            using (AsyncInnDbContext context = new AsyncInnDbContext(optionsRA))
            {
                await context.Database.EnsureDeletedAsync();

                ra = new RoomAmenities
                {
                    Amenities = new Amenities()
                    {
                        Name = "Microwave"
                    },
                    Room = new Room()
                    {
                        Name = "Ocean View"
                    }
                };

                context.RoomAmenities.Add(ra);
                await context.SaveChangesAsync();

                RoomAmenities roomAmenities = await context.RoomAmenities.FirstOrDefaultAsync(x => x.Amenities.Name == "Microwave");

                roomAmenities.Amenities.Name = "Teapot";
                context.RoomAmenities.Update(roomAmenities);
                await context.SaveChangesAsync();

                roomAmenities = await context.RoomAmenities.FirstOrDefaultAsync(x => x.Amenities.Name == "Teapot");

                Assert.True(roomAmenities.Amenities.Name == "Teapot");
            }
        }
Ejemplo n.º 14
0
        public async void HotelRoomDeleteTest()
        {
            using (AsyncInnDbContext context = new AsyncInnDbContext(optionsHR))
            {
                await context.Database.EnsureDeletedAsync();

                hr = new HotelRoom
                {
                    Hotel = new Hotel()
                    {
                        Name = "Everett"
                    },
                    Room = new Room()
                    {
                        Name = "Ocean View"
                    }
                };

                context.HotelRooms.Add(hr);
                await context.SaveChangesAsync();

                HotelRoom hotelRoom = await context.HotelRooms.FirstOrDefaultAsync(x => x.Hotel.Name == "Everett");

                context.HotelRooms.Remove(hotelRoom);
                await context.SaveChangesAsync();

                var allHotelRoom = await context.HotelRooms.ToListAsync();

                Assert.DoesNotContain(hotelRoom, allHotelRoom);
            }
        }
Ejemplo n.º 15
0
        public async void CanUpdateHotelRoomsFromDb()
        {
            // setup our db context
            // set value
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("GetHotelRoomsUpdateFromDb")
                .Options;
            HotelRoom hotelRoom = new HotelRoom();

            // UPDATE: use a clean context instance for test
            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                hotelRoom.RoomNumber = 999;
                context.Update(hotelRoom);
                context.SaveChanges();
            }

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                var entity = await context.HotelRooms.FirstOrDefaultAsync(x => x.RoomNumber == 999);

                Assert.Equal(999, entity.RoomNumber);
            }
        }
Ejemplo n.º 16
0
        public async void DeleteAmenityDB()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("DeleteAmenity")
                .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                //create amenity and assign values
                Amenity a = new Amenity();
                a.Name = "Air Conditioning";
                context.Amenity.Add(a);
                context.SaveChanges();

                var amenity = await context.Amenity.FirstOrDefaultAsync(x => x.Name == a.Name);

                int id = amenity.ID;

                context.Amenity.Remove(amenity);
                await context.SaveChangesAsync();

                var deletedAmenity = await context.Amenity.FirstOrDefaultAsync(x => x.ID == id);

                //assert db entry
                Assert.Null(deletedAmenity);
            }
        }
Ejemplo n.º 17
0
        public async void CanUpdateRoomAmenitiesFromDb()
        {
            // setup our db context
            // set value
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("GetRoomAmenitiesUpdateFromDb")
                .Options;
            RoomAmenities roomAmenities = new RoomAmenities();

            // UPDATE: use a clean context instance for test
            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                roomAmenities.RoomId = 999;
                context.Update(roomAmenities);
                context.SaveChanges();
            }

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                var entity = await context.RoomAmenities.FirstOrDefaultAsync(x => x.RoomId == 999);

                Assert.Equal(999, entity.RoomId);
            }
        }
Ejemplo n.º 18
0
        public async void DeleteHotelDB()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("DeleteHotel")
                .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                //create hotel and assign values
                Hotel h = new Hotel();
                h.Name = "Twin Farms";
                context.Hotels.Add(h);
                context.SaveChanges();

                var hotel = await context.Hotels.FirstOrDefaultAsync(x => x.Name == h.Name);

                int id = hotel.ID;

                context.Hotels.Remove(hotel);
                await context.SaveChangesAsync();

                var deletedHotel = await context.Hotels.FirstOrDefaultAsync(x => x.ID == id);

                // assert db entry
                Assert.Null(deletedHotel);
            }
        }
Ejemplo n.º 19
0
        public async void CanUpdateAmenityFromDatabase()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>()
                                                           .UseInMemoryDatabase("CanUpdateAmenityFromDatabase")
                                                           .Options;

            using AsyncInnDbContext context = new AsyncInnDbContext(options);

            AmenityManager service = new AmenityManager(context);

            _ = await service.CreateAmenity(new AmenityDto()
            {
                Name = "Test One"
            });

            await service.UpdateAmenity(new AmenityDto()
            {
                Id = 1, Name = "Test Two"
            });

            var actual = await service.GetAmenity(1);

            Assert.Equal(1, await context.Amenities.CountAsync());
            Assert.NotEqual("Test One", actual.Name);
            Assert.Equal("Test Two", actual.Name);
        }
Ejemplo n.º 20
0
        public async void DeleteRoomDB()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("DeleteRoom")
                .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                //create hotel and assign values
                Room r = new Room();
                r.Name = "Single";
                context.Rooms.Add(r);
                context.SaveChanges();

                var room = await context.Rooms.FirstOrDefaultAsync(x => x.Name == r.Name);

                int id = room.ID;

                context.Rooms.Remove(room);
                await context.SaveChangesAsync();

                var deletedRoom = await context.Rooms.FirstOrDefaultAsync(x => x.ID == id);

                //assert db entry
                Assert.Null(deletedRoom);
            }
        }
Ejemplo n.º 21
0
        public async void CanDeleteHotel()
        {
            Microsoft.EntityFrameworkCore.DbContextOptions <AsyncInnDbContext> options = new
                                                                                         DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase
                                                                                             ("CreateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext
                                                   (options))
            {
                //Arrange
                Hotel hotel = new Hotel();
                hotel.ID   = 1;
                hotel.Name = "Dotnet";

                //Act
                HotelManagementService hotelServices = new HotelManagementService(context);
                await hotelServices.CreateHotel(hotel);

                await hotelServices.DeleteHotel(1);

                var result = context.Hotels.FirstOrDefault(h => h.HotelRoom == h.HotelRoom);

                Assert.Null(result);
            }
        }
Ejemplo n.º 22
0
        public async void CreateHotelRoomDB()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("CreateHotelRoom")
                .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                //create room, create hotel, create
                //hotel room
                Hotel h = new Hotel();
                h.Name = "Single";
                Room r = new Room();
                r.Name = "King";
                context.Add(h);
                context.Add(r);
                context.SaveChanges();

                var hotel = context.Hotels.FirstOrDefaultAsync(x => x.Name == h.Name);
                var room  = context.Rooms.FirstOrDefaultAsync(x => x.Name == r.Name);

                HotelRoom hr = new HotelRoom();
                hr.HotelID     = hotel.Id;
                hr.RoomID      = room.Id;
                hr.PetFriendly = true;
                context.HotelRooms.Add(hr);
                context.SaveChanges();

                var hotelroom = await context.HotelRooms.FirstOrDefaultAsync(x => x.HotelID == hr.HotelID);

                //assert db entry
                Assert.Equal(hotelroom.RoomID, hr.RoomID);
            }
        }
Ejemplo n.º 23
0
        public async void CanUpdateRoom()
        {
            Microsoft.EntityFrameworkCore.DbContextOptions <AsyncInnDbContext> options = new
                                                                                         DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase
                                                                                             ("CreateRoom").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext
                                                   (options))
            {
                //Arrange
                Room room = new Room();
                room.ID         = 1;
                room.Name       = "Iron";
                room.RoomLayout = Layout.OneBedroom;

                room.RoomLayout = Layout.TwoBedroom;

                //Act
                RoomManagementService roomService = new RoomManagementService(context);
                await roomService.CreateRoom(room);

                await roomService.UpdateRoom(room);

                var result = await context.Room.FirstOrDefaultAsync(h => h.ID == room.ID);

                Assert.Equal(room, result);
            }
        }
Ejemplo n.º 24
0
        public async void CreateRoomAmenityDB()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>()
                .UseInMemoryDatabase("CreateRoomAmenity")
                .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // create room, create amenity, create
                //room amenity
                Amenity a = new Amenity();
                a.Name = "Air Conditioning";
                Room r = new Room();
                r.Name = "Mii amo";
                context.Add(a);
                context.Add(r);
                context.SaveChanges();

                var amenity = context.Amenity.FirstOrDefaultAsync(x => x.Name == a.Name);
                var room    = context.Rooms.FirstOrDefaultAsync(x => x.Name == r.Name);

                RoomAmenity ra = new RoomAmenity();
                ra.AmenitiesID = amenity.Id;
                ra.RoomID      = room.Id;
                context.RoomAmenity.Add(ra);
                context.SaveChanges();

                var roomamenity = await context.RoomAmenity.FirstOrDefaultAsync(x => x.AmenitiesID == ra.AmenitiesID);

                //assert db entry
                Assert.Equal(roomamenity.RoomID, ra.RoomID);
            }
        }
Ejemplo n.º 25
0
        public async void UpdateHotelWorks()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("UpdateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // arrange
                Hotel hotel = new Hotel();
                hotel.ID      = 1;
                hotel.Name    = "quiller";
                hotel.Address = "Seattle";
                hotel.Phone   = "206-555-5551";

                // Act
                HotelManagementService service = new HotelManagementService(context);

                await service.CreateHotel(hotel);

                hotel.Address = "Tacoma";
                await service.Updatehotel(hotel);

                // Assert
                Assert.Equal("Tacoma", hotel.Address);
            }
        }
Ejemplo n.º 26
0
        public async void CanEditRoom()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("UpdateRoom").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                Room room = new Room();
                room.ID     = 62;
                room.Name   = "Hawks";
                room.Layout = Layouts.OneBedroom;

                RoomManagementServices roomService = new RoomManagementServices(context);

                await roomService.CreateRoom(room);

                Room upRoom = await roomService.GetRooms(room.ID);

                upRoom.Layout = Layouts.TwoBedroom;

                await roomService.UpdateRooms(upRoom);

                var result = context.Room.FirstOrDefault(ho => ho.ID == room.ID);

                Assert.Equal(Layouts.TwoBedroom, result.Layout);
            }
        }
Ejemplo n.º 27
0
        public async void CanReadHotel()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("CreateHotel").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // Arrange
                Hotel hotel = new Hotel();
                hotel.ID        = 1;
                hotel.Name      = "test";
                hotel.Address   = "123 fake st";
                hotel.Phone     = "555-555-5555";
                hotel.RoomCount = 0;

                //Act
                HotelManagementService hotelServ = new HotelManagementService(context);

                await hotelServ.CreateHotel(hotel);

                var result = await hotelServ.GetHotel(hotel.ID);

                //Assert
                Assert.Equal(hotel, result);
            }
        }
Ejemplo n.º 28
0
        public async void CanSaveHotelRoomInDB()
        {
            DbContextOptions <AsyncInnDbContext> options = new
                                                           DbContextOptionsBuilder <AsyncInnDbContext>()
                                                           .UseInMemoryDatabase("SavingHotelRoom")
                                                           .Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                HotelRoom savehotelroom = new HotelRoom();
                savehotelroom.HotelID     = 1;
                savehotelroom.RoomID      = 1;
                savehotelroom.PetFriendly = false;
                savehotelroom.Rate        = 10;
                savehotelroom.RoomNumber  = 100;


                context.HotelRoom.Add(savehotelroom);
                await context.SaveChangesAsync();

                HotelRoom result = await context.HotelRoom.FirstOrDefaultAsync(x => x.PetFriendly == savehotelroom.PetFriendly);

                Assert.False(result.PetFriendly);
            }
        }
Ejemplo n.º 29
0
        public async void CanDeleteConfiguration()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("DeleteConfiguration").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // Arrange
                Room room = new Room();
                room.ID           = 1;
                room.Name         = "test";
                room.Layout       = Layout.OneBedroom;
                room.AmenityCount = 5;

                //Act
                ConfigurationManagementService roomServ = new ConfigurationManagementService(context);

                await roomServ.CreateConfiguration(room);

                roomServ.DeleteConfiguration(room.ID);

                var result = context.Rooms.FirstOrDefault(r => r.ID == room.ID);
                //Assert
                Assert.Null(result);
            }
        }
Ejemplo n.º 30
0
        public async void RoomUpdateTest()
        {
            using (AsyncInnDbContext context = new AsyncInnDbContext(optionsR))
            {
                await context.Database.EnsureDeletedAsync();

                r = new Room
                {
                    ID   = 3,
                    Name = "Ocean Room"
                };

                context.Rooms.Add(r);
                await context.SaveChangesAsync();

                Room Room = await context.Rooms.FirstOrDefaultAsync(x => x.ID == 3);

                Room.Name = "Cupid Special";
                context.Rooms.Update(Room);
                await context.SaveChangesAsync();

                Room = await context.Rooms.FirstOrDefaultAsync(x => x.Name == "Cupid Special");

                Assert.True(Room.Name == "Cupid Special");
            }
        }