コード例 #1
0
        public void Create_ThrowsException()
        {
            var repo = new RoomRepository();

            var result = repo.Create(1, null);

            Assert.That(result.Name, Is.EqualTo("Floating in a Void"));
        }
コード例 #2
0
        // Sort through Rooms to find next one
        public static int NextRoomID()
        {
            // Find vacant Rooms. If none, create one and add it to list
            List<int> roomIDs = new List<int>();

            vacantRoomInit:
            var allRooms = new RoomRepository().All().ToList();

            var vacantRoomsWithUsers = (from room in allRooms
                                        where Enumerable.Range(1, 4).Contains(UserProfileController.GetUserProfileCount(room.RoomID))
                                        select new { RoomID = room.RoomID }).ToList();

            var emptyRooms = (from room in allRooms
                                where UserProfileController.GetUserProfileCount(room.RoomID) == 0
                                select new { RoomID = room.RoomID }).ToList();

            if (vacantRoomsWithUsers.Count == 0 && emptyRooms.Count > 0)
            {
                // All rooms with users are full but an empty one exists, return empty room
                return emptyRooms.First().RoomID;
            }
            else if (vacantRoomsWithUsers.Count == 0 && emptyRooms.Count == 0)
            {
                // Create new Room, re-populate vacantRoomIDs or obtain new RoomID another way
                var roomRep = new RoomRepository();
                Room newRoom = new Room { Name = "Public Room" };

                roomRep.Create(newRoom);
                roomRep.SaveChanges();
                goto vacantRoomInit;
            }

            profileInit:
            // Change this to reflect online users only at deployment
            var allProfiles = new UserProfileRepository().All().ToList();

            var profiles = (from p in allProfiles.Where(p => Membership.GetUser(p.aspUserID).IsOnline)
                            where vacantRoomsWithUsers.Select(r => r.RoomID).Contains(p.RoomID) &&
                                  !VisitedRooms.Select(r => r.RoomID).Contains(p.RoomID)
                            select p).ToList();

            if (profiles.Count == 0)
            {
                VisitedRooms.Clear();
                goto profileInit;
            }

            // Obtain room with earliest JoinRoomTime
            var resultRoom = (from p in profiles
                              group p by p.RoomID into results
                              orderby results.Max(x => x.JoinRoomTime)
                              select new { RoomID = results.Key }).First();

            VisitedRooms.Add(new RoomRepository().GetById(resultRoom.RoomID));
            return resultRoom.RoomID;
        }
コード例 #3
0
        public async Task <CreateRoomEvent> Create(CreateRoomEvent roomData)
        {
            RoomModel room   = new RoomModel(roomData.Name);
            string    roomId = await _rooms.Create(room);

            return(new CreateRoomEvent()
            {
                Id = roomId
            });
        }
コード例 #4
0
ファイル: RoomController.cs プロジェクト: sbergot/DiceSharp
        async public Task <IActionResult> New()
        {
            var room = RoomRepository.Create();
            await RoomHelpers.WithRoomLock(room, () =>
            {
                User user = SessionManager.GetCurrentUser();
                room.State.Users.Add(user);
                room.State.Creator = user;
            });

            return(RedirectToAction("Index", new { roomId = room.Id }));
        }
コード例 #5
0
 public ActionResult CreateRoom([Bind(Include = "DormitoryId,Number")] Room room)
 {
     if (IsLoggedOn())
     {
         ViewBag.DormitoryId = new SelectList(dormitoryRepository.GetAll(), "ID", "Name", room.DormitoryId);
         if (roomRepository.Create((room)).ReasonPhrase == "Created")
         {
             return(RedirectToAction("Successful"));
         }
     }
     return(RedirectToAction("LoginForm", "Main"));
 }
コード例 #6
0
        public void CloseTest()
        {
            NpgsqlConnection _connection = new NpgsqlConnection(conectionStr);

            _connection.Open();

            IRoomRepository roomrepo = new RoomRepository(_connection, null);
            Room            r        = new Room(6);

            roomrepo.Create(r);

            roomrepo.Close(r);
            Assert.True(roomrepo.FindRoom(r.ID) == null);
        }
