Ejemplo n.º 1
0
        public async void Test_LodgingRepo_GetAsync()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();

                // Add repo-specific setup here.
                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var repo = new LodgingRepository(ctx);

                // Add repo-specific method calls here.
                var actual = await repo.GetAsync(new LodgingSearchFilterModel());

                // Add Asserts here.
                Assert.Empty(actual);
            }
        }
Ejemplo n.º 2
0
        public async void Test_ReviewRepo_GetAsyncById()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();

                // Add repo-specific setup here.
                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var repo = new ReviewRepository(ctx);

                // Add repo-specific method calls here.
                var actual = await repo.GetAsync(1);

                // Add Asserts here.
                Assert.Null(actual);
            }
        }
        public async void Test_Seed_HasRentals()
        {
            var dbOptions = await NewDb();

            var rental = new RentalModel()
            {
                Id = 1
            };

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.Rentals.AddAsync(rental);

                await ctx.SaveChangesAsync();

                // Setup for seeding the database
                Seed.SeedDatabase(ctx);
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                // Add Asserts here.
                Assert.False(ctx.Lodgings.Count() > 0);
                Assert.True(ctx.Rentals.Count() > 0);
                Assert.False(ctx.Reviews.Count() > 0);
            }
        }
Ejemplo n.º 4
0
        public async void Test_LodgingRepo_LodgingByCityAndOccupancy(LodgingModel lodging)
        {
            await _connection.OpenAsync();

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

                    await ctx.Lodgings.AddAsync(lodging);

                    await ctx.SaveChangesAsync();
                }

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

                    var actual = await lodgings.Lodging.LodgingByCityAndOccupancy("Austin", 3);

                    Assert.NotEmpty(actual);
                }
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }
Ejemplo n.º 5
0
        public async void Test_Repository_DeleteAsync(LodgingModel lodging, RentalModel rental, ReviewModel review)
        {
            await _connection.OpenAsync();

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

                    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);

                    await lodgings.DeleteAsync(1);

                    await ctx.SaveChangesAsync();

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

                using (var ctx = new LodgingContext(_options))
                {
                    var rentals = new Repository <RentalModel>(ctx);

                    await rentals.DeleteAsync(1);

                    await ctx.SaveChangesAsync();

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

                using (var ctx = new LodgingContext(_options))
                {
                    var reviews = new Repository <ReviewModel>(ctx);

                    await reviews.DeleteAsync(1);

                    await ctx.SaveChangesAsync();

                    Assert.Empty(await ctx.Reviews.ToListAsync());
                }
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }
        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);
            }
        }
Ejemplo n.º 7
0
        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_GetAsyncById()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var repo = new ConcreteRepository(ctx);
                var _    = repo.GetAsync(1, new DummyQueryParamsModel());
            }
        }
        public async void Test_LodgingRepo_LodgingByLocationAndOccupancy(LodgingModel lodging)
        {
            using (var ctx = new LodgingContext(Options))
            {
                await ctx.Lodgings.AddAsync(lodging);

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(Options))
            {
                var lodgings = new LodgingRepo(ctx);

                var actual = await lodgings.LodgingByLocationAndOccupancy(2, "Austin");

                Assert.NotEmpty(actual);
                Assert.True(actual.Count() == 1);
            }
        }
