Ejemplo n.º 1
0
        public async void Test_Repository_InsertAsync(LodgingModel lodging, RentalModel rental, ReviewModel review)
        {
            await _connection.OpenAsync();

            try
            {
                using (var ctx = new LodgingContext(_options))
                {
                    await ctx.Database.EnsureCreatedAsync();
                }

                using (var ctx = new LodgingContext(_options))
                {
                    var lodgings = new LodgingRepository(ctx);

                    await lodgings.InsertAsync(lodging);

                    await ctx.SaveChangesAsync();

                    Assert.NotEmpty(await ctx.Lodgings.ToListAsync());
                }

                using (var ctx = new LodgingContext(_options))
                {
                    var rentals = new RentalRepository(ctx);

                    await rentals.InsertAsync(rental);

                    await ctx.SaveChangesAsync();

                    Assert.NotEmpty(await ctx.Rentals.ToListAsync());
                }

                using (var ctx = new LodgingContext(_options))
                {
                    var reviews = new ReviewRepository(ctx);

                    await reviews.InsertAsync(review);

                    await ctx.SaveChangesAsync();

                    Assert.NotEmpty(await ctx.Reviews.ToListAsync());
                }
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }