Beispiel #1
0
        public async Task ReturnBReviewDTO_IfParamsAreValid()
        {
            //Arrange
            var mockIDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockIBarReviewMapper  = new Mock <IBarReviewMapper>();

            mockIBarReviewMapper
            .Setup(r => r.MapToBarReviewDTO(It.IsAny <BarsUsersReviews>()))
            .Returns <BarsUsersReviews>(r => new BarReviewDTO {
                BarId = r.BarId, AuthorId = r.UserId, Comment = r.Comment
            });

            var options = Utils.GetOptions(nameof(ReturnBReviewDTO_IfParamsAreValid));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new BarReviewService(mockIDateTimeProvider.Object, assertContext, mockIBarReviewMapper.Object);

                var result = await sut.GetBarReviewAsync(2, 2);

                Assert.AreEqual(2, result.BarId);
                Assert.AreEqual(2, result.AuthorId);
            }
        }
        public async Task ReturnTrue_IfBarReviewDeletedSuccesfully()
        {
            //Arrange
            var mockIDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockIBarReviewMapper  = new Mock <IBarReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnTrue_IfBarReviewDeletedSuccesfully));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new BarReviewService(mockIDateTimeProvider.Object, assertContext, mockIBarReviewMapper.Object);

                var result = await sut.DeleteBarReviewAsync(2, 2);

                var deletedReview = assertContext.BarsUsersReviews
                                    .FirstOrDefault(r => r.BarId == 2 && r.UserId == 2);


                Assert.IsTrue(result);
                Assert.AreEqual(true, deletedReview.IsDeleted);
            }
        }
        public async Task ReturnNull_IfBarReviewMissingOrDeleted()
        {
            //Arrange
            var mockIDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockIBarReviewMapper  = new Mock <IBarReviewMapper>();

            var options = Utils.GetOptions(nameof(ReturnNull_IfBarReviewMissingOrDeleted));

            Utils.GetInMemoryDataBase(options);
            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new BarReviewService(mockIDateTimeProvider.Object, assertContext, mockIBarReviewMapper.Object);

                var result = await sut.DeleteBarReviewAsync(3, 1);

                Assert.IsFalse(result);
            }
        }
Beispiel #4
0
        public async Task Return_IfParamsAreValid()
        {
            //Arrange
            var mockIDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockIBarReviewMapper  = new Mock <IBarReviewMapper>();

            var options = Utils.GetOptions(nameof(Return_IfParamsAreValid));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new BarReviewService(mockIDateTimeProvider.Object, assertContext, mockIBarReviewMapper.Object);

                var result = await sut.GetAllBarReviewsAsync(1);

                Assert.AreEqual(2, result.Count);
            }
        }
Beispiel #5
0
        public async Task ReturnNull_IfNoUpdatedBReviewDTO()
        {
            //Arrange
            var mockIDateTimeProvider = new Mock <IDateTimeProvider>();
            var mockIBarReviewMapper  = new Mock <IBarReviewMapper>();

            mockIBarReviewMapper
            .Setup(r => r.MapToBarReview(It.IsAny <BarReviewDTO>()))
            .Returns <BarReviewDTO>(r => new BarsUsersReviews
            {
                BarId   = r.BarId,
                UserId  = r.AuthorId,
                Comment = r.Comment
            });

            mockIBarReviewMapper
            .Setup(r => r.MapToBarReviewDTO(It.IsAny <BarsUsersReviews>()))
            .Returns <BarsUsersReviews>(r => new BarReviewDTO
            {
                BarId    = r.BarId,
                AuthorId = r.UserId,
                Comment  = r.Comment
            });

            var options = Utils.GetOptions(nameof(ReturnNull_IfNoUpdatedBReviewDTO));

            Utils.GetInMemoryDataBase(options);

            //Act & Assert
            using (var assertContext = new CocktailMagicianContext(options))
            {
                var sut = new BarReviewService(mockIDateTimeProvider.Object, assertContext, mockIBarReviewMapper.Object);

                var result = await sut.UpdateBarReviewAsync(1, 1, null);

                Assert.IsNull(result);
            }
        }
 public BarReviewsController(BarReviewService service)
 {
     _service = service;
 }