public void TestInitialize()
        {
            var fileMock = new Mock <IFormFile>();

            LodgingModel = new LodgingModel()
            {
                Name        = "Name",
                Description = "Description",
                Rating      = 3,
                IsFull      = true,
                Images      = new List <IFormFile> {
                    fileMock.Object
                },
                PricePerNight       = 100,
                Address             = "Valid Address 123",
                Phone               = "+598 98 303 040",
                ConfirmationMessage = "Your reservation has been confirmed!",
                TouristSpot         = 1
            };

            LodgingReviewModel = new LodgingReviewModel
            {
                BookingId  = 1,
                Rating     = 3,
                Commentary = "a Comment"
            };

            LodgingLogicMock       = new Mock <ILodgingLogic>(MockBehavior.Strict);
            LodgingReviewLogicMock = new Mock <ILodgingReviewLogic>(MockBehavior.Strict);

            LodgingController = new LodgingController(LodgingLogicMock.Object, LodgingReviewLogicMock.Object);
        }
예제 #2
0
        public async void Post_Update()
        {
            var mocks          = new Mocks();
            var submittedModel = new LodgingModel {
                Id = 1
            };

            mocks._repository.Setup(m => m.GetAsync(1, null)).Returns(
                Task.FromResult <LodgingModel>(
                    new LodgingModel {
                Id = 1
            }
                    )
                );

            mocks._repository.Setup(m => m.Update(submittedModel));

            var _controller = NewLodgingController(mocks);

            var result = await _controller.Post(null, new LodgingModel { Id = 1 });

            Assert.IsType <OkObjectResult>(result);

            var value = (result as OkObjectResult).Value as LodgingModel;

            Assert.Equal(1, value.Id);
        }
예제 #3
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();
            }
        }
        public void Test_Create_LodgingModel(LodgingModel lodging)
        {
            var validationContext = new ValidationContext(lodging);
            var actual            = Validator.TryValidateObject(lodging, validationContext, null, true);

            Assert.True(actual);
        }
예제 #5
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                _logger.LogInformation($"Deleting a lodging @ id = {id}...");
                LodgingModel lodge = await _unitOfWork.Lodging.SelectAsync(id);

                if (lodge == null)
                {
                    throw new KeyNotFoundException("The given id was not found.");
                }
                else
                {
                    await _unitOfWork.Lodging.DeleteAsync(lodge.Id);

                    await _unitOfWork.CommitAsync();

                    _logger.LogInformation($"Successfully deleted a lodging @ id = {lodge.Id}.");
                    return(Ok());
                }
            }
            catch (KeyNotFoundException e)
            {
                _logger.LogInformation($"Could not find lodging @ id = {id}. Caught: {e.Message}");
                return(NotFound(id));
            }
        }
예제 #6
0
        public static LodgingListModel GetHotels(string hotelName, string userkey)
        {
            using (var dc = new TurismoDataContext())
            {
                var key = Guid.Empty;

                Guid.TryParse(userkey, out key);

                var hotels = dc.Alojamientos.Where(p => p.ACTIVO == true && p.ALTACONFIRMADA == 1 && p.CODIGOBLOQUEO == 0 && p.NOMBRE.Contains(hotelName));

                List <LodgingModel> lodgings = new List <LodgingModel>();

                foreach (var hotel in hotels)
                {
                    LodgingModel lodging = new LodgingModel
                    {
                        LodgingName = hotel.NOMBRE,
                        LodgingId   = hotel.IDALOJ.ToString()
                    };
                    lodgings.Add(lodging);
                }


                var lodgingsmodel = new LodgingListModel
                {
                    Lodgings = lodgings
                };

                return(lodgingsmodel);
            }
        }
        public async Task <IActionResult> Put(LodgingModel lodging)
        {
            _unitOfWork.Lodging.Update(lodging);


            return(Accepted(lodging));
        }
예제 #8
0
        public async Task <IActionResult> Post(LodgingModel lodging)
        {
            if (lodging == null)
            {
                return(BadRequest());
            }

            var ExistingEntry = await _unitOfWork.Lodging.GetAsync(lodging.Id);

            if (ExistingEntry == null)
            {
                var obj = await _unitOfWork.Lodging.InsertAsync(lodging);

                await _unitOfWork.CommitAsync();

                return(Ok(obj));
            }
            else
            {
                _unitOfWork.Lodging.Update(lodging);

                await _unitOfWork.CommitAsync();

                return(Ok(lodging));
            }
        }
        public async void Test_Seed_HasLodgings()
        {
            var dbOptions = await NewDb();

            var lodging = new LodgingModel()
            {
                Id = 1
            };

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

                await ctx.Lodgings.AddAsync(lodging);

                await ctx.SaveChangesAsync();

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

            using (var ctx = new LodgingContext(dbOptions))
            {
                // Add Asserts here.
                Assert.True(ctx.Lodgings.Count() > 0);
                Assert.False(ctx.Rentals.Count() > 0);
                Assert.False(ctx.Reviews.Count() > 0);
            }
        }
