Пример #1
0
        public void CanAddUserToRoom()
        {
            var room              = new Room(0, TestHelper.RoomName, new DateTime(2000, 12, 12));
            var account1          = TestHelper.AccountMock();
            var account2          = TestHelper.AccountMock();
            var accountRepository = new AccountRepository();
            var roomRepository    = new RoomRepository();

            roomRepository.Add(room);

            accountRepository.Add(account1);
            accountRepository.Add(account2);

            room.Add(account1);
            room.Add(account2);

            roomRepository.Add(room);

            var  roomRepository2 = new RoomRepository();
            Room result          = roomRepository2.GetRoom(room.Id);

            Assert.AreEqual(2, result.Users.Count());


            var rooms = roomRepository2.GetRooms(account1.Id);

            Assert.AreEqual(1, rooms.Count());
        }
Пример #2
0
        private void roomRepositoryTest()
        {
            var         _roomRepository = new RoomRepository();
            List <Room> rooms           = new List <Room>();

            _roomRepository.WriteAll(rooms);

            Room r = new Room();

            r.RoomType = Model.RoomType.examinationRoom;
            _roomRepository.Add(r);

            r          = new Room();
            r.RoomType = Model.RoomType.operationRoom;
            _roomRepository.Add(r);

            rooms = _roomRepository.GetAll();

            _roomRepository.Update(r);

            rooms = _roomRepository.GetAll();

            _roomRepository.Remove(0);

            rooms = _roomRepository.GetAll();
        }
        public void GetComponentTypeByRoom_Successfull()
        {
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository          roomRepository          = new RoomRepository(context);
            IFloorRepository         floorRepository         = new FloorRepository(context);
            IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context);

            //Room(and it's floor)
            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();
            //Component
            var componentType1 = new ComponentTypeTO {
                Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl")
            };
            var componentType2 = new ComponentTypeTO {
                Archived = false, Name = new MultiLanguageString("Name2En", "Name2Fr", "Name2Nl")
            };
            var addedComponentType1 = componentTypeRepository.Add(componentType1);
            var addedComponentType2 = componentTypeRepository.Add(componentType2);

            context.SaveChanges();
            //Floor
            var componentTypes1 = new List <ComponentTypeTO>()
            {
                componentType1, componentType2
            };
            var componentTypes2 = new List <ComponentTypeTO>()
            {
                componentType1
            };

            RoomTO room1 = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1, ComponentTypes = componentTypes1
            };
            RoomTO room2 = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1, ComponentTypes = componentTypes2
            };
            var addedRoom1 = roomRepository.Add(room1);
            var addedRoom2 = roomRepository.Add(room2);

            context.SaveChanges();

            //ACT
            var result  = componentTypeRepository.GetComponentTypesByRoom(addedRoom1.Id);
            var result2 = componentTypeRepository.GetComponentTypesByRoom(addedRoom2.Id);

            //ASSERT
            Assert.AreEqual(2, result.Count());
            Assert.AreEqual(1, result2.Count());
        }
Пример #4
0
        public void Init()
        {
            _repoReserv.Clear();
            _repoUser.Clear();
            _repoRoom.Clear();

            _room1 = new Room('A', 1, 49, 4, Permission.Student);
            _room2 = new Room('B', 2, 23, 6, Permission.Student);

            _student = new User("jona8690", "*****@*****.**", Permission.Student);

            _repoRoom.Add(_room1);
            _repoRoom.Add(_room2);
        }
