public ILocationModel Update(ILocationModel model) { // Validate model BusinessWorkflowBase.ValidateRequiredNullableID(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Find existing entity // ReSharper disable once PossibleInvalidOperationException var existingEntity = LocationsRepository.Get(model.Id.Value); // Check if we would be applying identical information, if we are, just return the original // ReSharper disable once SuspiciousTypeConversion.Global if (LocationMapper.AreEqual(model, existingEntity)) { return(LocationMapper.MapToModel(existingEntity)); } // Map model to an existing entity LocationMapper.MapToEntity(model, ref existingEntity); existingEntity.UpdatedDate = BusinessWorkflowBase.GenDateTime; // Update it LocationsRepository.Update(LocationMapper.MapToEntity(model)); // Try to Save Changes LocationsRepository.SaveChanges(); // Return the new value return(Get(existingEntity.Id)); }
//Constructors public Agent(Agent[,,] map, LocationMapper locationMapper, int energy) { this.age = 0; this.map = map; this.locationMapper = locationMapper; this.energy = energy; }
//Constructors public ThinkingAgent(Agent[,,] map, LocationMapper locationMapper, int energy, Random rand) : base(map, locationMapper, energy) { this.rand = rand; brain = new Brain(rand); determinePerceptionOffsets(); }
public void Verify_MapToEntity_WithExistingEntity_AssignsLocationProperties() { // Arrange var mapper = new LocationMapper(); var model = LocationsMockingSetup.DoMockingSetupForLocationModel(); // Act ILocation existingEntity = new Location { Id = 1 }; mapper.MapToEntity(model.Object, ref existingEntity); // Assert Assert.Equal(model.Object.StartYear, existingEntity.StartYear); // Related Objects Assert.Equal(model.Object.FirstIssueAppearanceId, existingEntity.FirstIssueAppearanceId); Assert.Equal(model.Object.PrimaryImageFileId, existingEntity.PrimaryImageFileId); // Associated Objects model.VerifyGet(x => x.LocationAliases, Times.Once); //Assert.Equal(model.Object.LocationAliases?.Count, existingEntity.LocationAliases?.Count); model.VerifyGet(x => x.LocationAppearedInIssues, Times.Once); //Assert.Equal(model.Object.LocationAppearedInIssues?.Count, existingEntity.LocationAppearedInIssues?.Count); model.VerifyGet(x => x.LocationIssues, Times.Once); //Assert.Equal(model.Object.LocationIssues?.Count, existingEntity.LocationIssues?.Count); model.VerifyGet(x => x.LocationMovies, Times.Once); //Assert.Equal(model.Object.LocationMovies?.Count, existingEntity.LocationMovies?.Count); model.VerifyGet(x => x.LocationStoryArcs, Times.Once); //Assert.Equal(model.Object.LocationStoryArcs?.Count, existingEntity.LocationStoryArcs?.Count); model.VerifyGet(x => x.LocationVolumes, Times.Once); //Assert.Equal(model.Object.LocationVolumes?.Count, existingEntity.LocationVolumes?.Count); }
public void Map() { // Arrange var start = new DateTime(2010, 1, 1); var end = DateUtility.MaxDate; var range = new DateRange(start, end); var id = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contractDetails = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { id }, Details = contractDetails, MdmSystemData = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = start, EndDate = end } }; // NB Don't assign validity here, want to prove SUT sets it var details = new Location(); var mapping = new LocationMapping(); var mappingEngine = new Mock<IMappingEngine>(); mappingEngine.Setup(x => x.Map<EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(id)).Returns(mapping); mappingEngine.Setup(x => x.Map<EnergyTrading.MDM.Contracts.Sample.LocationDetails, Location>(contractDetails)).Returns(details); var mapper = new LocationMapper(mappingEngine.Object); // Act var candidate = mapper.Map(contract); // Assert //Assert.AreEqual(1, candidate.Details.Count, "Detail count differs"); Assert.AreEqual(1, candidate.Mappings.Count, "Mapping count differs"); Check(range, details.Validity, "Validity differs"); }
public ActionResult <Location> Get() { var location = _locationService.GetCurrent(); var locationMapped = LocationMapper.DomainToSDK(location); return(locationMapped); }
public async Task <DAL.App.DTO.Location> FindForUserAsync(int id, int userId) { var Location = await RepositoryDbSet .FirstOrDefaultAsync(m => m.Id == id && m.AppUserId == userId); return(LocationMapper.MapFromDomain(Location)); }
public void TestMapByCountryLocationArea() { var locationMapper = new LocationMapper(_locationQuery); // Ballarat LocationReference locationRef = locationMapper.Map("Australia", "VIC Other", "Ballarat", null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("VIC", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("Ballarat", locationRef.NamedLocation.Name); // Albury Wodonga locationRef = locationMapper.Map("Australia", "NSW Other", "Albury Wodonga", null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("NSW", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("Albury", locationRef.NamedLocation.Name); // Alice Springs locationRef = locationMapper.Map("Australia", "NT Other", "Alice Springs", null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("NT", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("Alice Springs", locationRef.NamedLocation.Name); // Auckland Inner locationRef = locationMapper.Map("New Zealand", "Auckland", "Auckland Inner", null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("New Zealand", locationRef.Country.Name); // Sydney Inner locationRef = locationMapper.Map("Australia", "Sydney", "Sydney Inner", null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("NSW", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("Sydney", locationRef.NamedLocation.Name); }
public void TestMapByCountry() { var locationMapper = new LocationMapper(_locationQuery); var locationRef = locationMapper.Map("Australia", null, null, null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.IsTrue(locationRef.IsCountry); locationRef = locationMapper.Map("United Kingdom", null, null, null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.IsTrue(locationRef.IsCountry); locationRef = locationMapper.Map("United States", null, null, null); Assert.IsTrue(locationRef.IsFullyResolved); Assert.IsTrue(locationRef.IsCountry); try { locationMapper.Map("Kazakhstan", null, null, null); Assert.Fail(); } catch (ServiceEndUserException ex) { Assert.AreEqual("Invalid country.", ex.Message); } }
public ILocationModel Create(ILocationModel model) { // Validate model BusinessWorkflowBase.ValidateIDIsNull(model.Id); //BusinessWorkflowBase.ValidateRequiredString(model.Name, nameof(model.Name)); // Search for an Existing Record (Don't allow Duplicates var results = Search(LocationMapper.MapToSearchModel(model)); if (results.Any()) { return(results.First()); } // Return the first that matches // Map model to a new entity var newEntity = LocationMapper.MapToEntity(model); newEntity.CreatedDate = BusinessWorkflowBase.GenDateTime; newEntity.UpdatedDate = null; newEntity.Active = true; // Add it LocationsRepository.Add(newEntity); // Try to Save Changes LocationsRepository.SaveChanges(); // Return the new value return(Get(newEntity.Id)); }
public HttpResponseMessage GetLocationByGuidAndId(Guid guid, int id) { var result = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account"); var clientEntity = _lookupService.GetClientByGuid(guid); if (clientEntity == null) { _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid)); } else { var locationEntity = _lookupService.GetLocationByIdAndClientId(new List <string> { clientEntity.Id.ToString() }, id); var location = new LocationDTO(); if (locationEntity != null) { location = LocationMapper.ToDataTransferObject(locationEntity); location.Areas = _lookupService.GetAreasByLocationId(location.Id).Select(x => AreaMapper.ToDataTransferObject(x)).ToList(); } result = Request.CreateResponse(HttpStatusCode.OK, location); } result.Headers.Add("Access-Control-Allow-Origin", "*"); return(result); }
public void CreateEntityTest() { LocationMapper _locationMapper = MapperFactory.createLocationMapper(); LocationDTO LocationDTO = DTOFactory.CreateLocationDTO(1, "Venezolania", "cagua"); var result = _locationMapper.CreateEntity(LocationDTO); Assert.IsInstanceOf <Location>(result); }
public void CreateDTOTest() { LocationMapper _locationMapper = MapperFactory.createLocationMapper(); Location entity = EntityFactory.CreateLocation(1, "Venezolania", "cagua"); var result = _locationMapper.CreateDTO(entity); Assert.IsInstanceOf <LocationDTO>(result); }
public override async Task <List <DAL.App.DTO.Location> > AllAsync() { return(await RepositoryDbSet .Include(m => m.Locations) .ThenInclude(t => t.Translations) .Include(c => c.Shows) .Include(i => i.Competitions) .Select(e => LocationMapper.MapFromDomain(e)).ToListAsync()); }
public Task <CountryDto> GetCountry(int id) { var country = _readOnlyService.Repository <Country>().Get(i => i.AutoId == id).FirstOrDefault(); var countryDto = LocationMapper.EntityToDto(country); var provinces = _readOnlyService.Repository <Province>().Get(i => i.CountryId == id).ToList(); countryDto.Provinces = LocationMapper.EntityToDtos(provinces).ToList(); return(Task.FromResult(countryDto)); }
/// <summary> /// Obtiene una lista de lista de todas las compañias registradas en la base de datos /// </summary> /// <param name="IncludeDisabled">Parametro donde se indica si se obtendran los registros deshabilitados</param> /// <param name="CompanyId">Parametro donde se indica el número de Id de la compañia a obtener</param> /// <returns>Objeto de tipo ResponseDTO con el listado de las compañias obtenidas</returns> private ResponseDTO <List <LocationDTO> > Get(bool IncludeDisabled, int?ProyectId = null, int?LocationId = null) { database = DatabaseFactory.CreateDataBase(databaseType, "[CLIENT].[USP_GET_LOCATIONS]", IncludeDisabled, ProyectId, LocationId); ResponseDTO <List <LocationDTO> > response = LocationMapper.MapperLocationDTO(database.DataReader); database.Connection.Close(); return(response); }
public DataTable getLocaitonPickList() { DataTable dt = new DataTable(); LocationMapper loc = new LocationMapper(); dt = loc.getLocPickList(); return(dt); }
public ActionResult <IEnumerable <LocationDTO> > GetCountries() { LocationMapper locationMapper = MapperFactory.createLocationMapper(); GetCountriesCommand commandGetCountries = CommandFactory.GetCountriesCommand(); commandGetCountries.Execute(); var result = commandGetCountries.GetResult(); _logger?.LogInformation($"Obtenido los paises exitosamente"); return(locationMapper.CreateDTOList(result)); }
public void CreateDTOListTest() { LocationMapper _locationMapper = MapperFactory.createLocationMapper(); Location entity = EntityFactory.CreateLocation(1, "Venezolania", "cagua"); List <Location> entities = new List <Location>(); entities.Add(entity); entities.Add(entity); var result = _locationMapper.CreateDTOList(entities); Assert.IsInstanceOf <List <LocationDTO> >(result); }
public void CreateEntityListTest() { LocationMapper _locationMapper = MapperFactory.createLocationMapper(); LocationDTO LocationDTO = DTOFactory.CreateLocationDTO(1, "Venezolania", "cagua"); List <LocationDTO> dtos = new List <LocationDTO>(); dtos.Add(LocationDTO); dtos.Add(LocationDTO); var result = _locationMapper.CreateEntityList(dtos); Assert.IsInstanceOf <List <Location> >(result); }
public void Verify_AreEqual_WithDifferentObjects_ReturnsFalse() { // Arrange var mapper = new LocationMapper(); var model = LocationsMockingSetup.DoMockingSetupForLocationModel(1); var entity = LocationsMockingSetup.DoMockingSetupForLocation(2); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.False(result); }
public void Verify_MapToModelLite_AssignsLiteOnlyLocationProperties() { // Arrange var mapper = new LocationMapper(); var entity = LocationsMockingSetup.DoMockingSetupForLocation(); // Act var model = mapper.MapToModelLite(entity.Object); // Assert Assert.Equal(entity.Object.StartYear, model.StartYear); // Related Objects Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); }
public async Task <City> GetCityByCityName(string cityName) { UriBuilder builder = new UriBuilder(_runtimeContext.LocationBaseEndpoint) { Path = "REST/v1/Locations", Query = $"locality={Uri.EscapeDataString(cityName)}&key={_runtimeContext.BingMapKey}" }; LocationDTO locationResponse = await _requestService.GetAsync <LocationDTO>(builder.Uri); LocationMapper locationMapper = new LocationMapper(); City city = locationMapper.ToDomainEntities(locationResponse); return(city); }
public void TestMapByPostcode() { var locationMapper = new LocationMapper(_locationQuery); LocationReference locationRef = locationMapper.Map("Australia", null, null, "3182"); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("VIC", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("3182", locationRef.NamedLocation.Name); locationRef = locationMapper.Map("Australia", "Melbourne", null, "3182"); Assert.IsTrue(locationRef.IsFullyResolved); Assert.AreEqual("VIC", locationRef.CountrySubdivision.ShortName); Assert.AreEqual("3182", locationRef.NamedLocation.Name); }
public override INSFileProviderEnumerator GetEnumerator(string containerItemIdentifier, out NSError error) { error = null; if (containerItemIdentifier == NSFileProviderItemIdentifier.WorkingSetContainer) { return(new EmptyEnumerator()); } if (LocationMapper.IsFolderIdentifier(containerItemIdentifier)) { return(new FolderEnumerator(containerItemIdentifier, StorageManager)); } return(new FileEnumerator(containerItemIdentifier, StorageManager)); }
public void WhenMappingLocation_MappingIsValid() { var location = new Location { Timestamp = 1597260818, Longitude = 1.7712m, Latitude = -10.7872m }; var locationMapped = LocationMapper.DomainToSDK(location); Assert.True( locationMapped.Timestamp == location.Timestamp && locationMapped.Longitude == location.Longitude && locationMapped.Latitude == location.Latitude ); }
public Task <PagedResult <CountryDto> > GetPaged(string name, string orderBy = "", bool orderAsc = true, int page = 1, int pageSize = 20) { var data = _readOnlyService.Repository <Country>().GetPaged(i => string.IsNullOrEmpty(name) || i.Name.ToLower().Contains(name.ToLower()), page: page, pageSize: pageSize); var result = new PagedResult <CountryDto> { CurrentPage = data.CurrentPage, PageCount = data.PageCount, PageSize = data.PageSize, RowCount = data.RowCount, Results = LocationMapper.EntityToDtos(data.Results) }; return(Task.FromResult(result)); }
public ActionResult <IEnumerable <LocationDTO> > GetCitiesByCountry([FromRoute] int countryId) { try { GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(countryId); commandId.Execute(); LocationMapper locationMapper = MapperFactory.createLocationMapper(); GetCitiesByCountryCommand commandIByCountry = CommandFactory.GetCitiesByCountryCommand(countryId); commandIByCountry.Execute(); var result = commandIByCountry.GetResult(); _logger?.LogInformation($"Obtenida las ciudades por pais id {countryId} exitosamente"); return(locationMapper.CreateDTOList(result)); } catch (LocationNotFoundException ex) { _logger?.LogWarning($"Location con id {countryId} no encontrada"); return(NotFound($"Location with id {countryId} not found")); } }
public override async Task <DTO.Location> FindAsync(params object[] id) { var culture = Thread.CurrentThread.CurrentUICulture.Name.Substring(0, 2).ToLower(); var location = await RepositoryDbSet.FindAsync(id); if (location != null) { await RepositoryDbContext.Entry(location) .Reference(c => c.Locations) .LoadAsync(); await RepositoryDbContext.Entry(location.Locations) .Collection(b => b.Translations) .Query() .Where(t => t.Culture == culture) .LoadAsync(); } return(LocationMapper.MapFromDomain(location)); }
public void Verify_MapToModel_AssignsLocationProperties() { // Arrange var mapper = new LocationMapper(); var entity = LocationsMockingSetup.DoMockingSetupForLocation(); // Act var model = mapper.MapToModel(entity.Object); // Assert Assert.Equal(entity.Object.StartYear, model.StartYear); // Related Objects Assert.Equal(entity.Object.FirstIssueAppearanceId, model.FirstIssueAppearanceId); Assert.Equal(entity.Object.PrimaryImageFileId, model.PrimaryImageFileId); // Associated Objects Assert.Equal(entity.Object.LocationAliases?.Count, model.LocationAliases?.Count); Assert.Equal(entity.Object.LocationAppearedInIssues?.Count, model.LocationAppearedInIssues?.Count); Assert.Equal(entity.Object.LocationIssues?.Count, model.LocationIssues?.Count); Assert.Equal(entity.Object.LocationMovies?.Count, model.LocationMovies?.Count); Assert.Equal(entity.Object.LocationStoryArcs?.Count, model.LocationStoryArcs?.Count); Assert.Equal(entity.Object.LocationVolumes?.Count, model.LocationVolumes?.Count); }
public HttpResponseMessage GetClientByGuid(Guid guid) { var result = Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Client code does not have an active account"); var clientEntity = _lookupService.GetClientByGuid(guid); if (clientEntity == null) { _log.Error(string.Format("Failed to lookup Client by GUID: {0}", guid)); } else { var client = ClientMapper.ToDataTransferObject(clientEntity); var locations = _lookupService.GetLocationsByClientId(clientEntity.Id); if (locations != null && locations.Count() > 0) { client.Locations = locations.Select(x => LocationMapper.ToDataTransferObject(x)).ToList(); } result = Request.CreateResponse(HttpStatusCode.OK, client); } result.Headers.Add("Access-Control-Allow-Origin", "*"); return(result); }
public void Verify_MapToSearchModel_AssignsLocationSearchProperties() { // Arrange var mapper = new LocationMapper(); var model = LocationsMockingSetup.DoMockingSetupForLocationModel(); // Act var searchModel = mapper.MapToSearchModel(model.Object); // Assert Assert.Equal(model.Object.FirstIssueAppearanceId, searchModel.FirstIssueAppearanceId); Assert.Equal(model.Object.FirstIssueAppearance?.CustomKey, searchModel.FirstIssueAppearanceCustomKey); Assert.Equal(model.Object.FirstIssueAppearance?.ApiDetailUrl, searchModel.FirstIssueAppearanceApiDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.SiteDetailUrl, searchModel.FirstIssueAppearanceSiteDetailUrl); Assert.Equal(model.Object.FirstIssueAppearance?.Name, searchModel.FirstIssueAppearanceName); Assert.Equal(model.Object.FirstIssueAppearance?.ShortDescription, searchModel.FirstIssueAppearanceShortDescription); Assert.Equal(model.Object.FirstIssueAppearance?.Description, searchModel.FirstIssueAppearanceDescription); Assert.Equal(model.Object.PrimaryImageFileId, searchModel.PrimaryImageFileId); Assert.Equal(model.Object.PrimaryImageFile?.CustomKey, searchModel.PrimaryImageFileCustomKey); Assert.Equal(model.Object.PrimaryImageFile?.ApiDetailUrl, searchModel.PrimaryImageFileApiDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.SiteDetailUrl, searchModel.PrimaryImageFileSiteDetailUrl); Assert.Equal(model.Object.PrimaryImageFile?.Name, searchModel.PrimaryImageFileName); Assert.Equal(model.Object.PrimaryImageFile?.ShortDescription, searchModel.PrimaryImageFileShortDescription); Assert.Equal(model.Object.PrimaryImageFile?.Description, searchModel.PrimaryImageFileDescription); }
public void Verify_AreEqual_WithEqualObjects_ReturnsTrue() { // Arrange var mapper = new LocationMapper(); var model = LocationsMockingSetup.DoMockingSetupForLocationModel(1); var entity = LocationsMockingSetup.DoMockingSetupForLocation(1); // Act var result = mapper.AreEqual(model.Object, entity.Object); // Assert Assert.True(result); }