public void ShouldGetAll() { // Arrange var options = new DbContextOptionsBuilder <VetBookerContext>() .UseInMemoryDatabase(databaseName: "ShouldGetAll") .Options; var storedList = new List <Vet> { new Vet(), new Vet(), new Vet() }; using (var context = new VetBookerContext(options)) { foreach (var vet in storedList) { context.Add(vet); context.SaveChanges(); } } // Act List <Vet> actualList; using (var context = new VetBookerContext(options)) { var repository = new VetRepository(context); actualList = repository.GetAll().ToList(); } // Assert Assert.Equal(storedList.Count(), actualList.Count()); }
public void ShouldReturnTheAvailableVets() { // Arrange var date = new DateTime(2020, 1, 25); var options = new DbContextOptionsBuilder <VetBookerContext>() .UseInMemoryDatabase(databaseName: "ShouldReturnTheAvailableVets") .Options; using (var context = new VetBookerContext(options)) { context.Vet.Add(new Vet { Id = 1 }); context.Vet.Add(new Vet { Id = 2 }); context.Vet.Add(new Vet { Id = 3 }); context.VetBooking.Add(new VetBooking { VetId = 1, Date = date }); context.VetBooking.Add(new VetBooking { VetId = 2, Date = date.AddDays(1) }); context.SaveChanges(); } using (var context = new VetBookerContext(options)) { var repository = new VetRepository(context); // Act var vets = repository.GetAvailableVets(date); // Assert Assert.Equal(2, vets.Count()); Assert.Contains(vets, d => d.Id == 2); Assert.Contains(vets, d => d.Id == 3); Assert.DoesNotContain(vets, d => d.Id == 1); } }
public void ShouldGetAllOrderedByDate() { // Arrange var options = new DbContextOptionsBuilder <VetBookerContext>() .UseInMemoryDatabase(databaseName: "ShouldGetAllOrderedByDate") .Options; var storedList = new List <VetBooking> { CreateVetBooking(1, new DateTime(2020, 1, 27)), CreateVetBooking(2, new DateTime(2020, 1, 25)), CreateVetBooking(3, new DateTime(2020, 1, 29)) }; var expectedList = storedList.OrderBy(x => x.Date).ToList(); using (var context = new VetBookerContext(options)) { foreach (var vetBooking in storedList) { context.Add(vetBooking); context.SaveChanges(); } } // Act List <VetBooking> actualList; using (var context = new VetBookerContext(options)) { var repository = new VetBookingRepository(context); actualList = repository.GetAll().ToList(); } // Assert Assert.Equal(expectedList, actualList, new VetBookingEqualityComparer()); }
public void Save(VetBooking vetBooking) { _context.VetBooking.Add(vetBooking); _context.SaveChanges(); }