Ejemplo n.º 1
0
        public void GetAllItems_WhenStoreIsPopulated_ReturnsAllItems()
        {
            //arrange
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "PopulatedStore")
                          .Options;

            //act
            using (var context = new ApplicationContext(options))
            {
                var service = new CarAdvertService(context);
                var items   = GetTestCarAdverts().ToList();

                items.ForEach(carAdvert => service.Add(carAdvert));

                context.SaveChanges();
            }

            //assert
            using (var context = new ApplicationContext(options))
            {
                var service       = new CarAdvertService(context);
                var allCarAdverts = service.GetAllItems().ToList();
                Assert.Equal(5, allCarAdverts.Count);
            }
        }
Ejemplo n.º 2
0
        public void Remove_WhenStoreIsPopulated_RemovessSingleItemById()
        {
            //arrange
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "RemoveSingleItem")
                          .Options;

            //act
            using (var context = new ApplicationContext(options))
            {
                var service = new CarAdvertService(context);
                var items   = GetTestCarAdverts().ToList();

                items.ForEach(carAdvert => service.Add(carAdvert));

                context.SaveChanges();
            }

            //assert
            using (var context = new ApplicationContext(options))
            {
                var service  = new CarAdvertService(context);
                var testGuid = new Guid("981a7ab2-7887-4afd-b123-7d440c181627");
                service.Remove(testGuid);

                var deletedCarAdvert = service.GetById(testGuid);
                var allCarAdverts    = service.GetAllItems().ToList();

                Assert.Null(deletedCarAdvert);
                Assert.Equal(4, allCarAdverts.Count);
            }
        }
Ejemplo n.º 3
0
        public void GetAllItems_WhenStoreIsEmpty_ReturnsEmptyList()
        {
            //arrange
            var options = new DbContextOptionsBuilder <ApplicationContext>()
                          .UseInMemoryDatabase(databaseName: "EmptyStore")
                          .Options;

            //act

            //assert
            using (var context = new ApplicationContext(options))
            {
                var service       = new CarAdvertService(context);
                var allCarAdverts = service.GetAllItems();
                Assert.Equal(new List <CarAdvert>(), allCarAdverts);
            }
        }