Ejemplo n.º 10
0
        public async void TestRepositorySelectAsync()
        {
            using (var ctx = new LodgingContext(Options))
            {
                ctx.Rentals.RemoveRange(ctx.Rentals);
                ctx.Lodgings.RemoveRange(ctx.Lodgings);
                ctx.Images.RemoveRange(ctx.Images);

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(Options))
            {
                var lodgings = new Repository <LodgingModel>(ctx);
                var actual   = await lodgings.SelectAsync();

                Assert.Empty(actual);
            }

            using (var ctx = new LodgingContext(Options))
            {
                var rentals = new Repository <RentalModel>(ctx);
                var actual  = await rentals.SelectAsync();

                Assert.Empty(actual);
            }

            using (var ctx = new LodgingContext(Options))
            {
                var reviews = new Repository <ReviewModel>(ctx);
                var actual  = await reviews.SelectAsync();

                Assert.Empty(actual);
            }
            using (var ctx = new LodgingContext(Options))
            {
                var images = new Repository <ImageModel>(ctx);
                var actual = await images.SelectAsync();

                Assert.Empty(actual);
            }
        }
        public async void Test_LodgingRepo_GetAsyncById()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var repo = new LodgingRepository(ctx);

                var actual = await repo.GetAsync(1, new LodgingQueryParamsModel());

                Assert.Null(actual);
            }
        }
        public async void Test_Apply_Sort_Order()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var query   = new List <DummyModel>().AsQueryable();
                var filters = new List <Expression <Func <DummyModel, bool> > >();
                var repo    = new ConcreteRepository(ctx);
                repo.RunApplyTest(query, filters, (e => e.Id), "asc");
                repo.RunApplyTest(query, filters, (e => e.Id), "desc");
                repo.RunApplyTest(query, filters, (e => e.Id), "default");
            }
        }
        public async void Test_LodgingRepo_GetAsync_IncludeImages()
        {
            var dbOptions = await NewDb();

            using (var ctx = new LodgingContext(dbOptions))
            {
                await ctx.Database.EnsureCreatedAsync();

                await ctx.SaveChangesAsync();
            }

            using (var ctx = new LodgingContext(dbOptions))
            {
                var repo = new LodgingRepository(ctx);

                var queryParams = new LodgingQueryParamsModel();
                queryParams.IncludeImages = true;

                var actual = await repo.GetAsync(queryParams);

                Assert.Empty(actual);
            }
        }
        public async void Test_Repository_SelectAsync_ById()
        {
            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);

                var actual = await lodgings.SelectAsync(1);

                Assert.Null(actual);
            }

            using (var ctx = new LodgingContext(Options))
            {
                var rentals = new Repository <RentalModel>(ctx);

                var actual = await rentals.SelectAsync(1);

                Assert.Null(actual);
            }

            using (var ctx = new LodgingContext(Options))
            {
                var reviews = new Repository <ReviewModel>(ctx);

                var actual = await reviews.SelectAsync(1);

                Assert.Null(actual);
            }
        }
        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);
            }
        }
Ejemplo n.º 16
0
        public async void Test_Repository_Update(LodgingModel lodging, RentalModel rental, ReviewModel review)
        {
            await _connection.OpenAsync();

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

                    await ctx.Lodging.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 expected = await ctx.Lodging.FirstAsync();

                    expected.Name = "name";
                    lodgings.Update(expected);
                    await ctx.SaveChangesAsync();

                    var actual = await ctx.Lodging.FirstAsync();

                    Assert.Equal(expected, actual);
                }

                using (var ctx = new LodgingContext(_options))
                {
                    var rentals  = new Repository <RentalModel>(ctx);
                    var expected = await ctx.Rentals.FirstAsync();

                    expected.Name = "name";
                    rentals.Update(expected);
                    await ctx.SaveChangesAsync();

                    var actual = await ctx.Rentals.FirstAsync();

                    Assert.Equal(expected, actual);
                }

                using (var ctx = new LodgingContext(_options))
                {
                    var reviews  = new Repository <ReviewModel>(ctx);
                    var expected = await ctx.Reviews.FirstAsync();

                    expected.Comment = "comment";
                    reviews.Update(expected);
                    await ctx.SaveChangesAsync();

                    var actual = await ctx.Reviews.FirstAsync();

                    Assert.Equal(expected, actual);
                }
            }
            finally
            {
                await _connection.CloseAsync();
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Represents the _UnitOfWork_ `Commit` method
 /// </summary>
 /// <returns></returns>
 public async Task <int> CommitAsync() => await _context.SaveChangesAsync();