public void TestInitialize()
        {
            var options = new DbContextOptionsBuilder <CustomerDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_writes_to_database")
                          .Options;

            context = new CustomerDbContext(options);
            context.Database.EnsureDeleted();
            customerRepository = new CustomerRepository(context);
            customerCollection = context.Set <CustomerDataModel>();
        }
Example #2
0
 public static async Task Seed(CustomerDbContext dbContext)
 {
     dbContext.Set <Customer>().Add(new Customer
     {
         Id           = Guid.NewGuid(),
         FirstName    = "Tuan",
         LastName     = "Manh",
         ContactTitle = "Mr",
         AddressInfo  = new AddressInfo(Guid.NewGuid(), "123 ABC", "Ho Chi Minh", "", "", "VN"),
         ContactInfo  = new ContactInfo(Guid.NewGuid(), "123456789", "1234567890", "http://tuanmanh.com.vn")
     });
     dbContext.Set <Customer>().Add(new Customer
     {
         Id           = Guid.NewGuid(),
         FirstName    = "Thang",
         LastName     = "Chung",
         ContactTitle = "Mr",
         AddressInfo  = new AddressInfo(Guid.NewGuid(), "456 ABC", "Ho Chi Minh", "", "", "VN"),
         ContactInfo  = new ContactInfo(Guid.NewGuid(), "123456789", "1234567890", "http://thangchung.com.vn")
     });
     await dbContext.SaveChangesAsync();
 }
 public EntityRepository(CustomerDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = _dbContext.Set <T>();
 }
Example #4
0
 public Repository(CustomerDbContext dbContext)
 {
     _dbContext  = dbContext ?? throw new ArgumentNullException();
     ModelDbSets = _dbContext.Set <TModel>();
 }
Example #5
0
 public async Task <IEnumerable <T> > GetAllAsync()
 {
     return(await _context.Set <T>().ToListAsync());
 }
Example #6
0
 public BaseRepository(CustomerDbContext context)
 {
     this._context = context;
     this._dbSet   = context.Set <TEntity>();
 }
Example #7
0
 public RepositoryBase(CustomerDbContext context)
 {
     _context = context;
     _dbSet   = context.Set <TEntity>();
 }
Example #8
0
 public CustomerRepository(CustomerDbContext context)
 {
     _db    = context;
     _dbSet = _db.Set <Customer>();
 }
Example #9
0
 public GenericRepository(CustomerDbContext customerDbContext)
 {
     context = customerDbContext;
     dbSet   = context.Set <TEntity>();
 }