public async Task CanGetASingleAmenity() { // Arrange AmenityDTO firstAmenityDto = new AmenityDTO { ID = 11, Name = "TV" }; AmenityDTO secondAmenityDto = new AmenityDTO { ID = 12, Name = "AC" }; var repository = BuildRepository(); AmenityDTO saved1 = await repository.Create(firstAmenityDto); AmenityDTO saved2 = await repository.Create(secondAmenityDto); // Act AmenityDTO result1 = await repository.GetAmenity(1); AmenityDTO result2 = await repository.GetAmenity(2); // Assert Assert.Equal("TV", result1.Name); Assert.Equal("AC", result2.Name); }
public async Task <AmenityDTO> Create(AmenityDTO hotel) { _context.Entry(hotel).State = Microsoft.EntityFrameworkCore.EntityState.Added; await _context.SaveChangesAsync(); return(hotel); }
public async Task CanGetAllAmenities() { // Arrange AmenityDTO firstAmenityDto = new AmenityDTO { ID = 11, Name = "TV" }; AmenityDTO secondAmenityDto = new AmenityDTO { ID = 12, Name = "AC" }; var repositoryAll = BuildRepository(); AmenityDTO saved1 = await repositoryAll.Create(firstAmenityDto); AmenityDTO saved2 = await repositoryAll.Create(secondAmenityDto); // Act List <AmenityDTO> result = await repositoryAll.GetAmenities(); // Assert Assert.Equal(5, result.Count); }
public async void CanGetListOfAmenities() { //Arrange string testAmenity1 = "Test Amenity1"; AmenityDTO testAmenityDTO1 = new AmenityDTO { Name = testAmenity1 }; string testAmenity2 = "Test Amenity2"; AmenityDTO testAmenityDTO2 = new AmenityDTO { Name = testAmenity2 }; var testAmenityRepo = BuildAmenityRepo(); //Act await testAmenityRepo.Create(testAmenityDTO1); await testAmenityRepo.Create(testAmenityDTO2); var gottenAmenities = await testAmenityRepo.GetAmenities(); //Assert Assert.NotNull(gottenAmenities); Assert.True(gottenAmenities.Count >= 2); Dispose(); }
public async void CanUpdateAmenity() { //Arrange string testAmenity = "Test Amenity"; AmenityDTO testAmenityDTO = new AmenityDTO { Name = testAmenity }; var testAmenityRepo = BuildAmenityRepo(); //Act var savedAmenity = testAmenityRepo.Create(testAmenityDTO); string updatedTestAmenityName = "Updated Name"; AmenityDTO updatedTestAmenityDTO = new AmenityDTO { Id = savedAmenity.Id, Name = updatedTestAmenityName }; var updatedAmenity = await testAmenityRepo.Update(updatedTestAmenityDTO); //Assert Assert.NotNull(updatedAmenity); Assert.NotEqual(0, updatedAmenity.Id); Assert.Equal(updatedTestAmenityName, updatedAmenity.Name); Assert.Equal(savedAmenity.Id, updatedAmenity.Id); Dispose(); }
public async Task Delete(int id) { AmenityDTO amenity = await GetAmenity(id); _context.Entry(amenity).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; await _context.SaveChangesAsync(); }
public async Task CanGetSpecificAmenity() { var amenity = new AmenityDTO { Name = "Amenity1", }; var amenity2 = new AmenityDTO { Name = "Amenity2", }; var amenity3 = new AmenityDTO { Name = "Amenity3", }; var repository = BuildRepository(); await repository.Create(amenity); var saved2 = await repository.Create(amenity2); await repository.Create(amenity3); // Amenity ID is 5 due to 3 previously seeded Amenities from DbContext var result = await repository.GetAmenity(5); Assert.Equal(saved2.Name, result.Name); }
/// <summary> /// Updates the Amenity with the information provided(PUT Route) /// </summary> /// <param name="amenity">The Amenity to be updated</param> /// <returns>Updated Amenity</returns> public async Task <AmenityDTO> Update(AmenityDTO amenity) { _context.Entry(amenity).State = EntityState.Modified; await _context.SaveChangesAsync(); return(amenity); }
/// <summary> /// GetAmenity - allows us to get a single amenity by ID /// </summary> /// <param name="id">the unique id of the amenity we want to get</param> /// <returns>the requested amenity object</returns> public async Task <AmenityDTO> GetAmenity(int id) { Amenity amenity = await _context.Amenities.FindAsync(id); var roomAmenities = await _context.RoomAmenities.Where(x => x.AmenityId == id) .Include(x => x.Room) .ToListAsync(); if (amenity == null) { return(null); } else { amenity.RoomAmenities = roomAmenities; AmenityDTO dto = new AmenityDTO() { Id = amenity.Id, Name = amenity.Name }; return(dto); } }
/// <summary> /// deletes an amenity /// </summary> /// <param name="ID">ID value of the amenity to be deleted</param> /// <returns></returns> public async Task DeleteAmenity(int ID) { AmenityDTO amenitydto = await GetAmenity(ID); Amenity amenity = await _context.Amenities.FirstOrDefaultAsync(x => x.ID == amenitydto.ID); _context.Entry(amenity).State = Microsoft.EntityFrameworkCore.EntityState.Deleted; await _context.SaveChangesAsync(); }
public async Task GetSingleAmenity() { // arrange var amenity = new AmenityDTO { Name = "Breakfast Machine", }; var amenity2 = new AmenityDTO { Name = "Lunch Machine", }; var amenity3 = new AmenityDTO { Name = "Dinner Machine", }; var amenity4 = new AmenityDTO { Name = "Dessert Machine", }; var service = BuildRepository(); var saved = await service.Create(amenity); var saved2 = await service.Create(amenity2); var saved3 = await service.Create(amenity3); var saved4 = await service.Create(amenity4); // act var result = await service.GetAmenity(1); var result2 = await service.GetAmenity(2); var result3 = await service.GetAmenity(3); var result4 = await service.GetAmenity(4); var result5 = await service.GetAmenity(5); var result6 = await service.GetAmenity(6); var result7 = await service.GetAmenity(7); // assert Assert.Equal("Microwave", result.Name); Assert.Equal("Television", result2.Name); Assert.Equal("Mini Safe", result3.Name); Assert.Equal("Breakfast Machine", result4.Name); Assert.Equal("Lunch Machine", result5.Name); Assert.Equal("Dinner Machine", result6.Name); Assert.Equal("Dessert Machine", result7.Name); }
private AmenityDTO ConvertToDTO(Amenities amenity) { AmenityDTO adto = new AmenityDTO() { Name = amenity.Name, ID = amenity.ID }; return(adto); }
/// <summary> /// Converts an Amenities object to an AmenityDTO object. /// </summary> /// <param name="amenity">The Amenities object to convert.</param> /// <returns>An AmenityDTO object.</returns> public AmenityDTO ConvertAmenitiesObjectToAmenityDTO(Amenities amenity) { AmenityDTO result = new AmenityDTO() { ID = amenity.ID, Name = amenity.Name }; return(result); }
public async Task <IActionResult> PutAmenity(int id, AmenityDTO amenityDto) { if (id != amenityDto.ID) { return(BadRequest()); } var updatedAmenity = await _amenity.Update(amenityDto); return(Ok(updatedAmenity)); }
/// <summary> /// Retrieves a single Amenities object from the DB. /// </summary> /// <param name="amenitiesID">The ID of the Amenities object to retrieve.</param> /// <returns>A single Amenities object.</returns> public async Task <AmenityDTO> GetAmenitiesByID(int amenitiesID) { // Finds the Amenities object in the DB with a matching ID. Amenities result = await _context.Amenities.FindAsync(amenitiesID); // Convert the Amenities object to an AmenityDTO object. AmenityDTO amenity = ConvertAmenitiesObjectToAmenityDTO(result); return(amenity); }
public async Task <AmenityDTO> GetAmenity(int id) { AmenityDTO amenity = await _context.Amenities .Where(x => x.Id == id) .Select(x => new AmenityDTO { Id = x.Id, Name = x.Name }) .FirstOrDefaultAsync(); return(amenity); }
public async Task <ActionResult <AmenityDTO> > GetAmenity(int id) { AmenityDTO amenity = await _amenity.GetAmenity(id); if (amenity == null) { return(NotFound()); } return(amenity); }
/// <summary> /// Gets a specific Amenity /// </summary> /// <param name="id">Unique Amenity identifier</param> /// <returns>Task of completion</returns> public async Task <AmenityDTO> GetAmenity(int id) { Amenity amenity = await _context.Amenities.FindAsync(id); AmenityDTO dto = new AmenityDTO() { ID = amenity.Id, Name = amenity.Name }; return(dto); }
/// <summary> /// Gets a specific amenity DTO from the database /// </summary> /// <param name="id">Id for amenity to be retrieved</param> /// <returns>Successful result of specified amenity DTO</returns> public async Task <AmenityDTO> GetAmenity(int id) { var result = await _context.Amenities.FindAsync(id); AmenityDTO amenityDTO = new AmenityDTO { ID = result.Id, Name = result.Name }; return(amenityDTO); }
/// <summary> /// Creates an amenity /// </summary> /// <param name="amenity">The amenity to create</param> /// <returns>Task of completion</returns> public async Task <AmenityDTO> Create(AmenityDTO amenity) { Amenities entity = new Amenities() { Name = amenity.Name }; _context.Entry(entity).State = EntityState.Added; await _context.SaveChangesAsync(); return(amenity); }
/// <summary> /// GetHotelRoom - allows us to see an individual room of an individual hotel /// </summary> /// <param name="hotelId">the unique identifier of the hotel we want to look at</param> /// <param name="roomNumber">the unique identifier of the individual room we want to see</param> /// <returns>the completed task showing the room</returns> public async Task <HotelRoomDTO> GetHotelRoom(int hotelId, int roomNumber) { // look in the db on the room table where the id is equal to the one brought in as an argument await _context.HotelRooms.FindAsync(hotelId, roomNumber); // My solution: // include all the RoomAmenities that the room has. //var roomAmenities = await _context.RoomAmenities.Where(x => x.RoomId == hotelRoom.RoomId) // .Include(x => x.Amenity) // .ToListAsync(); //hotelRoom.Room.RoomAmenities = roomAmenities; // EDIT FROM CLASS REPO: "MAGIC LINQ STUFF" var hotelRoom = await _context.HotelRooms.Where(x => x.HotelId == hotelId && x.RoomNumber == roomNumber) .Include(x => x.Hotel) .Include(x => x.Room) .ThenInclude(x => x.RoomAmenities) .ThenInclude(x => x.Amenity) .FirstOrDefaultAsync(); List <AmenityDTO> amenityDTOs = new List <AmenityDTO>(); foreach (var roomAmenities in hotelRoom.Room.RoomAmenities) { AmenityDTO amenityDTO = new AmenityDTO() { Id = roomAmenities.Amenity.Id, Name = roomAmenities.Amenity.Name, }; amenityDTOs.Add(amenityDTO); } RoomDTO roomDTO = new RoomDTO() { Id = hotelRoom.Room.Id, Name = hotelRoom.Room.Name, Layout = hotelRoom.Room.Layout.ToString(), Amenities = amenityDTOs, }; HotelRoomDTO dto = new HotelRoomDTO { HotelId = hotelRoom.HotelId, RoomNumber = hotelRoom.RoomNumber, Rate = hotelRoom.Rate, PetFriendly = hotelRoom.PetFriendly, RoomId = hotelRoom.RoomId, Room = roomDTO, }; return(dto); }
/// <summary> /// Adds an Amenity /// </summary> /// <param name="amenity">Unique Amenity identifier</param> /// <returns>Task of completion</returns> public async Task <AmenityDTO> Create(AmenityDTO dto) { Amenity amenity = new Amenity() { Name = dto.Name }; _context.Entry(amenity).State = EntityState.Added; await _context.SaveChangesAsync(); dto.ID = amenity.Id; return(dto); }
/// <summary> /// Updates a single amenity /// </summary> /// <param name="amenity">takes a single amenity object</param> /// <returns>returns the updated object</returns> // Update public async Task <AmenityDTO> Update(AmenityDTO amenity, int id) { Amenity updatedAmenity = new Amenity() { Id = id, Name = amenity.Name }; _context.Entry(updatedAmenity).State = EntityState.Modified; await _context.SaveChangesAsync(); return(amenity); }
/// <summary> /// Creates a new entry in the Amenity database table, /// based on the AmenityDTO parameter. /// </summary> /// <param name="amenityDto">A unique AmenityDTO object</param> /// <returns>The created amenityDto object</returns> public async Task <AmenityDTO> Create(AmenityDTO amenityDto) { Amenity amenity = new Amenity { Id = amenityDto.ID, Name = amenityDto.Name }; _context.Entry(amenity).State = EntityState.Added; await _context.SaveChangesAsync(); return(amenityDto); }
public async void CanCreateAAmenity() { AmenityDTO amenity = new AmenityDTO() { Name = "Chips" }; var service = BuildRepository(); var created = await service.Create(amenity); Assert.Equal("Chips", created.Name); }
public async Task <AmenityDTO> Create(AmenityDTO amenityDTO) { Amenity amenityEntity = new Amenity() { Name = amenityDTO.Name }; _context.Entry(amenityEntity).State = EntityState.Added; await _context.SaveChangesAsync(); amenityDTO.Id = amenityEntity.Id; return(amenityDTO); }
public async Task <AmenityDTO> GetAmentity(int id) { // our DB does NOT hold DTOs. It holds enitites. Amenities amenity = await _context.Amenities.FindAsync(id); AmenityDTO dto = new AmenityDTO() { ID = amenity.ID, Name = amenity.Name }; return(dto); }
public async Task <AmenityDTO> Update(AmenityDTO amenityDTO) { Amenity amenityEntity = new Amenity() { Id = amenityDTO.Id, Name = amenityDTO.Name }; _context.Entry(amenityEntity).State = EntityState.Modified; await _context.SaveChangesAsync(); return(amenityDTO); }
/// <summary> /// Checks to see if a given Amenities object exists in the DB. /// </summary> /// <param name="id">The ID of the given Amenities object.</param> /// <returns>A boolean determined by whether the object exists or not.</returns> private async Task <bool> AmenitiesExists(int id) { AmenityDTO result = await _amenities.GetAmenitiesByID(id); if (result != null) { return(true); } else { return(false); } }
/// <summary> /// Creates an Amenity called by the POST route /// </summary> /// <param name="amenity">One of the Amenities for the hotel that can be applied to a room</param> /// <returns>Amenity</returns> public async Task <AmenityDTO> Create(AmenityDTO amenityDTO) { Amenity amenity = new Amenity() { Id = amenityDTO.ID, Name = amenityDTO.Name }; _context.Entry(amenity).State = Microsoft.EntityFrameworkCore.EntityState.Added; await _context.SaveChangesAsync(); return(amenityDTO); }