Esempio n. 1
0
        public void Delete_Loop_With_Cache_And_Ef()
        {
            var cachingStrategy = new StandardCachingStrategy <Contact, string>(cacheProvider);
            var connection      = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <TestObjectContextCore>()
                          .UseSqlite(connection)
                          .Options;

            var context = new TestObjectContextCore(options);

            context.Database.EnsureCreated();

            var repository = new EfCoreRepository <Contact, string>(context, cachingStrategy);

            repository.Add(new Contact()
            {
                ContactId = "1", Name = "Contact1", ContactTypeId = 1
            });
            repository.Add(new Contact()
            {
                ContactId = "2", Name = "Contact2", ContactTypeId = 2
            });
            repository.Add(new Contact()
            {
                ContactId = "3", Name = "Contact3", ContactTypeId = 2
            });
            repository.FindAll(x => x.ContactTypeId == 2);

            repository = new EfCoreRepository <Contact, string>(new TestObjectContextCore(options), cachingStrategy);

            repository.Delete(x => x.ContactTypeId == 2);
        }
Esempio n. 2
0
        public void Delete_With_Cache_And_Ef()
        {
            var cachingStrategy = new StandardCachingStrategy <Contact, string>(cacheProvider);

            var connection = new SqliteConnection("DataSource=:memory:");

            connection.Open();

            var options = new DbContextOptionsBuilder <TestObjectContextCore>()
                          .UseSqlite(connection)
                          .Options;

            var context = new TestObjectContextCore(options);

            context.Database.EnsureCreated();

            var repository = new EfCoreRepository <Contact, string>(context, cachingStrategy);

            repository.Add(new Contact()
            {
                ContactId = "1", Name = "Contact1"
            });

            repository = new EfCoreRepository <Contact, string>(context, cachingStrategy);
            repository.Get("1");
            repository.CacheUsed.ShouldBeTrue();
            repository.Delete("1");
        }
        public async Task <ActionResult <CookieBaking> > BakeCookieForMixing(CookieBaking cookieBaking)
        {
            var cookieBakingid = await _cookieBakingRepository.Add(cookieBaking);

            cookieBaking.IsMixed = true;
            await _cookieBakingRepository.Update(cookieBaking);

            return(CreatedAtAction("BakeCookieForMixing", new { id = cookieBakingid }, cookieBaking));
        }
        public void CompoundKeyRepository_Should_Work()
        {
            var dbPath = EfDataDirectoryFactory.Build();
            ICompoundKeyRepository <User, string, int> repository = new EfCoreRepository <User, string, int>(context);

            repository.Add(new User {
                Username = "******", Age = 21, FullName = "Jeff - 21"
            });
            repository.Add(new User {
                Username = "******", Age = 31, FullName = "Jeff - 31"
            });
            repository.Add(new User {
                Username = "******", Age = 41, FullName = "Jeff - 41"
            });

            repository.Add(new User {
                Username = "******", Age = 31, FullName = "Ben - 31"
            });
            repository.Add(new User {
                Username = "******", Age = 41, FullName = "Ben - 41"
            });
            repository.Add(new User {
                Username = "******", Age = 51, FullName = "Ben - 51"
            });

            repository.Get("jeff", 31).FullName.ShouldBe("Jeff - 31");
            repository.Get("ben", 31).FullName.ShouldBe("Ben - 31");
            repository.Get("jeff", 41).FullName.ShouldBe("Jeff - 41");

            repository.FindAll(x => x.Age == 31).Count().ShouldBe(2);
        }
        public async Task <ActionResult <Order> > PostOrder(Order order)
        {
            try
            {
                //Note : we can add validation here
                var orderid = await _orderRepository.Add(order);

                return(CreatedAtAction("PostOrder", new { id = orderid }, order));
            }
            catch (System.Exception)
            {
                //Note : plan is to use global error handling as given in below link
                //https://docs.microsoft.com/en-us/aspnet/core/web-api/handle-errors?view=aspnetcore-3.0
                return(NotFound());
            }
        }