예제 #10
0
        public async Task <IActionResult> Put(LodgingModel lodging)
        {
            try
            {
                _logger.LogInformation($"Updating a lodging @ {lodging}...");
                var newlodging = await _unitOfWork.Lodging.SelectAsync(lodging.Id);

                if (newlodging == null)
                {
                    throw new KeyNotFoundException("The given id was not found.");
                }
                else
                {
                    _unitOfWork.Lodging.Update(newlodging);
                    await _unitOfWork.CommitAsync();

                    _logger.LogInformation($"Successfully updated a lodging @ {newlodging}.");
                    return(Accepted(lodging));
                }
            }
            catch (NullReferenceException e)
            {
                _logger.LogInformation($"Failed to update a lodging @ {lodging}. Caught: {e}.");
                return(NotFound(lodging));
            }
            catch (KeyNotFoundException e)
            {
                _logger.LogInformation($"Could not find lodging @ id = {lodging.Id}. Caught: {e.Message}");
                return(NotFound(lodging.Id));
            }
        }
예제 #11
0
        public async Task <IActionResult> PostAsync(LodgingModel lodging)
        {
            await _unitOfWork.Lodging.InsertAsync(lodging);

            await _unitOfWork.CommitAsync();

            return(Created(Url.RouteUrl(lodging.Id), lodging.Id));
        }
        public async Task <IActionResult> Post(LodgingModel lodging)
        {
            await _unitOfWork.Lodging.InsertAsync(lodging);

            await _unitOfWork.CommitAsync();

            return(Accepted(lodging));
        }
예제 #13
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();
            }
        }
예제 #14
0
        public async Task <IActionResult> Post(LodgingModel lodging)
        {
            _logger.LogInformation($"Creating a new lodging @ {lodging}...");
            await _unitOfWork.Lodging.InsertAsync(lodging);

            await _unitOfWork.CommitAsync();

            _logger.LogInformation($"Successfully created a new lodging @ {lodging}.");
            return(Accepted(lodging));
        }
        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);
            }
        }
예제 #16
0
        public async void Test_Controller_Put()
        {
            LodgingModel lodgingmodel = await _unitOfWork.Lodging.SelectAsync(2);

            var resultPass = await _controller.Put(lodgingmodel);

            var resultFail = await _controller.Put(null);

            Assert.NotNull(resultPass);
            Assert.NotNull(resultFail);
        }
예제 #17
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);
            }
        }
예제 #18
0
        public async void Delete_UsingInvalidId()
        {
            var          mocks      = new Mocks();
            LodgingModel mockResult = null;

            mocks._repository.Setup(m => m.DeleteAsync(1, null)).Returns(Task.FromResult(mockResult));

            var _controller = NewLodgingController(mocks);

            var result = await _controller.Delete(null, 1);

            Assert.IsType <NotFoundResult>(result);
        }
예제 #19
0
        public IActionResult Post([FromForm] LodgingModel lodgingModel)
        {
            IActionResult result;

            if (lodgingModel.HasErrors())
            {
                result = BadRequest(new ErrorModel(lodgingModel.Errors()));
            }
            else
            {
                var lodging = LodgingLogic.Create(lodgingModel.ToEntity());
                result = Created("GetAdministrator", new LodgingBasicInfoModel(lodging));
            }

            return(result);
        }
        public async void TestControllerPut()
        {
            LodgingModel lodgingmodel = (await _unitOfWork.Lodging.SelectAsync(e => e.EntityId == 2)).FirstOrDefault();

            var resultPass = await _controller.Put(lodgingmodel);

            var resultFail = await _controller.Put(null);

            Assert.NotNull(resultPass);
            Assert.NotNull(resultFail);

            LodgingModel lodgingModelBadId = (await _unitOfWork.Lodging.SelectAsync(e => e.EntityId == 2)).FirstOrDefault();

            lodgingModelBadId.EntityId = -1;

            var resultFail2 = await _controller.Put(lodgingModelBadId);

            Assert.NotNull(resultFail2);
        }
        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);
            }
        }
예제 #22
0
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                _logger.LogInformation($"Deleting a lodging @ id = {id}...");
                LodgingModel lodge = (await _unitOfWork.Lodging.SelectAsync(e => e.EntityId == id)).FirstOrDefault();

                await _unitOfWork.Lodging.DeleteAsync(lodge.EntityId);

                await _unitOfWork.CommitAsync();

                _logger.LogInformation($"Successfully deleted a lodging @ id = {lodge.EntityId}.");
                return(Ok());
            }
            catch (KeyNotFoundException e)
            {
                _logger.LogInformation(e, "Caught: {e.Message}. Id = {id}.", e, id);
                return(NotFound(id));
            }
        }
        public void TestInitialize()
        {
            var fileMock = new Mock <IFormFile>();

            LodgingModel = new LodgingModel()
            {
                Name        = "Name",
                Description = "Description",
                Rating      = 3,
                IsFull      = true,
                Images      = new List <IFormFile> {
                    fileMock.Object
                },
                PricePerNight       = 100,
                Address             = "Valid Address 123",
                Phone               = "+598 98 303 040",
                ConfirmationMessage = "Your reservation has been confirmed!",
                TouristSpot         = 1
            };
        }
