// Use this for initialization void Start() { if (Constants.TEST_NAME_GENERATION) { NameGeneratorTester.testGeneration(); } if (Constants.VALIDATE_LAYOUTS) { try{ LayoutValidator.runValidation(); }catch (Exception e) { TestLogger.log("WrongLayoutDeclarationException: " + e.Message); } } if (Constants.VALIDATE_ROOMS) { try{ RoomValidator.runValidation(); }catch (WrongRoomDeclarationException e) { TestLogger.log("WrongRoomDeclarationException: " + e.Message); } } if (Constants.TEST_DUNGEON_GENERATION) { DungeonGenerationTester.testGeneration(); } }
public HttpResponseMessage AddRoom([FromBody] RoomsDetailsView roomsDetails) { try { //var jsonString = userNew.Content.ReadAsStringAsync().Result; // UserDetailsView user = JsonConvert.DeserializeObject<UserDetailsView>(userNew); RoomValidator validator = new RoomValidator(); ValidationResult results = validator.Validate(roomsDetails); if (results.IsValid) { RoomsServie roomsServie = new RoomsServie(); roomsServie.AddRoom(roomsDetails); return(Request.CreateResponse(HttpStatusCode.OK)); // return Ok(); } else { //List<string> errorlist = new List<string>(); //foreach (var value in results.Errors) //{ // errorlist.Add(value.ErrorMessage); //} return(Request.CreateResponse(HttpStatusCode.BadRequest)); } } catch (HttpRequestException ex) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); // throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, // badInputValidationException.Result)); //Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } }
private static void Main() { var validator = new RoomValidator(); Console.WriteLine(validator.GetSumOfSectorIdsOfRealRooms("InputFile.txt")); Console.WriteLine(validator.GetSectorIdOfNorthPoleObjectStorage()); }
public IActionResult CreateRoom([FromBody] RoomDto roomDto) { var room = _mapper.Map <Room>(roomDto); var user = _userService.GetById(Int32.Parse(User.Identity.Name)); if (user == null) { return(Unauthorized()); } var validator = new RoomValidator(); var result = validator.Validate(roomDto); try { if (!result.IsValid) { throw new ApplicationException(string.Join(",", result.Errors)); } var returnedRoom = _roomService.Create(room, roomDto.Password); _userRoomService.Create(user, room, true); return(StatusCode(201, new { returnedRoom.Id, returnedRoom.Title })); } catch (ApplicationException ex) { return(BadRequest(ex.Message)); } }
public RoomController(IRoomService roomService) { this.roomService = roomService; this.toModelMapper = new MapperConfiguration(cfg => cfg.CreateMap <RoomDTO, RoomModel>()).CreateMapper(); this.toDtoMapper = new MapperConfiguration(cfg => cfg.CreateMap <RoomModel, RoomDTO>()).CreateMapper(); this.roomValidator = new RoomValidator(); }
public ActionResult DeleteConfirmed(int id) { Room room = _roomRepository.Get(id); if (!RoomValidator.CanDelete(_roomRepository)) { ModelState.AddModelError("", "Deleting is not possible because you cannot have less than 4 rooms in your hotel"); } if (ModelState.IsValid) { _roomRepository.Delete(room); return(View(room)); } return(RedirectToAction("Index")); }
public void FourChilderen_OneAdult() { //arrange var roomValidator = new RoomValidator(); var guest = new Guest(); guest = new Guest { Adult = 1, Child = 4, Infant = 0 }; //Act var messages = roomValidator.Validate(guest); //assert bool result = messages.Any(); Assert.IsTrue(result); }
public void ChildernMoreThanFive() { //arrange var roomValidator = new RoomValidator(); var guest = new Guest(); guest = new Guest { Adult = 0, Child = 6, Infant = 0 }; //Act var messages = roomValidator.Validate(guest); //assert bool result = messages.Any(); Assert.IsTrue(result); }
public void NoAdultPerBooking() { //arrange var roomValidator = new RoomValidator(); var guest = new Guest(); guest = new Guest { Adult = 0, Child = 4, Infant = 2 }; //Act var messages = roomValidator.Validate(guest); //assert bool result = messages.Any(); Assert.IsTrue(result); }
private void SaveRoom() { RoomValidator validator = new RoomValidator(); ValidationResult results = validator.Validate(_currentRoom); if (!results.IsValid) { foreach (var failure in results.Errors) { Console.WriteLine("Property " + failure.PropertyName + " failed validation. Error was: " + failure.ErrorMessage); } } else { MessengerInstance.Send(new LoadingMessage("Saving room...")); Exception exceptionResult = null; BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (object sender, DoWorkEventArgs e) => { if (_currentRoom.ID == 0) { _currentRoom.CreatedBy = StateManager.CurrentUser.ID; _currentRoom.ModifiedBy = null; } else _currentRoom.ModifiedBy = StateManager.CurrentUser.ID; _currentRoom = _roomService.Save(_currentRoom); }; worker.RunWorkerCompleted += (object sender, RunWorkerCompletedEventArgs e) => { RaisePropertyChanged("CurrentRoom"); MessengerInstance.Send(new NotificationMessage("RoomSaved")); MessengerInstance.Send(new LoadingMessage(false)); Cancel(); }; worker.RunWorkerAsync(); } }
public override bool IsValid() { ValidationResult = new RoomValidator().Validate(this); return(ValidationResult.IsValid); }
public void OneTimeSetUp() { _validator = new RoomValidator(); }