public void GetAllLocationNamesShould_ReturnAllNames() { var options = new DbContextOptionsBuilder <CarRentalDbContext>() .UseInMemoryDatabase(databaseName: "CarRental_Database_AllLocationNames") .Options; var dbContext = new CarRentalDbContext(options); var locationsService = new LocationsService(dbContext); var locationList = new List <Location>() { new Location { Name = locationNameOne }, new Location { Name = locationNameTwo }, new Location { Name = locationNameThree }, }; dbContext.Locations.AddRange(locationList); dbContext.SaveChanges(); var expected = new List <string> { locationNameOne, locationNameTwo, locationNameThree }; var result = locationsService.GetAllLocationNames().ToList(); Assert.Equal(expected, result); }
public LocationsServiceTest() { vehiclesRepository = Substitute.For <IVehiclesRepository>(); locationsRepository = Substitute.For <ILocationsRepository>(); locationsService = new LocationsService(vehiclesRepository, locationsRepository); }
public void DeleteLocationShould_ReturnFalseIfTheLocationIsReturnPlaceForOrder() { var options = new DbContextOptionsBuilder <CarRentalDbContext>() .UseInMemoryDatabase(databaseName: "CarRental_Database_DeleteLocationWithOrders") .Options; var dbContext = new CarRentalDbContext(options); var locationsService = new LocationsService(dbContext); var location = new Location { Name = locationNameOne }; locationsService.CreateLocation(location); var order = new Order { CarId = 1, ApplicationUserId = Guid.NewGuid().ToString(), PickUpLocationId = 1, ReturnLocationId = 1, Price = 100, RentStart = DateTime.UtcNow.Date, RentEnd = DateTime.UtcNow.Date.AddDays(2) }; dbContext.Orders.Add(order); var result = locationsService.DeleteLocation(locationNameTwo).GetAwaiter().GetResult(); Assert.False(result); }
private static List <LocationHolder> GetAllLocations() { List <LocationHolder> locationHolders = new List <LocationHolder>(); LocationsService locations = ServiceLocator.Instance.GetService <LocationsService>(); var items = locations.Items; foreach (var item in items) { if (item.Location.LatitudeLongitude == null) { continue; } var lh = new LocationHolder { Location = item.Location.LatitudeLongitude.Location, FilmName = item.Location.Name, FilmSiteLink = $"{item.ImageFolder}/index.html" }; locationHolders.Add(lh); } return(locationHolders); }
static void Main(string[] args) { SearchLocationsRequest request = CreateSearchLocationsRequest(); // LocationsService service = new LocationsService(); if (usePropertyFile()) { service.Url = getProperty("endpoint"); } // try { // Call the Locations web service passing in a SearchLocationsRequest and returning a SearchLocationsReply SearchLocationsReply reply = service.searchLocations(request); if (reply.HighestSeverity == NotificationSeverityType.SUCCESS || reply.HighestSeverity == NotificationSeverityType.NOTE || reply.HighestSeverity == NotificationSeverityType.WARNING) { ShowSearchLocationsReply(reply); } ShowNotifications(reply); } catch (SoapException e) { Console.WriteLine(e.Detail.InnerText); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press any key to quit!"); Console.ReadKey(); }
public void GetAllLocationsAsKeyValuePairShouldReturnCorrectNumber() { var list = new List <Location>() { new Location { Id = 1, Name = "Plovdiv/Bulgaria", }, new Location { Id = 2, Name = "Sofia/Bulgaria", }, new Location { Id = 3, Name = "Stara Zagora/Bulgaria", }, }; var repository = new Mock <IRepository <Location> >(); repository.Setup(r => r.AllAsNoTracking()).Returns(() => list.AsQueryable()); var service = new LocationsService(repository.Object); var locations = service.GetAllLocationsAsKeyValuePair(); Assert.Equal(3, locations.Count()); repository.Verify(x => x.AllAsNoTracking(), Times.Once); }
public void AddLocationTest() { Mock <IImagesService> imagesServiceMock = new Mock <IImagesService>(); imagesServiceMock .Setup(ls => ls.UploadImageAsync(new StreamMock())) .Returns(Task.FromResult("url")); using (ApplicationDbContext dbContext = serviceProvider.GetService <ApplicationDbContext>()) { LocationsService locationsService = new LocationsService(dbContext, serviceProvider.GetService <IMapper>(), serviceProvider.GetService <IConfiguration>(), imagesServiceMock.Object); AddLocationViewModel locationViewModel = new AddLocationViewModel { Title = "LocationTitle", Description = "LocationDescription", TownId = 1, }; locationsService.AddAsync(locationViewModel).GetAwaiter().GetResult(); Location location = dbContext.Locations.First(); Assert.Equal(locationViewModel.Title, location.Title); } }
public LibrariesController(LibrariesService librariesService, IMapper mapper, LocationsService locationsService, RolesService rolesService) { Locations = locationsService; Libraries = librariesService; Roles = rolesService; Mapper = mapper; }
public IEnumerable <Location> Get([FromBody] GridModel model) { var locations = new List <Location>(); if (model.SearchingColumns.Count > 0 && !string.IsNullOrEmpty(model.SearchingText)) { locations = LocationsService.GetLocations() .Where(location => location.Description.ToLower().Contains(model.SearchingText.ToLower()) || location.Name.ToLower().Contains(model.SearchingText.ToLower())) .ToList(); } else if (model.ParentId == null) { locations = LocationsService.GetLocations() .Where(location => location.ParentId == model.ParentId) .ToList(); } else { locations = LocationsService.GetLocations(); } return(locations); }
private static string ListAllLocations() { StringBuilder sb = new StringBuilder(); sb.Append("<br/>"); sb.Append("<br/>"); LocationsService locations = ServiceLocator.Instance.GetService <LocationsService>(); var items = locations.Items; foreach (var item in items) { string name = item.Name; string address = item.Location?.Address; string html = $"<a href='{item.ImageFolder}/index.html' >{name}</a>"; sb.Append($"<h4> {html}</h4>"); sb.Append($"<p> {address}</p>"); sb.Append("<br/>"); sb.Append("<br/>"); } return(sb.ToString()); }
public void EditLocation_Should_ThrowException_If_LocationExists() { Location existingLocation = new Location() { ID = 1, Name = "Location1", Active = true, AdditionalInformation = "Original additional info" }; Location edittedLocation = new Location() { ID = 1, Name = "Location2", Active = true, AdditionalInformation = "Editted additional info" }; mockLocationRepository.Setup(m => m.GetLocationByName(edittedLocation.Name)).Returns(edittedLocation); mockLocationRepository.Setup(m => m.UpdateLocation(edittedLocation)); LocationsService locationService = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object); Assert.Throws <LocationExistsException>(() => locationService.EditLocation(existingLocation, edittedLocation)); mockLocationRepository.Verify(m => m.UpdateLocation(edittedLocation), Times.Never); }
public void AddLocationWithoutName() { Mock <IImagesService> imagesServiceMock = new Mock <IImagesService>(); imagesServiceMock .Setup(ls => ls.UploadImageAsync(new StreamMock())) .Returns(Task.FromResult("url")); using (ApplicationDbContext dbContext = serviceProvider.GetService <ApplicationDbContext>()) { IConfiguration configuration = serviceProvider.GetService <IConfiguration>(); LocationsService locationsService = new LocationsService(dbContext, serviceProvider.GetService <IMapper>(), configuration, imagesServiceMock.Object); AddLocationViewModel locationViewModel = new AddLocationViewModel { Description = "LocationDescription", TownId = 1, }; locationsService.AddAsync(locationViewModel).GetAwaiter().GetResult(); int locations = dbContext.Locations.CountAsync().GetAwaiter().GetResult(); Location locationWithoutName = dbContext.Locations.FirstAsync().GetAwaiter().GetResult(); Assert.Equal(configuration["DefaultLocationName"], locationWithoutName.Title); Assert.True(locations == 1); } }
public IActionResult UpdateStorageArea(Guid siteId, Guid areaId, [FromBody] StorageAreaUpdateRequest storageAreaUpdateRequest) { if (siteId == null || areaId == null || storageAreaUpdateRequest == null || string.IsNullOrWhiteSpace(storageAreaUpdateRequest.Name)) { return(HandleBadRequest("A valid storage site ID, area ID and name have to be supplied.")); } try { StorageArea area = LocationsService.UpdateStorageArea(siteId, areaId, storageAreaUpdateRequest.Name); return(Ok(area)); } catch (StorageSiteNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (StorageAreaNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public void EditLocation_Should_Edit() { Location existingLocation = new Location() { ID = 1, Name = "Location1", Active = true, AdditionalInformation = "Original additional info" }; Location edittedLocation = new Location() { ID = 1, Name = "Location1", Active = true, AdditionalInformation = "Editted additional info" }; mockLocationRepository.Setup(m => m.UpdateLocation(edittedLocation)); LocationsService locationService = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object); locationService.EditLocation(existingLocation, edittedLocation); mockLocationRepository.Verify(m => m.UpdateLocation(edittedLocation), Times.Once); }
public static void Build(IModelEvent pageDetails) { pageDetails.ExtraIncludes.Add(eWolfBootstrap.Enums.BootstrapOptions.GALLERY); pageDetails.CopyLayoutsToKeywords(); Console.WriteLine(pageDetails.Name); List <string> images = ImageHelper.GetAllImages(pageDetails.ImagesPath); AddImageToLayouts(pageDetails, images); // create folders Directory.CreateDirectory(Constants.RootPath + "\\" + Constants.ModelEvents); Directory.CreateDirectory(Constants.RootPath + "\\" + Constants.ModelEvents + "\\" + pageDetails.ImageFolder); Directory.CreateDirectory(Constants.RootPath + "\\" + Constants.ModelEvents + "\\" + pageDetails.ImageFolder + @"\images"); string htmlpath = Constants.RootPath + "\\" + Constants.ModelEvents + "\\" + pageDetails.ImageFolder + "\\"; string imagePath = Constants.RootPath + "\\" + Constants.ModelEvents + "\\" + pageDetails.ImageFolder + @"\images"; eWolfBootstrap.Interfaces.IPageBuilder pageBuilder = new PageBuilder("index.html", htmlpath, pageDetails, "../../"); pageBuilder.Append(NavBarHelper.NavBar("../../")); pageBuilder.Append("<div class='container mt-4'>"); pageBuilder.Append(Jumbotron(pageDetails)); LocationsService ls = ServiceLocator.Instance.GetService <LocationsService>(); ls.AddLocation(pageDetails); AddImagesByLayout(images, pageDetails, htmlpath, imagePath, pageBuilder); pageBuilder.Output(); }
public IActionResult GetStorageSites( [FromQuery] bool getAll = false, [FromQuery] int page = 1, [FromQuery] int elementsPerPage = 10, [FromQuery] string search = null) { try { IEnumerable <StorageSite> sites = null; if (string.IsNullOrWhiteSpace(search)) { sites = LocationsService.GetAllStorageSites(); } else { sites = LocationsService.SearchStorageSitesByName(search); } IEnumerable <StorageSite> paginatedSites = sites; if (!getAll) { paginatedSites = sites.Skip((page - 1) * elementsPerPage).Take(elementsPerPage); } return(Ok(new PaginatedResponse(paginatedSites, sites.Count()))); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
/// <summary> /// Initializes a new instance of the <see cref="InventoryController"/> class. /// </summary> /// <param name="loggerFactory">A factory to create loggers from.</param> /// <param name="inventoryService">The service providing inventory functionality.</param> /// <param name="materialsService">A service providing material data.</param> /// <param name="locationsService">A service providing locations data.</param> public InventoryController(ILoggerFactory loggerFactory, InventoryService inventoryService, MaterialsService materialsService, LocationsService locationsService) { Logger = loggerFactory.CreateLogger <InventoryController>(); InventoryService = inventoryService; MaterialsService = materialsService; LocationsService = locationsService; }
public LocationsController(IBookingRepository bookingRepository, ILocationRepository locationRepository, IDirectoryService directoryService, EmailHelper emailHelper) { _logger = NLog.LogManager.GetCurrentClassLogger(); _directoryService = directoryService; _locationService = new LocationsService(_logger, locationRepository, bookingRepository, directoryService, emailHelper); _locationRepository = locationRepository; _bookingRepository = bookingRepository; _logger.Trace(LoggerHelper.InitializeClassMessage()); }
public IActionResult CreateStorageSite([FromBody] StorageSiteCreationRequest storageSiteCreationRequest) { if (storageSiteCreationRequest == null || string.IsNullOrWhiteSpace(storageSiteCreationRequest.Name)) { return(HandleBadRequest("A valid storage site name has to be supplied.")); } StorageSite site = LocationsService.CreateStorageSite(storageSiteCreationRequest.Name); return(Created(GetNewResourceUri(site.Id), site)); }
public IActionResult CreateStorageArea(Guid siteId, [FromBody] StorageAreaCreationRequest storageAreaCreationRequest) { if (storageAreaCreationRequest == null || string.IsNullOrWhiteSpace(storageAreaCreationRequest.Name)) { return(HandleBadRequest("A valid storage area name has to be supplied.")); } StorageArea area = LocationsService.AddAreaToStorageSite(siteId, storageAreaCreationRequest.Name); return(Created(GetNewResourceUri(area.Id), area)); }
private static ItemNewViewModel ItemNewViewModel_WithMockDependencies_And_FakeRepository(out FakeLocationsRepository mockLocationsRepository) { var mockNavigationService = new Mock <INavigationService>(); var mockDialogService = new Mock <IDialogService>(); var mockItemsService = new Mock <IItemsService>(); mockLocationsRepository = new FakeLocationsRepository(); var mockLocationService = new LocationsService(mockLocationsRepository, new InMemoryBlobCache()); var itemNewViewModel = new ItemNewViewModel(mockNavigationService.Object, mockDialogService.Object, mockItemsService.Object, mockLocationService); return(itemNewViewModel); }
public async Task LoadLocationsCleansData(int locationId, string locationName, string localAuthorityName, string locationAuthorityDistrict, int expectedNumberOfLocations) { //Setup A.CallTo(() => fakeNationalStatisticsLocationService.GetLocationsAsync()).Returns(GetTestLocations(locationId, locationName, localAuthorityName, locationAuthorityDistrict)); var loadLocationsService = new LocationsService(fakeLogger, fakeNationalStatisticsLocationService); //Act var result = await loadLocationsService.GetCleanLocationsAsync().ConfigureAwait(false); //Assert A.CallTo(() => fakeNationalStatisticsLocationService.GetLocationsAsync()).MustHaveHappenedOnceExactly(); result.Count().Should().Be(expectedNumberOfLocations); }
public void ToggleLocationActive_Should_Update_When_False_And_HasExistingBookings() { List <Booking> existingBookings = new List <Booking>() { new Booking() { ID = 1, PID = "1234", Owner = "Reece" }, new Booking() { ID = 2, PID = "5678", Owner = "Charlie" } }; Location existingLocation = new Location() { ID = 1, Name = "Location1", Active = true, AdditionalInformation = "Original additional info" }; mockBookingRepository.Setup(x => x.GetByDateAndLocation(It.IsAny <DateTime>().Date, existingLocation)).Returns(existingBookings); mockDirectoryRepository.Setup(m => m.GetUser(It.Is <Pid>(x => x.Identity == "1234"))).Returns(new User() { EmailAddress = "*****@*****.**" }); mockDirectoryRepository.Setup(m => m.GetUser(It.Is <Pid>(x => x.Identity == "5678"))).Returns(new User() { EmailAddress = "*****@*****.**" }); string fakeFromEmailAddress = "*****@*****.**"; string fakeBody = "Some Body Contents"; mockEmailHelper.Setup(m => m.GetEmailMarkup(It.IsAny <string>(), It.IsAny <List <Booking> >())).Returns(fakeBody); mockEmailHelper.Setup(m => m.SendEmail(fakeFromEmailAddress, It.IsAny <string>(), It.IsAny <string>(), fakeBody, It.IsAny <bool>())); NameValueCollection appSettings = new NameValueCollection(); appSettings.Add("fromEmail", fakeFromEmailAddress); LocationsService service = new LocationsService(logger.Object, mockLocationRepository.Object, mockBookingRepository.Object, mockDirectoryRepository.Object, mockEmailHelper.Object); service.ToggleLocationActive(existingLocation, false, appSettings); mockLocationRepository.Verify(m => m.UpdateLocation(existingLocation), Times.Once); mockBookingRepository.Verify(m => m.Delete(It.IsAny <List <Booking> >()), Times.Once); mockEmailHelper.Verify(m => m.SendEmail(fakeFromEmailAddress, It.IsAny <string>(), It.IsAny <string>(), fakeBody, It.IsAny <bool>()), Times.Exactly(existingBookings.Count)); }
public async Task GetNameById_WithInvalidData_ShouldWorkCorrectly(int?id) { var context = WilderExperienceContextInMemoryFactory.InitializeContext(); await this.SeedData(context); var repository = new EfDeletableEntityRepository <Location>(context); var service = new LocationsService(repository); var name = service.GetNameById(id); Assert.Null(name); }
public async Task GetIdByName_WithInvalidData_ShouldWorkCorrectly(string name) { var context = WilderExperienceContextInMemoryFactory.InitializeContext(); await this.SeedData(context); var repository = new EfDeletableEntityRepository <Location>(context); var service = new LocationsService(repository); var actualId = service.GetIdByName(name); Assert.True(actualId == 0); }
public void GetAllLocationsAsKeyValuePairShouldReturnZeroForEmptyDatabase() { var list = new List <Location>(); var repository = new Mock <IRepository <Location> >(); repository.Setup(r => r.AllAsNoTracking()).Returns(() => list.AsQueryable()); var service = new LocationsService(repository.Object); var locations = service.GetAllLocationsAsKeyValuePair(); Assert.Empty(locations); repository.Verify(x => x.AllAsNoTracking(), Times.Once); }
public IActionResult GetStorageSite(Guid id) { try { return(Ok(LocationsService.GetStorageSite(id))); } catch (StorageSiteNotFoundException exception) { return(HandleResourceNotFoundException(exception)); } catch (Exception exception) { return(HandleUnexpectedException(exception)); } }
public IEnumerable <Location> GetTest([FromBody] GridModel model) { var locations = new List <Location>(); if (model.ParentId == null) { locations = LocationsService.GetLocations() .Where(location => location.ParentId == model.ParentId) .ToList(); } else { locations = LocationsService.GetLocations(); } return(locations); }
public async Task GetNameById_ShouldWorkCorrectly() { var context = WilderExperienceContextInMemoryFactory.InitializeContext(); await this.SeedData(context); var repository = new EfDeletableEntityRepository <Location>(context); var service = new LocationsService(repository); var firstLocation = context.Locations.First(); var expectedName = firstLocation.Name; var id = firstLocation.Id; var actualName = service.GetNameById(id); Assert.True(expectedName == actualName); }
public async Task Search_ShouldWorkCorrectly() { var context = WilderExperienceContextInMemoryFactory.InitializeContext(); await this.SeedData(context); var repository = new EfDeletableEntityRepository <Location>(context); var service = new LocationsService(repository); var firstLocation = context.Locations.First(); var name = firstLocation.Name; var resultLocation = service.Search <LocationViewModel>(name); var firstResultLocation = resultLocation.FirstOrDefault(); Assert.True(resultLocation.Count() == 1); Assert.Equal(firstLocation.Name, firstResultLocation.Name); }