public async Task ThrowException_WhenBusinessAlreadyExists()
        {
            var businessName     = "business";
            var location         = "tsarigradsko";
            var gpsCoordinates   = "3424444";
            var about            = "about";
            var shortDescription = "shortDescription";
            var coverPicture     = "path";
            var pics             = new List <string>()
            {
                "path", "otherPath"
            };
            var facilities = new List <int>()
            {
                1, 2
            };
            var businessId = 1;

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

            BusinessTestUtils.GetContextWithBusiness(nameof(ThrowException_WhenBusinessAlreadyExists), businessId, businessName);

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

                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() => await businessService.CreateBusiness(businessName, location, gpsCoordinates, about, shortDescription, coverPicture, pics, facilities));
            }
        }
        public async Task ReturnBusiness_WhenAllParametersArePassed()
        {
            var name             = "business";
            var location         = "tsarigradsko";
            var gpsCoordinates   = "3424444";
            var about            = "about";
            var shortDescription = "shortDescription";
            var coverPicture     = "path";
            var pics             = new List <string>()
            {
                "path", "otherPath"
            };
            var facilities = new List <int>()
            {
                1, 2
            };

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

            Business mapInput = null;

            mappingProviderMocked.Setup(mpm => mpm.MapTo <BusinessDTO>(It.IsAny <Business>()))
            .Callback <object>(inputArg => mapInput = inputArg as Business);

            var createdOn = dateTimeWrapperMocked.Object.Now();

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ReturnBusiness_WhenAllParametersArePassed))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                await businessService.CreateBusiness(name, location, gpsCoordinates, about, shortDescription, coverPicture, pics, facilities);

                Assert.AreEqual(name, mapInput.Name);
                Assert.AreEqual(location, mapInput.Location);
                Assert.AreEqual(gpsCoordinates, mapInput.GPSCoordinates);
                Assert.AreEqual(about, mapInput.About);
                Assert.AreEqual(shortDescription, mapInput.ShortDescription);
                Assert.AreEqual(coverPicture, mapInput.CoverPicture);
                Assert.AreEqual(pics.Count, mapInput.Pictures.Count);
                Assert.AreEqual(facilities.Count, mapInput.BusinessesFacilities.Count);
                Assert.AreEqual(createdOn, mapInput.CreatedOn);
            }
        }
        public async Task ThrowException_WhenLogBookAlreadyExists()
        {
            var logbookName = "logbook";
            var businessId  = 1;

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

            BusinessTestUtils.GetContextWithBusinessAndLogBook(nameof(ThrowException_WhenLogBookAlreadyExists), businessId, logbookName);

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

                await Assert.ThrowsExceptionAsync <ArgumentException>(
                    async() => await businessService.AddLogBookToBusinessAsync(logbookName, businessId));
            }
        }
        public async Task FindAllLogsWithGivenParameters_WhenLogsExists()
        {
            var businessId = 1;
            var date       = DateTime.Now;

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

            var createdOn = dateTimeWrapperMocked.Object.Now();

            BusinessTestUtils.GetContextWithLogs(nameof(FindAllLogsWithGivenParameters_WhenLogsExists), businessId, date);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(FindAllLogsWithGivenParameters_WhenLogsExists))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var result          = await businessService.DeleteLogsForDate(businessId, date);

                Assert.AreEqual(2, result);
            }
        }
        public async Task ListBusinessLogbooksAsync_ReturnLogBooks()
        {
            var businessId  = 1;
            var logbookName = "logbook";

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

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusinessAndLogBook(nameof(ListBusinessLogbooksAsync_ReturnLogBooks), businessId, logbookName);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ListBusinessLogbooksAsync_ReturnLogBooks))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var logbooks        = await businessService.ListBusinessLogbooksAsync(businessId);

                Assert.AreEqual(1, logbooks.Count);
            }
        }
        public async Task ChangeIsDeletedToTrue_WhenLogsMatched()
        {
            var businessId = 1;
            var date       = DateTime.Now;

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

            var createdOn = dateTimeWrapperMocked.Object.Now();

            BusinessTestUtils.GetContextWithLogs(nameof(ChangeIsDeletedToTrue_WhenLogsMatched), businessId, date);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ChangeIsDeletedToTrue_WhenLogsMatched))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var result          = await businessService.DeleteLogsForDate(businessId, date);

                Assert.AreEqual(2, assertContext.Logs.Count(l => l.IsDeleted == true));
                //Assert.IsTrue(assertContext.Logs.All(l => l.IsDeleted == true));
            }
        }
        public async Task ReturnBusinesses_ContainingKeyword()
        {
            var businessId   = 1;
            var businessName = "business";
            var keyword      = "busi";

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

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusiness(nameof(ReturnBusinesses_ContainingKeyword), businessId, businessName);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ReturnBusinesses_ContainingKeyword))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                var businesses      = await businessService.ListAllBusinessesContainsKeyWordAsync(keyword);

                Assert.AreEqual(1, businesses.Count);
            }
        }
Example #8
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);
            }
        }
Example #9
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);
            }
        }
        public async Task ListAllBusinessesByPageAsync_CallCreateAsyncOnce()
        {
            var businessId   = 1;
            var businessName = "business";

            var pageNumber = 1;
            var pageSize   = 2;

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

            BusinessTestUtils.ResetAutoMapper();
            BusinessTestUtils.InitializeAutoMapper();
            BusinessTestUtils.GetContextWithBusiness(nameof(ListAllBusinessesByPageAsync_CallCreateAsyncOnce), businessId, businessName);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ListAllBusinessesByPageAsync_CallCreateAsyncOnce))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                await businessService.ListAllBusinessesByPageAsync(pageNumber, pageSize);

                paginatedListMocked.Verify(pl => pl.CreateAsync(It.IsAny <IQueryable <BusinessShortInfoDTO> >(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()), Times.Once);
            }
        }
        public async Task Return_WhenLogBookIsAdded()
        {
            var logbookName = "logbook";
            var businessId  = 1;

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

            //BusinessTestUtils.GetContextWithCategory(nameof(Return_WhenLogBookIsAdded), categoryName);

            using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(Return_WhenLogBookIsAdded))))
            {
                var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object);
                await businessService.AddLogBookToBusinessAsync(logbookName, businessId);

                var business = await assertContext.Businesses.FirstOrDefaultAsync(b => b.Id == businessId);

                var logbook = await assertContext.LogBooks.FirstOrDefaultAsync(lb => lb.BusinessId == businessId);

                Assert.AreEqual(logbookName, logbook.Name);
                Assert.AreEqual(businessId, logbook.BusinessId);
            }
        }
Example #12
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));
            }
        }