示例#1
0
 private void bSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(tbContent.Text) || cbMovie.SelectedIndex == 0 || cbRating.SelectedIndex == 0)
         {
             MessageBox.Show("Fields cannot be empty!");
             return;
         }
         ReviewModel addReviewModel = new ReviewModel();
         addReviewModel.Content = tbContent.Text;
         addReviewModel.Rating  = Convert.ToInt32(cbRating.SelectedItem);
         addReviewModel.Movie   = (Movie)cbMovie.SelectedItem;
         reviewsService.Add(addReviewModel);
         MessageBox.Show("Review added!");
     }
     catch (Exception exc)
     {
         MessageBox.Show(Convert.ToString(exc));
     }
 }
示例#2
0
        public async Task AddShouldAddCorrectDataAndReturnTrue()
        {
            var db     = this.GetDatabase();
            var config = new Mock <IConfiguration>();

            config.Setup(c => c["WebSiteSettings:Reviews:AutoPublish"])
            .Returns("true");
            config.Setup(c => c["WebSiteSettings:Reviews:ReviewsMinRatingToPublish"])
            .Returns("4");
            var    reviewService = new ReviewsService(db, config.Object);
            double rating        = 5;
            string text          = "Review";
            string userId        = "1";

            var result = await reviewService.Add(rating, text, userId);

            result.Should().Be(true);
            var reviews = await db.Reviews.ToListAsync();

            reviews.Should().HaveCount(1);
            reviews.Should().Match(r => r.ElementAt(0).Rating == rating &&
                                   r.ElementAt(0).Text == text && r.ElementAt(0).AuthorId == userId);
        }