コード例 #7
0
        public void IsCreatable()
        {
            Random random   = new Random(DateTime.Now.Millisecond);
            Room   testRoom = new Room
            {
                ID          = random.Next(),
                DormitoryId = 2,
                Number      = random.Next()
            };
            HttpResponseMessage response = repository.Create(testRoom);
            string jsonContents          = response.Content.ReadAsStringAsync().Result;
            Room   createdRoom           = JsonConvert.DeserializeObject <Room>(jsonContents);

            Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Created, "Room creation test has failed.");
            Assert.Equals(testRoom, createdRoom);
        }
コード例 #8
0
        public void UpdateMaxPlayer()
        {
            NpgsqlConnection _connection = new NpgsqlConnection(conectionStr);

            _connection.Open();

            IRoomRepository roomrepo = new RoomRepository(_connection, null);
            Room            r        = new Room(6);

            roomrepo.Create(r);
            roomrepo.UpdateMax(r, 10);

            Room r2 = roomrepo.FindRoom(r.ID);

            Assert.Equal(10, r2.MaxUser);
        }
コード例 #9
0
 public Room Create(Room room) => _repository.Create(room);
コード例 #10
0
 public void DivideRooms(Room initialRoom, String newNumber)
 {
     initialRoom.RoomNumber = newNumber;
     _roomRepository.Create(initialRoom);
 }
コード例 #11
0
 public void Create(Room entity)
 {
     roomRepository.Create(entity);
 }
コード例 #12
0
        public void Create_ThrowsException_InvalidVnum()
        {
            var repo = new RoomRepository();

            Assert.Throws <ArgumentException>(() => repo.Create(0, null));
        }
コード例 #13
0
ファイル: Repository.Test.cs プロジェクト: renatoavila/hotel
        public void Full()
        {
            // 1 - cadastro das categorias
            ICategoryRepository categoryRepository = new CategoryRepository();

            Category categorySingle = new Category("Single", 230);

            categoryRepository.Create(categorySingle);

            Category categoryStandard = new Category("Standard", 310);

            categoryRepository.Create(categoryStandard);

            Category categoryLuxo = new Category("Luxo", 470);

            categoryRepository.Create(categoryLuxo);

            Assert.True(categoryRepository.Get().Count == 3);

            // 2 - cadastro do quarto

            IRoomRepository roomRepository = new RoomRepository();

            Room roomSingle01 = new Room("01", categorySingle);

            roomRepository.Create(roomSingle01);

            Room roomSingle02 = new Room("02", categorySingle);

            roomRepository.Create(roomSingle02);

            Room roomStandard03 = new Room("03", categoryStandard);

            roomRepository.Create(roomStandard03);

            Room roomStandard04 = new Room("04", categoryStandard);

            roomRepository.Create(roomStandard04);

            Room roomLuxo05 = new Room("05", categoryLuxo);

            roomRepository.Create(roomLuxo05);

            Room roomLuxo06 = new Room("05", categoryLuxo);

            roomRepository.Create(roomLuxo05);

            Assert.True(roomRepository.Get().Count == 6);

            // 3 - cadstro do hospede
            IHotelGuestRepository hotelGuestRepositoryRepository = new HotelGuestRepository();

            HotelGuest hotelGuest = new HotelGuest("João de Barro", "*****@*****.**", "000.111.222-33", "(19) 99999-9999");

            hotelGuestRepositoryRepository.Create(hotelGuest);

            Assert.True(hotelGuestRepositoryRepository.Get().Count == 1);

            // 4 - cadastro da reserva
            IBookingRepository bookingRepository = new BookingRepository();

            Booking booking = new Booking(hotelGuest, DateTime.Now.AddDays(1), DateTime.Now.AddDays(2), roomSingle01);

            bookingRepository.Create(booking);

            Assert.True(bookingRepository.Get().Count == 1);
        }