public void StringOfIdToTablesTestInvalidEmptyStringTrowsException() { //Arrange const string stringOfTables = " "; //Act / Assert.ThrowsException <FormatException>(() => ConvertStringToTables.StringOfIdToTables(stringOfTables)); }
public ActionResult Reservation(ReservationDTO reservation) { //takes a string from Request and tries to convert to datetime var date = Request.Form["ReservationTimeHid"]; if (DateTime.TryParse(date, out var dt3)) { reservation.ReservationTime = dt3; } else { return(View(reservation)); } var r = Request.Form["Tables"]; if (!string.IsNullOrEmpty(r)) { //dette tager tables som kommer som en lang string og laver dem om til en liste try { var tables = ConvertStringToTables.StringOfIdToTables(r); if (tables.Count() <= 0) { return(View(reservation)); } reservation.Tables = tables; } catch (FormatException e) { Debug.WriteLine(e); return(View(reservation)); } var response = _reservationService.Create(reservation); if (response != null && reservation.OrderingFood == false && response.Id > 0) { return(RedirectToAction("Index", "Home")); } if (response != null && reservation.OrderingFood && response.Id > 0) { return(RedirectToAction("OrderFood", response)); } } return(View(reservation)); }
public void StringOfIdToTablesTestValid() { const string stringOfTables = "1,2,3,5,7"; var firstTable = new RestaurantTablesDTO(1, 0, 0); var thirdTable = new RestaurantTablesDTO(3, 0, 0); var lastTable = new RestaurantTablesDTO(7, 0, 0); var tables = ConvertStringToTables.StringOfIdToTables(stringOfTables); var restaurantTables = tables.ToList(); //Assert Assert.IsNotNull(tables); Assert.AreEqual(5, restaurantTables.Count()); Assert.AreEqual(firstTable.Id, restaurantTables.ElementAt(0).Id); Assert.AreEqual(thirdTable.Id, restaurantTables.ElementAt(2).Id); Assert.AreEqual(lastTable.Id, restaurantTables.ElementAt(4).Id); }