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);
        }
예제 #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");
        }
예제 #3
0
        public void EfCoreGetSateShouldBeUnchanged()
        {
            var repository = new EfCoreRepository <Contact, string>(dbContext);

            var firstContact = repository.Get("1");

            dbContext.Entry(firstContact).State.ShouldBe(EntityState.Unchanged);
        }
예제 #4
0
        public void EfCoreGetWithStrategySateShouldBeUnchanged()
        {
            var repository = new EfCoreRepository <Contact, string>(dbContext);

            var strat = new GenericFetchStrategy <Contact>();

            var firstContact = repository.Get("1", strat);

            dbContext.Entry(firstContact).State.ShouldBe(EntityState.Unchanged);
        }