Пример #5
0
        public async Task <Unit> Handle(CreateRoomCommand command, CancellationToken cancellationToken)
        {
            if (_context.HttpContext.Items["User"] == null)
            {
                throw new AuthenticationException("Authentication error!");
            }

            var userId = ((AccessToken)_context.HttpContext.Items["User"]) !.UserId;
            var user   = _playerRepository.GetById(userId);

            if (user is null)
            {
                user = new Player(userId);
                //throw new BadHttpRequestException("Player not connected to socket!");
            }
            var newGame = new Room(command.Id,
                                   command.RoomName,
                                   command.Password,
                                   command.GameId,
                                   command.Description,
                                   command.MaxPlayers,
                                   user);

            _roomRepository.Add(newGame);

            _unitOfWork.RegisterAggregateRoot(user);
            _unitOfWork.RegisterAggregateRoot(newGame);
            await _unitOfWork.CommitAsync(cancellationToken);

            return(Unit.Value);
        }
        public void RemoveById_AddANewIncidentThenRemoveIt_ReturnTrue()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IIncidentRepository      incidentRepository      = new IncidentRepository(context);
            IRoomRepository          roomRepository          = new RoomRepository(context);
            IFloorRepository         floorRepository         = new FloorRepository(context);
            IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context);
            IIssueRepository         issueRepository         = new IssueRepository(context);
            //Room(and it's floor)
            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();
            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            var addedRoom = roomRepository.Add(room);

            context.SaveChanges();
            //Component
            var componentType = new ComponentTypeTO {
                Archived = false, Name = new MultiLanguageString("Name1En", "Name1Fr", "Name1Nl")
            };
            var addedComponentType = componentTypeRepository.Add(componentType);

            context.SaveChanges();
            //Issue
            var issue = new IssueTO {
                Description = "prout", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType
            };
            var addedIssue = issueRepository.Add(issue);

            context.SaveChanges();
            //Incident
            var incident = new IncidentTO
            {
                Description = "No coffee",
                Issue       = addedIssue,
                Status      = IncidentStatus.Waiting,
                SubmitDate  = DateTime.Now,
                UserId      = 1,
                Room        = addedRoom
            };
            var addedIncident = incidentRepository.Add(incident);

            context.SaveChanges();
            //ACT
            var result = incidentRepository.Remove(addedIncident.Id);

            context.SaveChanges();
            //ASSERT
            Assert.IsTrue(result);
        }
        public void RemoveByEntity_AddANewRoomAndRemoveTheAddedRoom_ReturnTrue()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  repository      = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();

            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            var added = repository.Add(room);

            context.SaveChanges();
            //ACT
            var result = repository.Remove(added);

            context.SaveChanges();
            //ASSERT
            Assert.IsTrue(result);
        }
Пример #8
0
        public void Add_ReturnRoomTONotNull()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  repository      = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();

            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            //ACT
            var result = repository.Add(room);

            context.SaveChanges();
            //ASSERT
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Name.French, "Room1");
        }
Пример #9
0
        public void Update_AddARoopmAndChangeItsName_ReturnUpdatedRoom()
        {
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  repository      = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();

            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            var added = repository.Add(room);

            context.SaveChanges();
            added.Name = new MultiLanguageString("New Room1", "New Room1", "New Room1");
            var updated = repository.Update(added);

            Assert.AreEqual("New Room1", updated.Name.English);
        }
        public void GetByID_AddNewRoomAndRetrieveTheAddedRoom_ReturnTheCoorectRoom()
        {
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  repository      = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor1 = floorRepository.Add(floor);

            context.SaveChanges();

            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            var result = repository.Add(room);

            context.SaveChanges();

            var retrievedRoom = repository.GetById(result.Id);

            Assert.IsNotNull(retrievedRoom);
            Assert.AreEqual(retrievedRoom.ToString(), result.ToString());
        }
Пример #11
0
 public void Setup()
 {
     DataContext.Instance.Rooms.Clear();
     _roomRepo = new RoomRepository();
     _roomRepo.Add(new Room()
     {
         Id = 0, Name = "Kitchen", Devices = new List <IDevice>()
     });
     _roomRepo.Add(new Room()
     {
         Id = 1, Name = "Living Room", Devices = new List <IDevice>()
     });
     _roomRepo.Add(new Room()
     {
         Id = 2, Name = "Bathroom", Devices = new List <IDevice>()
     });
 }
