public async Task ShouldAssignMinuteServicesToRoomAndRemoveCurrentConnections() { //Arrange var context = new iReceptionDbContext(DbOptions); var repository = new RoomToMinuteServiceRepository(context); var existingMinuteServices = new RoomToMinuteService() { RoomId = 1, MinuteServiceId = 21 }; await context.RoomToMinuteServices.AddAsync((existingMinuteServices)); await context.SaveChangesAsync(); int roomId = 1; int[] serviceIds = { 2, 3, 4 }; //Act var actual = await repository.AssignAsync(roomId, serviceIds); var expected = serviceIds; var deletedRecord = await context.RoomToServices.FindAsync(1, 21); //Assert actual.Should().BeEquivalentTo(serviceIds); deletedRecord.Should().BeNull(); }
public async Task ShouldListAllExistingConnections() { //Arrange var context = new iReceptionDbContext(DbOptions); var repository = new RoomToMinuteServiceRepository(context); var existingMinuteServices = new List <RoomToMinuteService> { new RoomToMinuteService { RoomId = 1, MinuteServiceId = 2 }, new RoomToMinuteService { RoomId = 1, MinuteServiceId = 3 } }; await context.RoomToMinuteServices.AddRangeAsync(existingMinuteServices); await context.SaveChangesAsync(); //Act var actual = await repository.ListAssignedAsync(1); var expected = existingMinuteServices.Select(ms => ms.MinuteServiceId); //Assert actual.Should().BeEquivalentTo(expected); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } if (disposing) { using (var sampleDbContext = new iReceptionDbContext(DbOptions)) { sampleDbContext.Database.EnsureDeleted(); } } disposed = true; }
public async void ShouldThrowExceptionIfCompanyObjectExists() { //Arrange var context = new iReceptionDbContext(DbOptions); var hotelCompany = new HotelCompany(); var repository = new HotelCompanyRepository(context); await context.AddAsync(hotelCompany); await context.SaveChangesAsync(); //Act var expectedExceptionMessage = "HotelCompany object is already created"; //Assert var actualException = await Assert.ThrowsAsync <InvalidOperationException> (async() => await repository.AddAsync()); actualException.Message.Should().BeEquivalentTo(expectedExceptionMessage); }
public async Task ShouldAssignNothingAndReturnReservationId() { //Arrange var context = new iReceptionDbContext(DbOptions); var repository = new MinuteServiceToReservationRepository(context, null); var convertedMinuteServiceToReservation = new MinuteServiceToReservation { ReservationId = 1, MinuteServiceId = 0, Duration = 30 }; //Act var actual = await repository.AddAsync(convertedMinuteServiceToReservation); var expected = convertedMinuteServiceToReservation.ReservationId; //Assert Assert.Equal(expected, actual); }
public async Task ShouldThrowExceptionWhenReservationIsPaid() { //Arrange var context = new iReceptionDbContext(DbOptions); var paidReservation = new Reservation { IsPaid = true }; var repository = new ReservationRepository(context); await context.Reservations.AddAsync(paidReservation); await context.SaveChangesAsync(); //Act var expectedExceptionMessage = "Reservation is already paid"; //Assert var actualException = await Assert.ThrowsAsync <InvalidOperationException> (async() => await repository.PayAsync(1)); actualException.Message.Should().BeEquivalentTo(expectedExceptionMessage); }
public async Task ShouldAddNewReservation() { //Arrange var context = new iReceptionDbContext(DbOptions); var roomToReturn = new Room { PricePerDay = 10 }; await context.Rooms.AddAsync(roomToReturn); await context.SaveChangesAsync(); var repository = new ReservationRepository(context); var convertedDto = new Reservation { StartDate = new DateTime(2020, 7, 23), EndDate = new DateTime(2020, 7, 30), RoomId = 1, ClientId = 1, }; //Act var actual = await repository.AddAsync(convertedDto); var actualObject = await context.Reservations.OrderByDescending(r => r.Id).FirstOrDefaultAsync(); var expected = 1; var expectedBalance = (convertedDto.EndDate - convertedDto.StartDate).Days * roomToReturn.PricePerDay; //Assert Assert.Equal(expected, actual); Assert.Equal(expectedBalance, actualObject.Balance); Assert.False(actualObject.IsPaid); Assert.False(actualObject.Active); Assert.False(actualObject.IsDeleted); }
public async Task ShouldClearExistingConnections() { //Arrange var context = new iReceptionDbContext(DbOptions); var repository = new RoomToMinuteServiceRepository(context); var existingMinuteService = new RoomToMinuteService { RoomId = 1, MinuteServiceId = 21 }; await context.RoomToMinuteServices.AddAsync(existingMinuteService); await context.SaveChangesAsync(); //Act await repository.DeleteAsync(1); var actual = context.RoomToMinuteServices.ToList(); //Assert actual.Should().BeEmpty(); }
public async Task ShouldRemoveGivenConnection() { //Arrange var context = new iReceptionDbContext(DbOptions); var repository = new MinuteServiceToReservationRepository(context, null); var connectionToDelete = new MinuteServiceToReservation { ReservationId = 1, MinuteServiceId = 2 }; await context.MinuteServicesToReservation.AddAsync(connectionToDelete); await context.SaveChangesAsync(); //Act var actual = await repository.DeleteAsync(connectionToDelete.ReservationId, connectionToDelete.MinuteServiceId); var expected = connectionToDelete.MinuteServiceId; //Assert Assert.Equal(expected, actual); }
public async Task ShouldAssignServiceToReservation() { //Arrange var context = new iReceptionDbContext(DbOptions); var returnedMinuteService = new MinuteService { Id = 1, PricePerMinute = 10 }; var msRepository = new Mock <IMinuteServiceRepository>(); msRepository .Setup(r => r.GetAsync(It.IsAny <int>())) .ReturnsAsync(returnedMinuteService); var repository = new MinuteServiceToReservationRepository(context, msRepository.Object); var convertedMinuteServiceToReservation = new MinuteServiceToReservation { ReservationId = 1, MinuteServiceId = 12, Duration = 30 }; //Act var actual = await repository.AddAsync(convertedMinuteServiceToReservation); var expected = convertedMinuteServiceToReservation.MinuteServiceId; var actualCost = (await context.MinuteServicesToReservation.FirstAsync( mstr => mstr.MinuteServiceId == 12)).Cost; var expectedCost = convertedMinuteServiceToReservation.Duration * returnedMinuteService.PricePerMinute; //Assert Assert.Equal(expected, actual); Assert.Equal(expectedCost, actualCost); }
public ReservationRepository(iReceptionDbContext db) { _db = db; }
public RoomRepository(iReceptionDbContext db, IBuildingRepository buildingRepository) { _db = db; _buildingRepository = buildingRepository; }
public ServiceRepository(iReceptionDbContext db) { _db = db; }
public MinuteServiceToReservationRepository(iReceptionDbContext db, IMinuteServiceRepository minuteServiceRepository) { _db = db; _minuteServiceRepository = minuteServiceRepository; }
public ClientRepository(iReceptionDbContext db) { _db = db; }
public RoomToMinuteServiceRepository(iReceptionDbContext db) { _db = db; }
public BuildingRepository(iReceptionDbContext db) { _db = db; }
public HotelCompanyRepository(iReceptionDbContext db) { _db = db; }