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 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 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); } }
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); } }
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 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)); } }