Пример #12
0
        public void GetRoomsByFloors_ReturnCorrectNumberOfCorrespondingRooms()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  roomRepository  = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var floor2 = new FloorTO {
                Number = -1
            };
            var addedFloor1 = floorRepository.Add(floor);
            var addedFloor2 = floorRepository.Add(floor2);

            context.SaveChanges();

            RoomTO room1 = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            RoomTO room2 = new RoomTO {
                Name = new MultiLanguageString("Room2", "Room2", "Room2"), Floor = addedFloor1
            };
            RoomTO room3 = new RoomTO {
                Name = new MultiLanguageString("Room3", "Room3", "Room3"), Floor = addedFloor2
            };

            roomRepository.Add(room1);
            roomRepository.Add(room2);
            roomRepository.Add(room3);
            context.SaveChanges();

            var result1 = roomRepository.GetRoomsByFloor(addedFloor1.Id);
            var result2 = roomRepository.GetRoomsByFloor(addedFloor2.Id);

            Assert.IsNotNull(result1);
            Assert.IsNotNull(result2);
            Assert.AreEqual(2, result1.Count);
            Assert.AreEqual(1, result2.Count);
        }
        public void TestsInitialize()
        {
            _repoRoom.Clear();
            _repoReserv.Clear();
            _repoUser.Clear();

            _room1 = new Room('A', 1, 2, 4, Permission.Student);
            _room2 = new Room('A', 1, 99, 8, Permission.Student);
            _room3 = new Room('B', 1, 45, 2, Permission.Student);

            _repoRoom.Add(_room1);
            _repoRoom.Add(_room2);
            _repoRoom.Add(_room3);

            _student = new User("roxa0198", "*****@*****.**", Permission.Student);

            _repoUser.Add(_student);
        }
        public void GetAll_AddThreeRooms_ReturnCorrectNumberOfRooms()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository  repository      = new RoomRepository(context);
            IFloorRepository floorRepository = new FloorRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var floor2 = new FloorTO {
                Number = -1
            };
            var addedFloor1 = floorRepository.Add(floor);
            var addedFloor2 = floorRepository.Add(floor2);

            context.SaveChanges();

            RoomTO room1 = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor1
            };
            RoomTO room2 = new RoomTO {
                Name = new MultiLanguageString("Room2", "Room2", "Room2"), Floor = addedFloor1
            };
            RoomTO room3 = new RoomTO {
                Name = new MultiLanguageString("Room3", "Room3", "Room3"), Floor = addedFloor2
            };

            repository.Add(room1);
            context.SaveChanges();
            repository.Add(room2);
            context.SaveChanges();
            repository.Add(room3);
            context.SaveChanges();
            //ACT
            var rooms = repository.GetAll();

            //ASSERT
            Assert.AreEqual(3, rooms.Count());
        }
Пример #15
0
        public void CanAddNewRooms()
        {
            var room1 = new Room(0, TestHelper.RoomName, new DateTime(2000, 12, 12));

            var roomRepository = new RoomRepository();

            roomRepository.Add(room1);

            Assert.That(room1.Id != 0);
        }
Пример #16
0
        public void RegisterRoom(string building, string floor, string nr, string maxpeople, string minpermissionlevel)
        {
            char       buildingLetter     = char.Parse(building);
            int        floorNr            = int.Parse(floor);
            int        roomNr             = int.Parse(nr);
            int        maxPeopleNr        = int.Parse(maxpeople);
            Permission minPermissionLevel = HelperFunctions.ConvertIntToPermission(int.Parse(minpermissionlevel));

            IRoom room = new Room(buildingLetter, floorNr, roomNr, maxPeopleNr, minPermissionLevel);

            _repoRoom.Add(room);
        }
