public void GetAvailableLodgingsByTouristSpotOk() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); Lodging lodgingOfConrad = new Lodging() { Id = Guid.NewGuid(), Name = "Hotel Enjoy Conrad", QuantityOfStars = 5, Address = "Parada 4 Playa Mansa, Rambla Claudio Williman", PricePerNight = 1500, TouristSpot = touristSpot, }; lodgingRepository.Add(lodging); lodgingRepository.Add(lodgingOfConrad); List <Lodging> listWithOriginalsLodgings = new List <Lodging>(); listWithOriginalsLodgings.Add(lodging); listWithOriginalsLodgings.Add(lodgingOfConrad); List <Lodging> listOfLodgingOfDb = lodgingRepository.GetAvailableLodgingsByTouristSpot(touristSpot.Id).ToList(); CollectionAssert.AreEqual(listWithOriginalsLodgings, listOfLodgingOfDb); }
public void CreateInvalidLodgingWithoutRegionOnTouristSpotTest() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>())); lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null); var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict); touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientBusinessLogicException()); touristSpotRepositoryMock.Setup(m => m.GetTouristSpotByName(It.IsAny <string>())).Returns(value: null); touristSpotRepositoryMock.Setup(m => m.Add(It.IsAny <TouristSpot>())); var regionMock = new Mock <IRepository <Region> >(MockBehavior.Strict); regionMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientBusinessLogicException()); RegionManagement regionLogic = new RegionManagement(regionMock.Object); var categoryMock = new Mock <ICategoryRepository>(MockBehavior.Strict); categoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(aCategory); CategoryManagement categoryLogic = new CategoryManagement(categoryMock.Object); TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object, regionLogic, categoryLogic); LodgingManagementForImportation lodgingLogic = new LodgingManagementForImportation(lodgingRepositoryMock.Object, touristSpotLogic); Lodging resultOfCreateALodging = lodgingLogic.Create(lodging, touristSpot, listOfPicturesPath); }
public void GetLodgingDoesntExist() { ContextObl context = ContextFactory.GetMemoryContext(Guid.NewGuid().ToString()); ILodgingRepository lodgingRepository = new LodgingRepository(context); Lodging lodgingOfDb = lodgingRepository.Get(lodging.Id); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ConfirmationNumber,LodgingName,Address,AddressSuburb,AddressCity,AddressRegion,AddressPostcode,AddressCountry,ArrivalDate,ArrivalTime,DepartureDate,DepartureTime,NumOfGuests,NumOfRooms,RoomDescription,TripId")] Lodging lodging) { if (id != lodging.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(lodging); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LodgingExists(lodging.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Details", new { lodging.Id })); } return(View(lodging)); }
public LodgingModifiedModel(Lodging lodging) { Name = lodging.Name; TouristSpot = new TouristSpotNoAssociationsModel(lodging.TouristSpot); IsFull = lodging.IsFull; Address = lodging.Address; }
public JsonResult Put(Lodging lodge) { string query = @" update dbo.DeadPeople set LodgingType = '" + lodge.LodgingType + @"', isMonument = '" + lodge.isMonument + @"', PeopleLimit = '" + lodge.PeopleLimit + @"', isReserved = '" + lodge.isReserved + @"' where IdLodge = " + lodge.IdLodge + @""; DataTable table = new DataTable(); string sqlDataSource = _configuration.GetConnectionString("CmentarzConnectionTEST"); SqlDataReader myReader; using (SqlConnection myCon = new SqlConnection(sqlDataSource)) { myCon.Open(); using (SqlCommand myCommand = new SqlCommand(query, myCon)) { myReader = myCommand.ExecuteReader(); table.Load(myReader);; myReader.Close(); myCon.Close(); } return(new JsonResult("Zaktualizowano kwaterę pomyślnie")); } }
public Reserve Create(Reserve reserve, Guid lodgingId) { try { reserve.Id = Guid.NewGuid(); reserve.PhoneNumberOfContact = Int32.Parse(RandomPhoneNumber(8)); reserve.DescriptionForGuest = RandomDescription(50); Lodging lodgingOfReserve = lodgingManagement.GetLodgingById(lodgingId); int totalDays = (reserve.CheckOut - reserve.CheckIn).Days; int[] QuantityOfGuest = new int[4] { reserve.QuantityOfAdult, reserve.QuantityOfChild, reserve.QuantityOfBaby, reserve.QuantityOfRetired }; reserve.LodgingOfReserve = lodgingOfReserve; reserve.StateOfReserve = Reserve.ReserveState.Creada; reserve.TotalPrice = lodgingOfReserve.CalculateTotalPrice(totalDays, QuantityOfGuest); reserve.VerifyFormat(); reserveRepository.Add(reserve); return(reserve); } catch (ReserveException e) { throw new DomainBusinessLogicException(e.Message); } catch (ClientBusinessLogicException e) { throw new ClientBusinessLogicException(MessageExceptionBusinessLogic.ErrorCreatingReserve, e); } catch (ServerException e) { throw new ServerBusinessLogicException("No se puede crear la reserva deseada.", e); } }
public ReportBasicInfoModel(Lodging lodging) { Id = lodging.Id; Name = lodging.Name; Address = lodging.Address; TouristSpotId = lodging.TouristSpot.Id; }
public Review Create(Review review, Guid idOfReserveAssociated) { try { Reserve reserveAssociated = reserveManagementLogic.GetById(idOfReserveAssociated); VerifyIfExistReviewForReserve(idOfReserveAssociated); review.IdOfReserve = idOfReserveAssociated; review.NameOfWhoComments = reserveAssociated.Name; review.LastNameOfWhoComments = reserveAssociated.LastName; Lodging lodgingOfReview = reserveAssociated.LodgingOfReserve; review.LodgingOfReview = lodgingOfReview; review.VerifyFormat(); reviewRepository.Add(review); double averageReviewScoreUpdated = reviewRepository.GetAverageReviewScoreByLodging(lodgingOfReview.Id); lodgingManagementLogic.UpdateAverageReviewScore(lodgingOfReview, averageReviewScoreUpdated); return(review); } catch (ReviewException e) { throw new DomainBusinessLogicException(e.Message); } catch (ClientBusinessLogicException e) { throw new ClientBusinessLogicException(MessageExceptionBusinessLogic.ErrorCreatingReview, e); } catch (DomainBusinessLogicException e) { throw new DomainBusinessLogicException(e.Message); } catch (ServerException e) { throw new ServerBusinessLogicException("No se puede crear la review debido a que ha ocurrido un error.", e); } }
public void HasAnyBookingReturnsFalseIfABookingOnlyExistsForDeletedLodgingInTouristSpot() { TouristSpots.ForEach(ts => Context.Add(ts)); var lodging = new Lodging { Id = 1, Address = "Addr 1", TouristSpot = TouristSpots.ElementAt(0), IsDeleted = true }; Context.Add(lodging); var booking = new Booking { Id = 1, CheckIn = DateTime.Now, CheckOut = DateTime.Now.AddDays(5), Lodging = lodging, Tourist = new Tourist { Name = "Example", Email = "*****@*****.**" }, States = new List <BookingState> { new BookingState { Description = "desc", State = "Aceptada" } } }; Context.Add(booking); Context.SaveChanges(); Assert.IsFalse(Repository.HasAnyBooking(TouristSpots.ElementAt(0).Id)); }
static void Main(string[] args) { try { var destination = new Destination { Country = "Indonesia", Description = "EcoTourism at its best in exquisite Bali", Name = "Bali" }; var lodging = new Lodging { Name = "Rainy Day Motel", }; var cstr = @"Server=DESKTOP-D51E9P0; Database=BreakAway;User ID=sa;Password=l88888888"; //Data Source=DESKTOP-D51E9P0;Persist Security Info=True;User ID=sa;Password=*********** //Data Source=DESKTOP-D51E9P0;Initial Catalog=master;Persist Security Info=True;User ID=sa;Password=*********** using (var connection = new SqlConnection(cstr)) { using (var context = new BreakAwayContext(connection)) { context.Lodgings.Add(lodging); context.SaveChanges(); } } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { Console.WriteLine(" 保存失败! 错误信息:" + ex.Message); } Console.WriteLine("OK"); Console.Read(); }
public void TestInitialize() { var touristSpot = new TouristSpot { Id = 1, Name = "name", Description = "description", Image = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Region = null, TouristSpotCategories = new List <TouristSpotCategory>() }; var lodging = new Lodging { Id = 1, Name = "Name", Description = "Description", Rating = 3, IsFull = true, PricePerNight = 100, Address = "Valid Address 123", Phone = "+598 98 303 040", ConfirmationMessage = "Your reservation has been confirmed!", TouristSpot = touristSpot }; LodgingImage = new LodgingImage { Id = 1, LodgingId = lodging.Id, Lodging = lodging, ImageData = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 } }; LodgingImageBasicInfoModel = new LodgingImageBasicInfoModel(LodgingImage); }
public void TestInitialize() { var touristSpot = new TouristSpot() { Id = 1, Name = "name", Description = "description", Image = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Region = null, TouristSpotCategories = new List <TouristSpotCategory>() }; Lodging = new Lodging() { Id = 1, Name = "Name", Description = "Description", Rating = 3, IsFull = true, Images = new List <LodgingImage>() { new LodgingImage() }, PricePerNight = 100, Address = "Valid Address 123", Phone = "+598 98 303 040", ConfirmationMessage = "Your reservation has been confirmed!", TouristSpot = touristSpot, IsDeleted = false }; }
public async Task <IActionResult> Edit(int id, [Bind("Id,LodgingName,Description,LodgingWebsite,ApplicationUserId,CityId")] Lodging lodging) { if (id != lodging.Id) { return(NotFound()); } var user = await GetCurrentUserAsync(); lodging.ApplicationUserId = user.Id; if (ModelState.IsValid) { try { _context.Update(lodging); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LodgingExists(lodging.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index", "Trips")); } ViewData["ApplicationUserId"] = new SelectList(_context.ApplicationUsers, "Id", "Id", lodging.ApplicationUserId == user.Id); ViewData["CityId"] = new SelectList(_context.City, "Id", "CityName", lodging.CityId); return(View(lodging)); }
public void CreateValidLodgingTestOk() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Add(It.IsAny <Lodging>())); lodgingRepositoryMock.Setup(m => m.GetLodgingByNameAndTouristSpot(lodging.Name, touristSpot.Id)).Returns(value: null); var touristSpotRepositoryMock = new Mock <ITouristSpotRepository>(MockBehavior.Strict); touristSpotRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(touristSpot); TouristSpotManagement touristSpotLogic = new TouristSpotManagement(touristSpotRepositoryMock.Object); LodgingManagementForImportation lodgingLogicForImportation = new LodgingManagementForImportation(lodgingRepositoryMock.Object, touristSpotLogic); Lodging resultOfCreateALodging = lodgingLogicForImportation.Create(lodging, touristSpot, listOfPicturesPath); Lodging lodgingToCompare = new Lodging() { Id = resultOfCreateALodging.Id, Name = resultOfCreateALodging.Name, QuantityOfStars = resultOfCreateALodging.QuantityOfStars, Address = resultOfCreateALodging.Address, Images = resultOfCreateALodging.Images, PricePerNight = resultOfCreateALodging.PricePerNight, IsAvailable = resultOfCreateALodging.IsAvailable, TouristSpot = resultOfCreateALodging.TouristSpot }; lodgingRepositoryMock.VerifyAll(); Assert.AreEqual(lodging, lodgingToCompare); }
public JsonResult Post(Lodging lodge) { string query = @" insert into dbo.Lodgings values ('" + Convert.ToInt32(lodge.LodgingType) + @"', N'" + lodge.isMonument + @"', N'" + lodge.PeopleLimit + @"', '" + lodge.isReserved + @"')"; DataTable table = new DataTable(); string sqlDataSource = _configuration.GetConnectionString("CmentarzConnectionTEST"); SqlDataReader myReader; using (SqlConnection myCon = new SqlConnection(sqlDataSource)) { myCon.Open(); using (SqlCommand myCommand = new SqlCommand(query, myCon)) { myReader = myCommand.ExecuteReader(); table.Load(myReader);; myReader.Close(); myCon.Close(); } return(new JsonResult("Dodano kwaterę pomyślnie")); } }
private static Booking CreateBooking(int id, Lodging lodging, bool wasRejected) { var booking = new Booking { Id = id, CheckIn = DateTime.Now, CheckOut = DateTime.Now.AddDays(5), Lodging = lodging, Tourist = new Tourist { Name = "Example", Email = "*****@*****.**" }, States = new List <BookingState> { new BookingState { Description = "desc", State = "Aceptada" } } }; if (wasRejected) { booking.States.Add(new BookingState { Description = "desc", State = "Rechazada" }); } return(booking); }
public IActionResult Edit(int ID) { // TODO: Add better ViewModel Lodging lodging = _lodgingService.FindByID(ID); return(View(lodging)); }
public IActionResult DeleteConfirmed(int ID) { // TODO: Add validation Lodging lodging = _lodgingService.FindByID(ID); _lodgingService.Remove(lodging); return(RedirectToAction(nameof(Index))); }
public ActionResult DeleteConfirmed(int id) { Lodging lodging = db.Lodgings.Find(id); db.Lodgings.Remove(lodging); db.SaveChanges(); return(RedirectToAction("Index")); }
private static void UpdateLodging(Lodging lodging) { using (var context = new BreakAwayContext()) { context.Entry(lodging).State = EntityState.Modified; context.SaveChanges(); } }
public void SetUp() { regionForTouristSpot = new Region() { Id = Guid.NewGuid(), Name = Region.RegionName.Región_Centro_Sur, }; catogoryForTouristSpot = new Category() { Id = Guid.NewGuid(), Name = "Playa" }; touristSpotForLodging = new TouristSpot() { Id = Guid.NewGuid(), Name = "Punta del Este", Description = "Un lugar increible", Region = regionForTouristSpot, ListOfCategories = new List <CategoryTouristSpot>() { new CategoryTouristSpot() { Category = catogoryForTouristSpot } } }; lodgingForReserve = new Lodging() { Id = Guid.NewGuid(), Name = "Hotel las cumbres", Address = "En la punta de punta del este", QuantityOfStars = 5, PricePerNight = 100, TouristSpot = touristSpotForLodging }; reserveOfLodging = new Reserve() { Id = Guid.NewGuid(), Name = "Joaquin", LastName = "Lamela", Email = "*****@*****.**", DescriptionForGuest = "Se ha registrado correctamente la reserva", PhoneNumberOfContact = 29082733, CheckIn = new DateTime(2020, 10, 05), CheckOut = new DateTime(2020, 10, 07), QuantityOfAdult = 1, QuantityOfBaby = 1, QuantityOfChild = 1, QuantityOfRetired = 2, LodgingOfReserve = lodgingForReserve, StateOfReserve = Reserve.ReserveState.Creada, TotalPrice = 660 }; }
public void ClientErrorInGetLodgingTest() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientException()); LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object); Lodging resultOfGetLodging = lodgingLogic.GetLodgingById(lodging.Id); }
public void FailInUpdateNotExistLodgingTest() { var lodgingRepositoryMock = new Mock <ILodgingRepository>(MockBehavior.Strict); lodgingRepositoryMock.Setup(m => m.Get(It.IsAny <Guid>())).Throws(new ClientException()); lodgingRepositoryMock.Setup(m => m.Update(It.IsAny <Lodging>())); LodgingManagement lodgingLogic = new LodgingManagement(lodgingRepositoryMock.Object); Lodging resultOfUpdate = lodgingLogic.UpdateLodging(lodging.Id, lodging); }
private void trace(Lodging l, string msg) { if (msg != null) { Trace.Write(msg); } Trace.WriteLine(string.Format("{0}", l.GetType().Name)); Trace.WriteLine(string.Format(" {0}", l.Name)); }
public void DeleteLodgeFromDb(Lodging lodge) { if (lodge == null) { throw new ArgumentNullException(nameof(lodge)); } _context.Lodgings.Remove(lodge); }
public void AddLodgeToDb(Lodging lodge) { if (lodge == null) { throw new ArgumentException(nameof(lodge)); } _context.Lodgings.Add(lodge); }
public void SetUp() { touristSpot = new TouristSpot { Id = Guid.NewGuid(), Name = "Maldonado", Description = "Departamento donde la naturaleza y la tranquilidad desborda." }; lodging = new Lodging() { Id = Guid.NewGuid(), Name = "Hotel Las Cumbres", QuantityOfStars = 5, Address = "Ruta 12 km 3.5", PricePerNight = 150, TouristSpot = touristSpot, }; reserve = new Reserve() { CheckIn = new DateTime(2020, 10, 28), CheckOut = new DateTime(2020, 10, 28), DescriptionForGuest = "Bienvenido", Email = "*****@*****.**", Id = Guid.NewGuid(), Name = "Agustin", LastName = "Her", LodgingOfReserve = lodging, PhoneNumberOfContact = 59866545, QuantityOfAdult = 1, QuantityOfBaby = 1, QuantityOfChild = 1, QuantityOfRetired = 2, StateOfReserve = Reserve.ReserveState.Creada, TotalPrice = 1230 }; review = new Review() { Id = Guid.NewGuid(), Description = "Me gusto mucho la estadia", IdOfReserve = reserve.Id, LastNameOfWhoComments = reserve.LastName, NameOfWhoComments = reserve.Name, LodgingOfReview = lodging, Score = 4 }; reviewForRequest = new ReviewModelForRequest() { Description = "Me gusto mucho la estadia", IdOfReserveAssociated = reserve.Id, Score = 4 }; }
public void EqualsIsFalseIfIdOrAddressAreNotTheSame() { var other = new Lodging() { Id = Lodging.Id, Address = "123", }; Assert.IsFalse(other.Equals(Lodging)); }
public ActionResult Edit([Bind(Include = "LodgingId,Name,Owner,IsResort,MilesFromNearestAirport,LocationId")] Lodging lodging) { if (ModelState.IsValid) { db.Entry(lodging).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(lodging)); }