public async void TestRepositoryDeleteAsync(LodgingModel lodging, RentalModel rental, ReviewModel review, ImageModel image) { using (var ctx = new LodgingContext(Options)) { ctx.Rentals.RemoveRange(ctx.Rentals); ctx.Lodgings.RemoveRange(ctx.Lodgings); ctx.Images.RemoveRange(ctx.Images); await ctx.Rentals.AddAsync(rental); await ctx.Reviews.AddAsync(review); await ctx.Images.AddAsync(image); await ctx.Lodgings.AddAsync(lodging); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(Options)) { var lodgings = new Repository <LodgingModel>(ctx); await lodgings.DeleteAsync(lodging.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(ctx.Lodgings.Find(lodging.EntityId)).State); } using (var ctx = new LodgingContext(Options)) { var rentals = new Repository <RentalModel>(ctx); await rentals.DeleteAsync(rental.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(ctx.Rentals.Find(rental.EntityId)).State); } using (var ctx = new LodgingContext(Options)) { var reviews = new Repository <ReviewModel>(ctx); await reviews.DeleteAsync(review.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(ctx.Reviews.Find(review.EntityId)).State); } using (var ctx = new LodgingContext(Options)) { var images = new Repository <ImageModel>(ctx); await images.DeleteAsync(image.EntityId); Assert.Equal(EntityState.Deleted, ctx.Entry(ctx.Images.Find(image.EntityId)).State); } }
public async void Test_Repository_Update(LodgingModel lodging, RentalModel rental, ReviewModel review) { using (var ctx = new LodgingContext(Options)) { ctx.Rentals.RemoveRange(ctx.Rentals); ctx.Lodgings.RemoveRange(ctx.Lodgings); await ctx.Lodgings.AddAsync(lodging); await ctx.Rentals.AddAsync(rental); await ctx.Reviews.AddAsync(review); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(Options)) { var lodgings = new Repository <LodgingModel>(ctx); var lodgingToUpdate = await ctx.Lodgings.FirstAsync(); lodgingToUpdate.Name = "Name"; lodgings.Update(lodgingToUpdate); var result = ctx.Lodgings.Find(lodging.Id); Assert.Equal(lodgingToUpdate.Name, result.Name); Assert.Equal(EntityState.Modified, ctx.Entry(result).State); } using (var ctx = new LodgingContext(Options)) { var rentals = new Repository <RentalModel>(ctx); var rentalToUpdate = await ctx.Rentals.FirstAsync(); rentalToUpdate.LotNumber = "4"; rentals.Update(rentalToUpdate); var result = ctx.Rentals.Find(rental.Id); Assert.Equal(rentalToUpdate.LotNumber, result.LotNumber); Assert.Equal(EntityState.Modified, ctx.Entry(result).State); } using (var ctx = new LodgingContext(Options)) { var reviews = new Repository <ReviewModel>(ctx); var reviewToUpdate = await ctx.Reviews.FirstAsync(); reviewToUpdate.Comment = "Comment"; reviews.Update(reviewToUpdate); var result = ctx.Reviews.Find(review.Id); Assert.Equal(reviewToUpdate.Comment, result.Comment); Assert.Equal(EntityState.Modified, ctx.Entry(result).State); } }
public async void Test_Repository_InsertAsync(LodgingModel lodging, RentalModel rental, ReviewModel review) { using (var ctx = new LodgingContext(Options)) { ctx.Rentals.RemoveRange(ctx.Rentals); ctx.Lodgings.RemoveRange(ctx.Lodgings); await ctx.SaveChangesAsync(); } using (var ctx = new LodgingContext(Options)) { var lodgings = new Repository <LodgingModel>(ctx); await lodgings.InsertAsync(lodging); Assert.Equal(EntityState.Added, ctx.Entry(lodging).State); } using (var ctx = new LodgingContext(Options)) { var rentals = new Repository <RentalModel>(ctx); await rentals.InsertAsync(rental); Assert.Equal(EntityState.Added, ctx.Entry(rental).State); } using (var ctx = new LodgingContext(Options)) { var reviews = new Repository <ReviewModel>(ctx); await reviews.InsertAsync(review); Assert.Equal(EntityState.Added, ctx.Entry(review).State); } }