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 Submit() { var success = await _businessService.CreateBusiness( new Business { Name = Name, TradingName = TradingName, WebAddress = WebAddress, Contact = new HeadContact { FirstName = FirstName, SecondName = SecondName, Email = Email, ContactNumber = ContactNumber }, Office = new HeadOffice { PostCode = PostCode, AddressLine1 = AddressLine1, AddressLine2 = AddressLine2 } }); if (success) { _navigationManager.NavigateTo("/businesses"); Clear(); } }