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 ListAllBusinessesAsync_ReturnBusinesses() { var businessId = 1; var businessName = "business"; var mappingProviderMocked = new Mock <IMappingProvider>(); var dateTimeWrapperMocked = new Mock <IDateTimeWrapper>(); var paginatedListMocked = new Mock <IPaginatedList <BusinessShortInfoDTO> >(); BusinessTestUtils.ResetAutoMapper(); BusinessTestUtils.InitializeAutoMapper(); BusinessTestUtils.GetContextWithBusiness(nameof(ListAllBusinessesAsync_ReturnBusinesses), businessId, businessName); using (var assertContext = new AlphaHotelDbContext(BusinessTestUtils.GetOptions(nameof(ListAllBusinessesAsync_ReturnBusinesses)))) { var businessService = new BusinessService(assertContext, mappingProviderMocked.Object, dateTimeWrapperMocked.Object, paginatedListMocked.Object); var businesses = await businessService.ListAllBusinessesAsync <BusinessDTO>(); Assert.AreEqual(1, 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); } }