예제 #24
0
        public async void Post_Insert()
        {
            var mocks          = new Mocks();
            var submittedModel = new LodgingModel {
                Id = 1
            };

            mocks._repository.Setup(m => m.GetAsync(1, null)).Returns(
                Task.FromResult <LodgingModel>(
                    null
                    )
                );

            mocks._repository.Setup(m => m.InsertAsync(submittedModel)).Returns(Task.FromResult(submittedModel));

            var _controller = NewLodgingController(mocks);

            var result = await _controller.Post(null, submittedModel);

            Assert.IsType <OkObjectResult>(result);
        }
예제 #25
0
        public async Task <IActionResult> Put(LodgingModel lodging)
        {
            try
            {
                _logger.LogInformation($"Updating a lodging @ {lodging}...");
                var newlodging = (await _unitOfWork.Lodging.SelectAsync(e => e.EntityId == lodging.EntityId)).FirstOrDefault();
                _unitOfWork.Lodging.Update(newlodging);
                await _unitOfWork.CommitAsync();

                _logger.LogInformation($"Successfully updated a lodging @ {newlodging}.");
                return(Accepted(lodging));
            }
            catch (NullReferenceException e)
            {
                _logger.LogInformation(e, "Caught: {e}. Given lodging parameter was null.", e);
                return(NotFound(lodging));
            }
            catch (KeyNotFoundException e)
            {
                _logger.LogInformation(e, "Caught: {e.Message}. Id = {lodging.Id}.", e, lodging);
                return(NotFound(lodging.EntityId));
            }
        }
        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);
            }
        }
예제 #27
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();
            }
        }
        public void Test_Validate_LodgingModel(LodgingModel lodging)
        {
            var validationContext = new ValidationContext(lodging);

            Assert.Empty(lodging.Validate(validationContext));
        }
예제 #29
0
        public static void SeedDatabase(LodgingContext context)
        {
            var lodging1 = new LodgingModel()
            {
                Id        = 1,
                Name      = "Campsite 1",
                Bathrooms = 3,
                Location  = new LocationModel()
                {
                    Id      = 1,
                    Address = new AddressModel()
                    {
                        Id            = 1,
                        Street        = "77 Woodsgate Sq",
                        City          = "Baguio",
                        Country       = "Philippines",
                        StateProvince = "Benguet",
                        PostalCode    = "2600",
                        LocationId    = 1
                    },
                    Latitude  = "16.4023° N",
                    Longitude = "120.5960° E",
                    Locale    = "en"
                },
                Rentals = new List <RentalModel>()
                {
                    new RentalModel
                    {
                        Id        = 1,
                        Status    = "available",
                        Name      = "Baguio House",
                        Occupancy = 6,
                        Price     = 100.00,
                        Type      = "home",
                        LodgingId = 1
                    },
                    new RentalModel
                    {
                        Id        = 2,
                        Status    = "available",
                        Name      = "Baguio Cabin",
                        Occupancy = 4,
                        Price     = 100.00,
                        Type      = "cabin",
                        LodgingId = 1
                    },
                    new RentalModel
                    {
                        Id        = 3,
                        Status    = "booked",
                        Name      = "Waterfront cabin",
                        Occupancy = 2,
                        Price     = 100.00,
                        Type      = "cabin",
                        LodgingId = 1
                    },
                    new RentalModel
                    {
                        Id        = 4,
                        Status    = "available",
                        Name      = "Boat House",
                        Occupancy = 8,
                        Price     = 100.00,
                        Type      = "home",
                        LodgingId = 1
                    }
                },
                Reviews = new List <ReviewModel>()
                {
                    new ReviewModel
                    {
                        Id          = 1,
                        AccountId   = 1,
                        Comment     = "I love it here",
                        Rating      = 10,
                        DateCreated = DateTime.Now,
                        LodgingId   = 1
                    },
                    new ReviewModel
                    {
                        Id          = 2,
                        AccountId   = 1,
                        Comment     = "The flora and fauna is beautiful",
                        Rating      = 10,
                        DateCreated = DateTime.Now,
                        LodgingId   = 1
                    },
                    new ReviewModel
                    {
                        Id          = 3,
                        AccountId   = 1,
                        Comment     = "Nice houses",
                        Rating      = 10,
                        DateCreated = DateTime.Now,
                        LodgingId   = 1
                    },
                    new ReviewModel
                    {
                        Id          = 4,
                        AccountId   = 1,
                        Comment     = "Water is warm",
                        Rating      = 10,
                        DateCreated = DateTime.Now,
                        LodgingId   = 1
                    }
                }
            };

            context.Add(lodging1);
            context.SaveChanges();
        }
예제 #30
0
 public ActionResult Lodging(LodgingModel lodging)
 {
     return(View(lodging));
 }