Пример #17
0
        public void TestInitialize()
        {
            _repoRoom.Clear();

            _roomList = new List <IRoom>();

            _student = new User("matt2694", "*****@*****.**", Permission.Student);
            _teacher = new User("alhe", "*****@*****.**", Permission.Teacher);
            _admin   = new User("frje", "*****@*****.**", Permission.Admin);

            _room1 = new Room('A', 2, 9, 6, Permission.Student);
            _room2 = new Room('A', 2, 15, 6, Permission.Teacher);
            _room3 = new Room('A', 2, 115, 6, Permission.Admin);
            _room4 = new Room('A', 7, 5, 2, Permission.Student);
            _room5 = new Room('B', 7, 5, 10, Permission.Student);

            _repoRoom.Add(_room1);
            _repoRoom.Add(_room2);
            _repoRoom.Add(_room3);
            _repoRoom.Add(_room4);
            _repoRoom.Add(_room5);

            _dateFrom = new DateTime(2016, 4, 29, 8, 0, 0);
            _dateTo   = new DateTime(2016, 4, 29, 16, 0, 0);

            _reservation1 = new Reservation(_student, _room1, 6, _dateFrom, _dateTo);
            _reservation2 = new Reservation(_teacher, _room2, 6, _dateFrom, _dateTo);
            _reservation3 = new Reservation(_admin, _room3, 6, _dateFrom, _dateTo);
        }
Пример #18
0
        public void CanSearchForRooms()
        {
            var roomName = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture);
            var room1    = new Room(0, roomName, new DateTime(2000, 12, 12));

            var roomRepository = new RoomRepository();

            roomRepository.Add(room1);

            var searchResults = roomRepository.GetRooms(roomName);

            Assert.AreEqual(1, searchResults.Count());
        }
Пример #19
0
        public void Room01AddTest()
        {
            var Room = new Room
            {
                Capacity     = 100,
                Color        = "#ff00ff",
                HasProjector = true,
                Name         = "Room 01"
            };

            repository.Add(Room);
            Assert.IsTrue(repository.Save());
        }
Пример #20
0
        public void Add_ThrowException_WhenNullIsSupplied()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            IRoomRepository repository = new RoomRepository(context);

            //ACT & ASSERT
            Assert.ThrowsException <ArgumentNullException>(() => repository.Add(null));
        }
Пример #21
0
        public void AddRoomTest()
        {
            Assert.AreEqual(true, _roomRepo.Add(new Room()
            {
                Id = 3, Name = "Hall", Devices = new List <IDevice>()
            }));
            Assert.AreEqual("Hall", _roomRepo.Get(3).Name);
            Assert.AreEqual(3, _roomRepo.Get("Hall").Id);

            var allRooms = (List <Room>)_roomRepo.Get();

            Assert.AreEqual(4, allRooms.Count);
        }
