Пример #1
0
        public async Task Return_WhenFeedbackIsNotDeleted()
        {
            var text   = "text";
            var author = "gosho";
            var rating = 5;

            var editedText   = "new text";
            var editedAuthor = "pesho";
            var editedRating = 4;
            var isDeleted    = false;

            var businessId = 1;
            var feedbackId = 1;

            var paginatedListMocked   = new Mock <IPaginatedList <FeedbackDTO> >();
            var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>();
            var censorMocked          = new Mock <ICensor>();

            FeedbackTestUtils.GetContextWithFullFeedback(nameof(Return_WhenFeedbackIsNotDeleted), text, rating, author, businessId, feedbackId);

            using (var assertContext = new AlphaHotelDbContext(FeedbackTestUtils.GetOptions(nameof(Return_WhenFeedbackIsNotDeleted))))
            {
                var feedbackService = new FeedbackService(assertContext, paginatedListMocked.Object, dateTimeWrapperMocked.Object, censorMocked.Object);
                await feedbackService.EditFeedback(feedbackId, editedAuthor, editedText, editedRating, isDeleted);

                var feedback = await assertContext.Feedbacks.FirstOrDefaultAsync(f => f.Id == feedbackId);

                Assert.AreEqual(editedText, feedback.Text);
                Assert.AreEqual(editedRating, feedback.Rate);
                Assert.AreEqual(editedAuthor, feedback.Author);
                Assert.IsFalse(feedback.IsDeleted);
                Assert.AreEqual(feedback.ModifiedOn, dateTimeWrapperMocked.Object.Now());
            }
        }
Пример #2
0
        public async Task ThrowException_WhenFeedbackIsNotFound()
        {
            var text                  = "text";
            var author                = "gosho";
            var rating                = 5;
            var businessId            = 1;
            var isDeleted             = false;
            var feedbackId            = 1;
            var wrongFeedbackId       = 2;
            var paginatedListMocked   = new Mock <IPaginatedList <FeedbackDTO> >();
            var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>();
            var censorMocked          = new Mock <ICensor>();

            FeedbackTestUtils.GetContextWithFullFeedback(nameof(ThrowException_WhenFeedbackIsNotFound), text, rating, author, businessId, feedbackId);

            using (var assertContext = new AlphaHotelDbContext(FeedbackTestUtils.GetOptions(nameof(ThrowException_WhenFeedbackIsNotFound))))
            {
                var feedbackService = new FeedbackService(assertContext, paginatedListMocked.Object, dateTimeWrapperMocked.Object, censorMocked.Object);

                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() => await feedbackService.EditFeedback(wrongFeedbackId, author, text, rating, isDeleted));
            }
        }