示例#1
0
        public async void CanCreateRoom()
        {
            DbContextOptions <HotelManagementDbContext> options =
                new DbContextOptionsBuilder <HotelManagementDbContext>
                    ().UseInMemoryDatabase("RoomAmenity").Options;

            using (HotelManagementDbContext context = new HotelManagementDbContext(options))
            {
                // arrange
                Room roomA = new Room();
                roomA.ID               = 1;
                roomA.Name             = "basic";
                roomA.RoomAmentitiesID = 1;


                // Act
                RoomManagementService Service = new RoomManagementService(context);
                await Service.CreateRoom(roomA);

                var result = context.Room.Any(h => h.Name == roomA.Name);


                // Assert
                Assert.True(result);
            }
        }
示例#2
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);
            }
        }
示例#3
0
        public async void CanDeleteRoom()
        {
            DbContextOptions <HotelManagementDbContext> options =
                new DbContextOptionsBuilder <HotelManagementDbContext>
                    ().UseInMemoryDatabase("DeleteRoom").Options;

            using (HotelManagementDbContext context = new HotelManagementDbContext(options))
            {
                // arrange
                Room roomA = new Room();
                roomA.ID               = 1;
                roomA.Name             = "basic";
                roomA.RoomAmentitiesID = 1;


                // Act
                RoomManagementService Service = new RoomManagementService(context);
                await Service.CreateRoom(roomA);

                Service.DeleteRoom(roomA);
                var result = context.Room.FirstOrDefault(m => m.ID == roomA.ID);


                // Assert
                Assert.Null(result);
            }
        }
示例#4
0
        public async void CanUpdateRoom()
        {
            DbContextOptions <HotelManagementDbContext> options =
                new DbContextOptionsBuilder <HotelManagementDbContext>
                    ().UseInMemoryDatabase("RoomAmenity").Options;

            using (HotelManagementDbContext context = new HotelManagementDbContext(options))
            {
                // arrange
                Room roomA = new Room();
                roomA.ID               = 1;
                roomA.Name             = "basic";
                roomA.RoomAmentitiesID = 1;


                // Act
                RoomManagementService Service = new RoomManagementService(context);
                await Service.CreateRoom(roomA);

                roomA.RoomAmentitiesID = 2;
                Service.UpdateRoom(roomA);



                // Assert
                Assert.Equal(2, roomA.RoomAmentitiesID);
            }
        }
示例#5
0
        public async void CanUpdateRoom()
        {
            DbContextOptions <AsyncInnDbContext> options = new DbContextOptionsBuilder <AsyncInnDbContext>().UseInMemoryDatabase("UpdateRoom").Options;

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

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

                room.Layout = Layout.OneBedroom;
                await roomManagementService.UpdateRoom(room);

                var result = context.Rooms.FirstOrDefault(r => r.ID == room.ID);

                // Assert
                Assert.Equal(room, result);
            }
        }
示例#6
0
        public async void CreateRoomWorksAgain()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("CreateRoom").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // arrange
                Room room = new Room();
                room.ID     = 2;
                room.Name   = "quillers";
                room.Layout = 1;

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

                await service.CreateRoom(room);

                var created = context.Rooms.FirstOrDefault(r => r.ID == room.ID);

                // Assert
                Assert.Equal(room, created);
            }
        }
示例#7
0
        public async void UpdateRoomWorks()
        {
            DbContextOptions <AsyncInnDbContext> options =
                new DbContextOptionsBuilder <AsyncInnDbContext>
                    ().UseInMemoryDatabase("UpdateRoom").Options;

            using (AsyncInnDbContext context = new AsyncInnDbContext(options))
            {
                // arrange
                Room room = new Room();
                room.ID     = 1;
                room.Name   = "quiller";
                room.Layout = 1;

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

                await service.CreateRoom(room);

                room.Name = "quillers";
                await service.UpdateRoom(room);

                // Assert
                Assert.Equal("quillers", room.Name);
            }
        }