Пример #22
0
        public void CreateRoom(Room Room)
        {
            RoomRepository roomRepo = new RoomRepository();

            try
            {
                roomRepo.Add(Room);
                GlobalUnitOfWork.Commit();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 private void BtnSave_Click(object sender, EventArgs e)
 {
     if (lstTypes.SelectedIndex > -1)
     {
         Room room = new Room();
         room.Number = txtNumber.Text;
         room.Block  = txtBlock.Text;
         room.Floor  = Convert.ToInt32(txtFloor.Text);
         room.TypeID = type.ID;
         room.Price  = Convert.ToDecimal(txtPrice.Text);
         roomRepository.Add(room);
         LoadListBox();
         ClearTextBoxes();
     }
 }
        public void Init()
        {
            _repoReserv.Clear();
            _repoRoom.Clear();
            _repoUser.Clear();

            _room1   = new Room('A', 4, 49, 4, Permission.Student);
            _student = new User("hedv", "*****@*****.**", Permission.Student);

            _repoUser.Add(_student);
            _repoRoom.Add(_room1);

            _from = new DateTime(2017, 5, 8, 12, 0, 0);
            _to   = new DateTime(2017, 5, 8, 13, 0, 0);
        }
Пример #25
0
        public ActionResult Create(Room room)
        {
            if (!ModelState.IsValid)
            {
                return(View(room));
            }

            if (room == null)
            {
                return(NotFound());
            }

            // TODO: Add insert logic here
            _roomRepository.Add(room);
            return(RedirectToAction(nameof(Details), "Building", new { Id = room.BuildingNumber }));
        }
Пример #26
0
        public async Task <ActionResult <Room> > PostRoom([FromBody] NewRoomDTO roomDTO)
        {
            var chat = await _chatRepository.Add(new Chat { Messages = new List <Message>() });

            Room room = new Room {
                Name = roomDTO.RoomName, DateOfCreation = DateTime.Now, Chat = chat, ChatID = chat.Id
            };
            await _roomRepository.Add(room);

            var user = await _userRepository.Get(roomDTO.UserUid);

            await _roomUserRepository.Add(new RoomUser { Room = room, RoomID = room.Id, User = user, UserID = user.Id });

            //return await _roomRepository.Get(room.Id);
            return(CreatedAtAction("GetRoom", new { id = room.Id }, room));
        }
Пример #27
0
        public ActionResult Add(Room room)
        {
            User u = (User)Session[CommonConstants.USER_SESSION];

            room.CreatedBy = u.id;
            var result = _roomRepo.Add(room);

            if (result == 1)
            {
                return(Json(new { status = 1, message = "Thêm thành công" }, JsonRequestBehavior.AllowGet));
            }
            else if (result == -1)
            {
                return(Json(new { status = -1, message = "Mã đã bị trùng" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = 0, message = "Thêm thất bại" }, JsonRequestBehavior.AllowGet));
        }
Пример #28
0
        public void CreateRoomTest()
        {
            //Arrange
            RoomModel room = new RoomModel();

            room.RoomNumber  = 1;
            room.Price       = 1200;
            room.IsAvailable = true;
            room.Floor       = 3;
            room.Capacity    = 1;
            room.Area        = 20;
            room.Description = "furnished";
            //Act
            roomDb.Add(room);
            //Assert
            Assert.IsNotNull(room);
        }
Пример #29
0
        public HttpResponseMessage Post(RoomViewModel model)
        {
            if (ModelState.IsValid)
            {
                _repository.Add(model);

                var response = Request.CreateResponse <RoomViewModel>(HttpStatusCode.Created, model);

                string uri = Url.Link("DefaultApi", new { id = model.Id });
                response.Headers.Location = new Uri(uri);
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Пример #30
0
        public void GetAllReservationsTest()
        {
            UserRepository repoUser  = UserRepository.Instance;
            RoomRepository repoRooms = RoomRepository.Instance;

            repoUser.Clear();
            repoRooms.Clear();

            DALFacade testDALFacade = new DALFacade();

            string username = "******";
            string building = "C";
            string floorNr  = "4";
            string nr       = "1000";
            string dateFrom = "2017-05-05 18:00:00.00";
            string dateTo   = "2017-05-05 19:00:00.00";
            string peopleNr = "1";

            List <Dictionary <string, string> > resultdReservationsInfo = new List <Dictionary <string, string> >();
            Dictionary <string, string>         oneReservation          = new Dictionary <string, string>();

            oneReservation.Add("Username", username);
            oneReservation.Add("Building", building);
            oneReservation.Add("FloorNr", floorNr);
            oneReservation.Add("Nr", nr);
            oneReservation.Add("DateFrom", dateFrom);
            oneReservation.Add("DateTo", dateTo);
            oneReservation.Add("PeopleNr", peopleNr);

            resultdReservationsInfo.Add(oneReservation);

            repoUser.Add(testUser);
            repoRooms.Add(testRoom);

            Reservation expectedReservation = new Reservation(testUser, testRoom, 1, testDateFrom, testDateTo);


            var mock = new Mock <DAL.IReservationsForMocking>();

            mock.Setup(reservationsMock => reservationsMock.GetAllReservationsFromDatabase()).Returns(() => resultdReservationsInfo);

            List <Reservation> returnedReservation = testDALFacade.ConvertFromStringsToReservationObjects(mock.Object.GetAllReservationsFromDatabase());

            Assert.AreEqual(expectedReservation, returnedReservation[0]);
        }