Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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());
        }