public void GetBookingsInLocationAtDateTime() { var bookings = BookingGenerator.CreateList(); bookings[1].BookingDateTime = bookings[2].BookingDateTime; bookings[1].Facility = bookings[2].Facility; bookings[1].FacilityId = bookings[2].FacilityId; var booking2Expected = bookings[2]; List <Booking> expected = new List <Booking>(); expected.Add(bookings[1]); expected.Add(bookings[2]); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Booking.AddRange(bookings); context.SaveChanges(); var repository = new BookingRepository(context); var call = repository.GetBookingsInLocationAtDateTime(booking2Expected.BookingDateTime, booking2Expected.Facility.VenueId, booking2Expected.Facility.SportId).ToList(); Assert.Equal(expected, call); } }
public async void SportIdExists_ReturnTrue() { var sport = SportGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new SportRepository(context); await repository.AddAsync(sport); Assert.True(repository.SportIdExists(sport.SportId)); } }
public async void DoesSportExist_addSportReturnFalse() { var sport = SportGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new SportRepository(context); await repository.AddAsync(sport); Assert.False(repository.DoesSportExist(sport.SportName + ' ')); } }
public async void AddAsync_AddsToConext() { var venue = VenueGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new VenueRepository(context); await repository.AddAsync(venue); Assert.Equal(1, await context.Venue.CountAsync()); Assert.Equal(venue, await context.Venue.SingleAsync()); } }
public async void AddAsync_AddAsyncToConext() { var sport = SportGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new SportRepository(context); await repository.AddAsync(sport); Assert.Equal(1, await context.Sport.CountAsync()); Assert.Equal(sport, await context.Sport.SingleAsync()); } }
public async void AddAsync_AddAsyncToConext() { var booking = BookingGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new BookingRepository(context); await repository.AddAsync(booking); Assert.Equal(1, await context.Booking.CountAsync()); Assert.Equal(booking, await context.Booking.SingleAsync()); } }
public async void AddAsync_AddsToConext() { var facility = FacilityGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); var repository = new FacilityRepository(context); await repository.AddAsync(facility); Assert.Equal(1, await context.Facility.CountAsync()); Assert.Equal(facility, await context.Facility.SingleAsync()); } }
public void VenueExists_ChecksById() { var venue = VenueGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.Add(venue); context.SaveChanges(); var repository = new VenueRepository(context); Assert.True(repository.VenueExists(venue.VenueId)); Assert.False(repository.VenueExists(-1)); Console.WriteLine(venue.VenueId); } }
public void FacilityExists_ChecksById() { var facility = FacilityGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Facility.Add(facility); context.SaveChanges(); var repository = new FacilityRepository(context); Assert.True(repository.FacilityExists(facility.FacilityId)); Assert.False(repository.FacilityExists(-1)); Console.WriteLine(facility.FacilityId); } }
public void DoesVenueExist_ChecksByName() { var venue = VenueGenerator.Create(); venue.VenueName = "King's College"; using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.Add(venue); context.SaveChanges(); var repository = new VenueRepository(context); Assert.True(repository.DoesVenueExist("King's College")); Assert.False(repository.DoesVenueExist("Queens's College")); } }
public async void DeleteAsync_RemovesFromContext() { var venue = VenueGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.Add(venue); context.SaveChanges(); Assert.Equal(1, await context.Venue.CountAsync()); var repository = new VenueRepository(context); await repository.DeleteAsync(venue); Assert.Equal(0, await context.Venue.CountAsync()); } }
public async void DeleteAsync_DeleteFromContext() { var booking = BookingGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { var repository = new BookingRepository(context); context.Database.EnsureCreated(); context.Booking.Add(booking); context.SaveChanges(); Assert.Equal(1, await context.Booking.CountAsync()); await repository.DeleteAsync(booking); Assert.Equal(0, await context.Booking.CountAsync()); } }
public async void GetByIdAsync_ReturnsCorrectItems() { var list = FacilityGenerator.CreateList(5); var expected = list[2]; using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Facility.AddRange(list); context.SaveChanges(); Assert.Equal(list.Count, await context.Facility.CountAsync()); var repository = new FacilityRepository(context); var facility = await repository.GetByIdAsync(expected.FacilityId); Assert.IsType <Facility>(facility); Assert.Equal(expected, facility); } }
public async void UpdateAsync_UpdatesInContext() { var facility = FacilityGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Facility.Add(facility); context.SaveChanges(); var repository = new FacilityRepository(context); var newFacility = await repository.GetByIdAsync(facility.FacilityId); newFacility.FacilityName = "Court 1"; newFacility.SportId = 2; Assert.Equal(1, await context.Facility.CountAsync()); Assert.Equal(newFacility, await context.Facility.SingleAsync()); } }
public async void GetByIdAsync_ReturnsCorrectItems() { var list = VenueGenerator.CreateList(5); var expected = list[2]; using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.AddRange(list); context.SaveChanges(); Assert.Equal(list.Count, await context.Venue.CountAsync()); var repository = new VenueRepository(context); var venue = await repository.GetByIdAsync(expected.VenueId); Assert.IsType <Venue>(venue); Assert.Equal(expected, venue); } }
public async void UpdateAsync_UpdatesInContext() { var venue = VenueGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.Add(venue); context.SaveChanges(); var repository = new VenueRepository(context); var newVenue = await repository.GetByIdAsync(venue.VenueId); newVenue.VenueName = "Old Sports Hall"; await repository.UpdateAsync(newVenue); Assert.Equal(1, await context.Venue.CountAsync()); Assert.Equal(newVenue, await context.Venue.SingleAsync()); } }
public async void GetAllAsync_ReturnsAllFromContext() { var expectedVenues = VenueGenerator.CreateList(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Venue.AddRange(expectedVenues); context.SaveChanges(); Assert.Equal(expectedVenues.Count, await context.Venue.CountAsync()); var repository = new VenueRepository(context); var resources = repository.GetAllAsync(); Assert.IsAssignableFrom <IQueryable <Venue> >(resources); Assert.Equal(expectedVenues, resources); } }
public async void UpdateAsync_UpdatesInContext() { var sport = SportGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Sport.Add(sport); context.SaveChanges(); var repository = new SportRepository(context); var newSport = await repository.GetByIdAsync(sport.SportId); newSport.SportName = "Hockey"; await repository.UpdateAsync(newSport); Assert.Equal(1, await context.Sport.CountAsync()); Assert.Equal(newSport, await context.Sport.SingleAsync()); } }
public async void UpdateAsync_UpdatesInContext() { var booking = BookingGenerator.Create(); using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Booking.Add(booking); context.SaveChanges(); var repository = new BookingRepository(context); var newBooking = await repository.GetByIdAsync(booking.BookingId); newBooking.IsBlock = true; await repository.UpdateAsync(newBooking); Assert.Equal(1, await context.Booking.CountAsync()); Assert.Equal(newBooking, await context.Booking.SingleAsync()); } }
public async void GetByIdAsync_ReturnsCorrectItems() { var list = SportGenerator.CreateList(5); var expected = list[2]; using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Sport.AddRange(list); await context.SaveChangesAsync(); Assert.True(true); Assert.Equal(list.Count, await context.Sport.CountAsync()); var repository = new SportRepository(context); var sport = await repository.GetByIdAsync(expected.SportId); Assert.IsType <Sport>(sport); Assert.Equal(expected, sport); } }
public async void GetByIdAsync_ReturnsCorrectItems() { var bookings = BookingGenerator.CreateList(5); var expected = bookings[2]; using (var context = new booking_facilitiesContext(contextOptions)) { context.Database.EnsureCreated(); context.Booking.AddRange(bookings); await context.SaveChangesAsync(); Assert.True(true); Assert.Equal(bookings.Count, await context.Booking.CountAsync()); var repository = new BookingRepository(context); var booking = await repository.GetByIdAsync(expected.BookingId); Assert.IsType <Booking>(booking); Assert.Equal(expected, booking); } }
public BookingRepository(booking_facilitiesContext context) { this.context = context; }