public virtual async Task Migrate() { var breedItem1 = new Breed(); breedItem1.SetProperties(1, "A", 1); this.Context.Breeds.Add(breedItem1); var paymentTypeItem1 = new PaymentType(); paymentTypeItem1.SetProperties(1, "A"); this.Context.PaymentTypes.Add(paymentTypeItem1); var penItem1 = new Pen(); penItem1.SetProperties(1, "A"); this.Context.Pens.Add(penItem1); var petItem1 = new Pet(); petItem1.SetProperties(1, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, "A", 1, 1m); this.Context.Pets.Add(petItem1); var saleItem1 = new Sale(); saleItem1.SetProperties(1, 1m, "A", "A", 1, 1, "A"); this.Context.Sales.Add(saleItem1); var speciesItem1 = new Species(); speciesItem1.SetProperties(1, "A"); this.Context.Species.Add(speciesItem1); await this.Context.SaveChangesAsync(); }
public async virtual Task <Breed> Create(Breed item) { this.Context.Set <Breed>().Add(item); await this.Context.SaveChangesAsync(); this.Context.Entry(item).State = EntityState.Detached; return(item); }
public async void Create() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); var entity = new Breed(); await repository.Create(entity); var record = await context.Set <Breed>().FirstOrDefaultAsync(); record.Should().NotBeNull(); }
public async void Create() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); var entity = new Breed(); entity.SetProperties(default(int), "B", 1); await repository.Create(entity); var records = await context.Set <Breed>().ToListAsync(); records.Count.Should().Be(2); }
public async virtual Task Delete( int id) { Breed record = await this.GetById(id); if (record == null) { return; } else { this.Context.Set <Breed>().Remove(record); await this.Context.SaveChangesAsync(); } }
public async virtual Task Update(Breed item) { var entity = this.Context.Set <Breed>().Local.FirstOrDefault(x => x.Id == item.Id); if (entity == null) { this.Context.Set <Breed>().Attach(item); } else { this.Context.Entry(entity).CurrentValues.SetValues(item); } await this.Context.SaveChangesAsync(); }
public async void Get() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); Breed entity = new Breed(); context.Set <Breed>().Add(entity); await context.SaveChangesAsync(); var record = await repository.Get(entity.Id); record.Should().NotBeNull(); }
public async void Delete() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); Breed entity = new Breed(); context.Set <Breed>().Add(entity); await context.SaveChangesAsync(); await repository.Delete(entity.Id); Breed modifiedRecord = await context.Set <Breed>().FirstOrDefaultAsync(); modifiedRecord.Should().BeNull(); }
public async void Update_Entity_Is_Not_Tracked() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); Breed entity = new Breed(); context.Set <Breed>().Add(entity); await context.SaveChangesAsync(); await repository.Update(new Breed()); var modifiedRecord = context.Set <Breed>().FirstOrDefaultAsync(); modifiedRecord.Should().NotBeNull(); }
public async void DeleteFound() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); Breed entity = new Breed(); entity.SetProperties(default(int), "B", 1); context.Set <Breed>().Add(entity); await context.SaveChangesAsync(); await repository.Delete(entity.Id); var records = await context.Set <Breed>().ToListAsync(); records.Count.Should().Be(1); }
public async void Update_Entity_Is_Not_Tracked() { Mock <ILogger <BreedRepository> > loggerMoc = BreedRepositoryMoc.GetLoggerMoc(); ApplicationDbContext context = BreedRepositoryMoc.GetContext(); var repository = new BreedRepository(loggerMoc.Object, context); Breed entity = new Breed(); entity.SetProperties(default(int), "B", 1); context.Set <Breed>().Add(entity); await context.SaveChangesAsync(); context.Entry(entity).State = EntityState.Detached; await repository.Update(entity); var records = await context.Set <Breed>().ToListAsync(); records.Count.Should().Be(2); }
public void SetBreedIdNavigation(Breed item) { this.BreedIdNavigation = item; }