public async System.Threading.Tasks.Task DeleteAsyncTestAsync() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_DeleteAsyncTestAsync") .Options; // Example element var booking = new Booking() { BookingDate = new System.DateTime(2019, 10, 10, 0, 0, 0), Id = 1 }; // Add the element using (var context = new SportCenterDBContext(options)) { context.Bookings.Add(booking); context.SaveChanges(); } // Delete the element using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var exist = await manager.Exist(1); exist.Should().Be(true); await manager.DeleteAsync(1); exist = await manager.Exist(1); exist.Should().BeFalse(); } }
public void BookingMemberAllowedTest() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_BookingMemberAllowedTest") .Options; // Add the elements using (var context = new SportCenterDBContext(options)) { context.Members.Add(new Member() { Id = 1 }); context.Courts.Add(new Court() { Id = 1, Sport = new Sport() { Id = 1 } }); context.SaveChanges(); } // Checks if the user is allowed to perform the booking using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var exists = manager.BookingMemberAllowed(1, new DateTime(2019, 10, 10, 10, 0, 0)); exists.Should().BeTrue(); } }
public async System.Threading.Tasks.Task UpdateTestAsync() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_UpdateTestAsync") .Options; // Example element var booking = new Booking() { Id = 1, BookingDate = new DateTime(2019, 10, 10, 0, 0, 0), CreatedDate = new DateTime(2019, 10, 10, 0, 0, 0), CourtForeignKey = 1, MemberForeignKey = 1 }; // Add the element using (var context = new SportCenterDBContext(options)) { context.Members.Add(new Member() { Id = 1 }); context.Courts.Add(new Court() { Id = 1, Sport = new Sport() { Id = 1 } }); context.Bookings.Add(booking); context.SaveChanges(); } // Update the value and checks before and after using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var original = await manager.Get(1); original.CreatedDate.Should().BeSameDateAs(new DateTime(2019, 10, 10, 0, 0, 0)); original.CreatedDate = new DateTime(2019, 10, 11, 0, 0, 0); await manager.Update(1, original); var modified = await manager.Get(1); modified.CreatedDate.Should().BeSameDateAs(new DateTime(2019, 10, 11, 0, 0, 0)); } }
/// <inheritdoc /> public async Task <Booking> Update(int id, Booking element) { var entity = await Get(id); entity.BookingDate = element.BookingDate; entity.Court = element.Court; entity.CourtForeignKey = element.CourtForeignKey; entity.Member = element.Member; entity.MemberForeignKey = element.MemberForeignKey; _context.Bookings.Update(entity); _context.SaveChanges(); return(entity); }
public void BookingAlreadyExistTest() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_BookingAlreadyExistTest") .Options; // Example element var booking = new Booking() { Id = 1, BookingDate = new DateTime(2019, 10, 10, 0, 0, 0), CreatedDate = new DateTime(2019, 10, 10, 0, 0, 0), CourtForeignKey = 1, MemberForeignKey = 1 }; // Add the element using (var context = new SportCenterDBContext(options)) { context.Members.Add(new Member() { Id = 1 }); context.Courts.Add(new Court() { Id = 1, Sport = new Sport() { Id = 1 } }); context.Bookings.Add(booking); context.SaveChanges(); } // Update the value and checks before and after using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var exists = manager.BookingAlreadyExist(1, new DateTime(2019, 10, 10, 0, 0, 0)); exists.Should().BeTrue(); var nonExists = manager.BookingAlreadyExist(1, new DateTime(2019, 10, 11, 0, 0, 0)); nonExists.Should().BeFalse(); } }
public void GetDailyBookingsTest() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_GetDailyBookingsTest") .Options; // Add the elements using (var context = new SportCenterDBContext(options)) { context.Members.Add(new Member() { Id = 1 }); context.Courts.Add(new Court() { Id = 1, Sport = new Sport() { Id = 1 } }); context.Bookings.Add(new Booking() { Id = 1, MemberForeignKey = 1, CourtForeignKey = 1, BookingDate = new DateTime(2019, 1, 19, 11, 00, 00) }); context.Bookings.Add(new Booking() { Id = 2, MemberForeignKey = 1, CourtForeignKey = 1, BookingDate = new DateTime(2019, 1, 19, 10, 00, 00) }); context.Bookings.Add(new Booking() { Id = 3, MemberForeignKey = 1, CourtForeignKey = 1, BookingDate = new DateTime(2019, 1, 10, 10, 00, 00) }); context.SaveChanges(); } // Get the Elements using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var elements = manager.GetDailyBookings(new DateTime(2019, 1, 19, 11, 00, 00)); elements.Count().Should().Be(2); elements.ElementAt(0).Id.Should().Be(1); elements.ElementAt(1).Id.Should().Be(2); } }
public async System.Threading.Tasks.Task GetAllTestAsync() { var options = new DbContextOptionsBuilder <SportCenterDBContext>() .UseInMemoryDatabase(databaseName: "BookingManager_GetAllTestAsync") .Options; // Add the elements using (var context = new SportCenterDBContext(options)) { context.Members.Add(new Member() { Id = 1, Name = "Manolo" }); context.Courts.Add(new Court() { Id = 1, Sport = new Sport() { Id = 1 } }); context.Bookings.Add(new Booking() { Id = 1, MemberForeignKey = 1, CourtForeignKey = 1 }); context.Bookings.Add(new Booking() { Id = 2, MemberForeignKey = 1, CourtForeignKey = 1, BookingDate = new DateTime(2019, 1, 1) }); context.SaveChanges(); } // Get All the Elements using (var context = new SportCenterDBContext(options)) { var manager = new BookingManager(context); var elements = await manager.GetAll(); elements.Count().Should().Be(2); elements.ElementAt(0).Id.Should().Be(1); elements.ElementAt(1).Id.Should().Be(2); } }