示例#1
0
        public async Task FindDetailedBusinessAsync_ReturnBusinesses()
        {
            var businessId     = 1;
            var feedbackCount  = 1;
            var feedbackRating = 5;

            var mappingProviderMocked = new Mock <IMappingProvider>();
            var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>();
            var paginatedListMocked   = new Mock <IPaginatedList <BusinessShortInfoDTO> >();

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusinessAndFeedback(nameof(FindDetailedBusinessAsync_ReturnBusinesses), businessId, feedbackRating);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(FindDetailedBusinessAsync_ReturnBusinesses))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var business        = await businessService.FindDetaliedBusinessAsync(businessId, feedbackCount);

                Assert.AreEqual(feedbackCount, business.Feedbacks.Count);
            }
        }
示例#2
0
        public async Task ListTopNBusinessesAsync_ReturnZero_WhenTheBusinessHasNoFeedbacks()
        {
            var count = 0;

            var businessId     = 1;
            var feedbackRating = 5;

            var mappingProviderMocked = new Mock <IMappingProvider>();
            var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>();
            var paginatedListMocked   = new Mock <IPaginatedList <BusinessShortInfoDTO> >();

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusinessAndFeedback(nameof(ListTopNBusinessesAsync_ReturnZero_WhenTheBusinessHasNoFeedbacks), businessId, feedbackRating);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ListTopNBusinessesAsync_ReturnZero_WhenTheBusinessHasNoFeedbacks))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var businesses      = await businessService.ListTopNBusinessesAsync(count);

                Assert.AreEqual(count, businesses.Count);
            }
        }
示例#3
0
        public async Task FindDetailedBusinessAsync_ThrowException_WhenBusinessIsNotFound()
        {
            var businessId      = 1;
            var wrongBusinessId = 2;
            var feedbacksCount  = 1;

            var feedbackRating = 5;

            var mappingProviderMocked = new Mock <IMappingProvider>();
            var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>();
            var paginatedListMocked   = new Mock <IPaginatedList <BusinessShortInfoDTO> >();

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusinessAndFeedback(nameof(FindDetailedBusinessAsync_ThrowException_WhenBusinessIsNotFound), businessId, feedbackRating);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(FindDetailedBusinessAsync_ThrowException_WhenBusinessIsNotFound))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);

                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() => await businessService.FindDetaliedBusinessAsync(wrongBusinessId, feedbacksCount));
            }
        }