コード例 #1
0
        public void Create_ThrowExceptionIfHotelWithGivenIdDoNotExist()
        {
            var model = new HotelReviewWriteViewModel {
                HotelId = 1
            };
            Action testCode = () => this.hotelReviewsService.Create(model, "testUsername");

            testCode.ShouldThrow <HotelNullException>();
        }
コード例 #2
0
        public IActionResult Write(HotelReviewWriteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(base.RedirectToAction("Write", new { hotelId = model.HotelId }));
            }

            this.hotelReviewsService.Create(model, this.User.Identity.Name);

            return(base.RedirectToAction("Details", "Hotels", new { model.HotelId }));
        }
コード例 #3
0
        public IActionResult Write(int hotelId)
        {
            if (this.hotelReviewsService.CheckForExistingReview(hotelId, this.User.Identity.Name))
            {
                string errorMsg = "You already write a review for this hotel!";
                return(base.View(GlobalConstants.ErrorViewName, errorMsg));
            }

            string hotelName = this.hotelsService.GetNameById(hotelId);
            var    viewModel = new HotelReviewWriteViewModel {
                HotelId = hotelId, HotelName = hotelName
            };

            return(base.View(viewModel));
        }
コード例 #4
0
        public void Create(HotelReviewWriteViewModel model, string username)
        {
            if (!this.hotelsService.CheckExistById(model.HotelId))
            {
                throw new HotelNullException();
            }

            HotelReview hotelReview = this.mapper.Map <HotelReview>(model);

            MbUser user = this.usersService.GetByUsername(username);

            hotelReview.User = user;

            this.dbContext.HotelReviews.Add(hotelReview);
            this.dbContext.SaveChanges();
        }
コード例 #5
0
        public void Create_ShouldCreateNewReviewCorrectly()
        {
            int hotelId = 1;

            this.dbContext.Hotels.Add(new Hotel {
                Id = hotelId
            });
            this.dbContext.SaveChanges();

            Rating        rating        = Rating.Average;
            Season        timeOfYear    = Season.Autumn;
            TravellerType travellerType = TravellerType.Business;

            var model = new HotelReviewWriteViewModel
            {
                HotelId       = hotelId,
                Rating        = rating,
                TimeOfYear    = timeOfYear,
                TravellerType = travellerType,
            };

            string username = "******";

            this.dbContext.Users.Add(new MbUser {
                UserName = username
            });
            this.dbContext.SaveChanges();

            this.hotelReviewsService.Create(model, username);
            HotelReview result = this.dbContext.HotelReviews.First();

            result.ShouldSatisfyAllConditions
            (
                () => result.HotelId.ShouldBe(hotelId),
                () => result.Rating.ShouldBe(rating),
                () => result.TimeOfYear.ShouldBe(timeOfYear),
                () => result.TravellerType.ShouldBe(travellerType),
                () => result.User.UserName.ShouldBe(username)
            );
        }