public void Map_CacheTest_ReturnMappedObject() { IMapper mapper = new DtoMapper(); mapper.Map <Source, Destination>(SourceToTest); Destination actualDestination = mapper.Map <Source, Destination>(SourceToTest); Assert.Equal(ExpectedDestination, actualDestination); }
public void Map_MappingUsingCache() { IMapper mapper = new DtoMapper(); mapper.Map <Source, Destination>(Source); //create cache for "Source -> Destination" pair Destination actual = mapper.Map <Source, Destination>(Source); Assert.Equal(ExpectedWithoutConfiguration, actual); }
public IEnumerable <DoctorDto> GetAllDoctors(string filterString) { var doctorEntities = doctorRepository.GetDoctors(); if (!string.IsNullOrEmpty(filterString)) { doctorEntities = doctorEntities.Where(x => x.FirstName.Contains(filterString) || x.LastName.Contains(filterString)); } return(mapper.Map(doctorEntities)); }
public void SetUp() { DtoMapper mapper = new DtoMapper(new LinkProvider()); m_order = new Order(); m_order.Cancel("You are too slow."); m_dto = mapper.Map<Order, OrderDto>(m_order); }
// Converts order DTOs to VMs static IEnumerable <OrderVm> GetExpectedOrders(IEnumerable <OrderDto> orders) { var dtoMapper = new DtoMapper(); var vmMapper = new VmMapper(); return(orders.Select(order => vmMapper.Map(dtoMapper.Map(order, null)))); }
public void SetUp() { var mapper = new DtoMapper(new LinkProvider()); m_order = new Order(); m_order.Pay("123", "jose"); m_dto = mapper.Map<Order, OrderDto>(m_order); }
public void SetUp() { var mapper = new DtoMapper(new LinkProvider()); m_order = new Order(); m_dto = mapper.Map <Order, OrderDto>(m_order); }
public void Map_SimpleMapping() { IMapper mapper = new DtoMapper(); Destination actual = mapper.Map <Source, Destination>(Source); Assert.Equal(ExpectedWithoutConfiguration, actual); }
public async Task AddCoordinateToList(int coordinateListId, Coordinate coordinate) { coordinate.CoordinateListId = coordinateListId; CoordinateDto coordinateDto = DtoMapper.Map(coordinate); Coordinates.Add(coordinateDto); await SaveChangesAsync().ConfigureAwait(false); }
public void SetUp() { DtoMapper mapper = new DtoMapper(new LinkProvider()); m_order = new Order(); m_order.Cancel("You are too slow."); m_dto = mapper.Map <Order, OrderDto>(m_order); }
public void SetUp() { var mapper = new DtoMapper(new LinkProvider()); m_order = new Order(); m_order.Pay("123", "jose"); m_order.Finish(); m_dto = mapper.Map <Order, OrderDto>(m_order); }
public void Save(TodoListAggregate listEntity) { var listDto = new TodoListDto(); var resultItemList = new List <TodoListItemDto>(); DtoMapper.Map(listEntity, listDto); using (var c = _sqlConnectionProvider.GetConnection()) { using (var tran = c.BeginTransaction()) { try { if (listEntity.Key == 0) { const string insertTodoListSql = "INSERT INTO [TodoList]([ListId],[Name]) OUTPUT INSERTED.[Id] VALUES(@listId, @name)"; listDto.Id = c.QuerySingle <int>(insertTodoListSql, new { listId = listDto.ListId, name = listDto.Name }, tran); } else { //const string insertTodoListSql = "UPDATE [TodoList]([Name]) VALUES(@Name)"; c.Update(listDto, tran); } //remove deleted items const string deleteRemovedSql = "DELETE FROM [TodoItem] WHERE [TodoList_Id] = @listId AND Id NOT IN @ids"; c.Execute(deleteRemovedSql, new { listId = listDto.Id, ids = listEntity.Items.Select(e => e.Key) }, tran); foreach (var itemEntity in listEntity.Items) { var dto = new TodoListItemDto(); DtoMapper.Map(listDto.Id, itemEntity, dto); if (itemEntity.Key == 0) { dto.Id = (int)c.Insert(dto, tran); } else if (itemEntity.Key > 0) { c.Update(dto, tran); } resultItemList.Add(dto); } tran.Commit(); } catch { tran.Rollback(); throw; } } } }
public void Map_NullParameter_ArgumentNullExceptionThrown() { // arrange IMapper mapper = new DtoMapper(); // act Func <object> act = () => mapper.Map <Source, Destination>(null); // assert Assert.Throws <ArgumentNullException>(act); }
public void Map_MappingUsingConfiguration() { MapperConfiguration mapperConfiguration = new MapperConfiguration(); mapperConfiguration.Register <Source, Destination, string>(source => source.Name, destination => destination.FirstName) .Register <Source, Destination, long>(source => source.OneNumberCanConvert, destination => destination.AnotherNumberCanConvert); IMapper mapper = new DtoMapper(mapperConfiguration); Destination actual = mapper.Map <Source, Destination>(Source); Assert.Equal(ExpectedWithConfiguration, actual); }
public void Map_CacheMiss_GetCacheForDidNotCalled_CreateMappingFunctionCalled() { var mockCache = new Mock <IMappingFunctionsCache>(); mockCache.Setup(cache => cache.HasCacheFor(It.IsAny <MappingTypesPair>())).Returns(false); Mock <IMappingFunctionsFactory> mockFactory = CreateFakeMappingFunctionsFactory(); IMapper mapper = new DtoMapper(mockCache.Object, mockFactory.Object); mapper.Map <object, object>(new object()); mockCache.Verify(cache => cache.GetCacheFor <object, object>(It.IsAny <MappingTypesPair>()), Times.Never); mockFactory.Verify(factory => factory.CreateMappingFunction <object, object>(It.IsAny <List <MappingPropertiesPair> >()), Times.Once); }
protected void Application_Start() { log4net.Config.XmlConfigurator.Configure(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DtoMapper.Map(); InitializeIocContainer.Initialize(); var permissionManager = IocHelper.Resolve <IPermissionManager>(); permissionManager.Initialize(); }
private void OnAddConsultationRequest() { var success = _backendRequestHandler.Handle(DtoMapper.Map(_viewModel)); if (success) { _onConsultationAdded.CallIfNotNull(); _window.Close(); } else { MessageDialog.CreateNotification("Konsultation konnte nicht angelegt werden", "Bitte geben Sie ggf. einen anderen Verfügbarkeitszeitraum an", "x.smartplan").Show(_window); } }
public async Task <CoordinateList> CreateCoordinateList(List <Coordinate> coordinates) { CoordinateListDto coordinateListDto = new CoordinateListDto(); CoordinateLists.Add(coordinateListDto); await SaveChangesAsync().ConfigureAwait(false); coordinates.ForEach(x => x.CoordinateListId = coordinateListDto.Id); List <CoordinateDto> coordinateDtos = coordinates.Select(DtoMapper.Map).ToList(); Coordinates.AddRange(coordinateDtos); await SaveChangesAsync().ConfigureAwait(false); CoordinateList createdCoordinateList = DtoMapper.Map(coordinateListDto, coordinateDtos); return(createdCoordinateList); }
public async Task <CoordinateList> GetCoordinateList(int coordinateListId) { CoordinateListDto coordinateListDto = await CoordinateLists .AsQueryable() .FirstOrDefaultAsync(x => x.Id == coordinateListId) .ConfigureAwait(false); List <CoordinateDto> coordinateDtos = await Coordinates .AsQueryable() .Where(x => x.CoordinateListId == coordinateListId) .ToListAsync() .ConfigureAwait(false); CoordinateList coordinateList = DtoMapper.Map(coordinateListDto, coordinateDtos); return(coordinateList); }
public void Map_NoCache_CheckCacheNotCalled() { Mock <IFunctionsCache> cacheMock = new Mock <IFunctionsCache>(); cacheMock.Setup(cache => cache.Contains(It.IsAny <MappingTypeAssociation>())).Returns(false); Mock <IFunctionBuilder> builderMock = new Mock <IFunctionBuilder>(); builderMock.Setup(builder => builder.Build <object, object>( It.IsAny <List <MappingProperty> >())).Returns(o => o); IMapper mapper = new DtoMapper(builderMock.Object, cacheMock.Object); mapper.Map <object, object>(new object()); cacheMock.Verify(cache => cache.Get <object, object>(It.IsAny <MappingTypeAssociation>()), Times.Never); builderMock.Verify(builder => builder.Build <object, object>(It.IsAny <List <MappingProperty> >()), Times.Once); }
public async Task <IReview> Update(int id, bool needUpdateText, string text, float?rate, bool?isVisible) { using (var provider = ContextProviderFactory.Create()) { var reviews = provider.GetTable <Review>() .Where(t => t.Id == id); if (!reviews.Any()) { throw new InvalidOperationException($"No review with id = {id}"); } if (reviews.Count() > 1) { throw new InvalidOperationException($"По идентификатор найдено более 1 соответствия"); } var review = reviews.First(); var res = await provider.GetTable <Review>() .Where(t => t.Id == id) .UpdateAsync(t => new Review() { IsVisible = isVisible ?? t.IsVisible, Text = needUpdateText ? text : t.Text, Rate = rate ?? t.Rate, UpdateDate = DateTime.Now }); return(DtoMapper.Map <IReview>(review)); } }
public async Task <PagingResult <IAttractionWithLinks> > CustomFilter(int page, int pageSize, string name, int?cityId, int?districtId, int[] subjectIds, bool subjectsAtLeastOne, int[] placeTypeIds, bool placeTypesAtLeastOne, OrderModel orderModel) { using (var cp = _contextProviderFactory.Create()) { var attrs = cp.GetTable <Attraction>(); if (cityId != null) { attrs = attrs.Where(w => w.CityId == cityId); } if (!string.IsNullOrEmpty(name)) { attrs = attrs.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase)); } if (districtId != null) { attrs = attrs.Where(w => w.DistrictId == districtId); } if (subjectIds?.Any() ?? false) { var attrSubjIds = await _attractionSubjectsService.Get(1, int.MaxValue, new SearchModel() { Filter = ParameterInArray(nameof(AttractionSubject.SubjectId), subjectIds.Cast <object>().ToArray()) }); var groups = attrSubjIds.Items.GroupBy(k => k.AttractionId).Where(w => subjectsAtLeastOne ? subjectIds.Any(a => w.Select(s => s.SubjectId).Contains(a)) : subjectIds.All(a => w.Select(s => s.SubjectId).Contains(a))); attrs = attrs.Where(w => groups.Select(t => t.Key).Contains(w.Id)); } if (placeTypeIds?.Any() ?? false) { var attrPlaceTypes = await _attractionPlaceTypeService.Get(1, int.MaxValue, new SearchModel() { Filter = ParameterInArray(nameof(AttractionPlaceType.PlaceTypeId), placeTypeIds.Cast <object>().ToArray()) }); var groups = attrPlaceTypes.Items.GroupBy(k => k.AttractionId).Where(w => placeTypesAtLeastOne ? placeTypeIds.Any(a => w.Select(s => s.PlaceTypeId).Contains(a)) : placeTypeIds.All(a => w.Select(s => s.PlaceTypeId).Contains(a))); attrs = attrs.Where(w => groups.Select(t => t.Key).Contains(w.Id)); } IReadOnlyCollection <Attraction> attractions = await attrs.GetFilteredTable(new SearchModel() { Order = orderModel }, cp) .Skip((page - 1) * pageSize) .Take(pageSize) .ToArrayAsync(); var paging = new PagingResult <IAttraction>() { Total = attrs.Count(), Items = !attractions.Any() ? new IAttraction[0] : DtoMapper.Map <IAttraction[]>(attractions), }; var res = await GetPagingWithLinksInternal(paging); return(res); } }
public override void Initialize(IAbpInitializationContext initializationContext) { base.Initialize(initializationContext); DtoMapper.Map(); }
public async Task <PagingResult <IHotelWithLinks> > CustomFilter(int page, int pageSize, string name, int?cityId, int?districtId, int?housingTypeId, int[] equipmentTypes, bool equipmentTypesAtLeastOne, int[] serviceTypes, bool serviceTypesAtLeastOne, OrderModel orderModel) { using (var cp = _contextProviderFactory.Create()) { var hotels = cp.GetTable <Hotel>(); if (cityId != null) { hotels = hotels.Where(w => w.CityId == cityId); } if (housingTypeId != null) { hotels = hotels.Where(w => w.HousingTypeId == housingTypeId); } if (!string.IsNullOrEmpty(name)) { hotels = hotels.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase)); } if (districtId != null) { hotels = hotels.Where(w => w.DistrictId == districtId); } if (equipmentTypes?.Any() ?? false) { var attrSubjIds = cp.GetTable <RouteSubjectName>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => equipmentTypesAtLeastOne ? equipmentTypes.Any(a => w.Select(s => s.SubjectNameId).Contains(a)) : equipmentTypes.All(a => w.Select(s => s.SubjectNameId).Contains(a))) .Select(s => s.Key); hotels = hotels.Where(w => attrSubjIds.Contains(w.Id)); } if (serviceTypes?.Any() ?? false) { var attrSubjIds = cp.GetTable <RouteSubjectName>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => serviceTypesAtLeastOne ? serviceTypes.Any(a => w.Select(s => s.SubjectNameId).Contains(a)) : serviceTypes.All(a => w.Select(s => s.SubjectNameId).Contains(a))) .Select(s => s.Key); hotels = hotels.Where(w => attrSubjIds.Contains(w.Id)); } IReadOnlyCollection <Hotel> hotelsFinal = await hotels.GetFilteredTable(new SearchModel() { Order = orderModel }, cp) .Skip((page - 1) * pageSize) .Take(pageSize) .ToArrayAsync(); var paging = new PagingResult <IHotel>() { Total = hotels.Count(), Items = !hotelsFinal.Any() ? new IHotel[0] : DtoMapper.Map <IHotel[]>(hotelsFinal), }; var res = await GetPagingWithLinksInternal(paging); return(res); } }
public async Task <PagingResult <IRestaurantWithLinks> > CustomFilter(int page, int pageSize, string name, int?cityId, int?districtId, int?cateringTypeId, int[] cuisineTypeIds, bool atLeastOneCuisineType, int[] denyTypeIds, bool atLeastOneDenyType, OrderModel orderModel) { using (var cp = _contextProviderFactory.Create()) { var rests = cp.GetTable <Restaurant>(); if (cityId != null) { rests = rests.Where(w => w.CityId == cityId); } if (cateringTypeId != null) { rests = rests.Where(w => w.CateringTypeId == cateringTypeId); } if (!string.IsNullOrEmpty(name)) { rests = rests.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.OrdinalIgnoreCase)); } if (districtId != null) { rests = rests.Where(w => w.DistrictId == districtId); } if (cuisineTypeIds?.Any() ?? false) { var attrCuisines = cp.GetTable <RestaurantCuisineType>() .ToArray() .GroupBy(atts => atts.RestaurantId) .Where(w => atLeastOneCuisineType ? cuisineTypeIds.Any(a => w.Select(s => s.CuisineTypeId).Contains(a)) : cuisineTypeIds.All(a => w.Select(s => s.CuisineTypeId).Contains(a))) .Select(s => s.Key); rests = rests.Where(w => attrCuisines.Contains(w.Id)); } if (denyTypeIds?.Any() ?? false) { var attrDeny = cp.GetTable <RestaurantDenyType>() .ToArray() .GroupBy(atts => atts.RestaurantId) .Where(w => atLeastOneDenyType ? denyTypeIds.Any(a => w.Select(s => s.DenyTypeId).Contains(a)) : denyTypeIds.All(a => w.Select(s => s.DenyTypeId).Contains(a))) .Select(s => s.Key); rests = rests.Where(w => attrDeny.Contains(w.Id)); } IReadOnlyCollection <Restaurant> restsFinal = await rests.GetFilteredTable(new SearchModel() { Order = orderModel }, cp) .Skip((page - 1) * pageSize) .Take(pageSize) .ToArrayAsync(); var paging = new PagingResult <IRestaurant>() { Total = rests.Count(), Items = !restsFinal.Any() ? new IRestaurant[0] : DtoMapper.Map <IRestaurant[]>(restsFinal), }; var res = await GetPagingWithLinksInternal(paging); return(res); } }
public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); DtoMapper.Map(); }
public void Map_NullPassed_ExceptionThrown() { IMapper mapper = new DtoMapper(); Assert.Throws <ArgumentNullException>(() => mapper.Map <object, object>(null)); }
public async Task <PagingResult <IRouteWithLinks> > CustomFilter(int page, int pageSize, string name, bool?animals, int[] peopleTypeIds, int[] ageTypeIds, int[] subjectNameIds, bool subjectNamesAtLeastOne, int[] subjectTypeIds, bool subjectTypesAtLeastOne, int?cityId, int?districtId, IFromToFilter <float> durationFilter, IFromToFilter <float> lengthFilter, OrderModel orderModel) { using (var cp = _contextProviderFactory.Create()) { var routes = cp.GetTable <Route>(); if (cityId != null) { routes = routes.Where(w => w.CityId == cityId); } if (districtId != null) { routes = routes.Where(w => w.DistrictId == districtId); } if (animals != null) { routes = routes.Where(w => w.Animals == animals); } if (!string.IsNullOrEmpty(name)) { routes = routes.Where(w => w.Name.ToLower().Contains(name.ToLower(), StringComparison.InvariantCultureIgnoreCase)); } if (peopleTypeIds?.Any() ?? false) { var attrSubjIds = cp.GetTable <RoutePeopleType>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => peopleTypeIds.All(a => w.Select(s => s.PeopleTypeId).Contains(a))).Select(s => s.Key); routes = routes.Where(w => attrSubjIds.Contains(w.Id)); } if (ageTypeIds?.Any() ?? false) { var attrSubjIds = cp.GetTable <RouteAgeType>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => ageTypeIds.All(a => w.Select(s => s.AgeTypeId).Contains(a))).Select(s => s.Key); routes = routes.Where(w => attrSubjIds.Contains(w.Id)); } if (subjectNameIds?.Any() ?? false) { var attrSubjIds = cp.GetTable <RouteSubjectName>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => subjectNamesAtLeastOne ? subjectNameIds.Any(a => w.Select(s => s.SubjectNameId).Contains(a)) : subjectNameIds.All(a => w.Select(s => s.SubjectNameId).Contains(a))) .Select(s => s.Key); routes = routes.Where(w => attrSubjIds.Contains(w.Id)); } if (subjectTypeIds?.Any() ?? false) { var attrSubjIds = cp.GetTable <RouteSubjectType>() .ToArray() .GroupBy(atts => atts.RouteId) .Where(w => subjectTypesAtLeastOne ? subjectTypeIds.Any(a => w.Select(s => s.SubjectTypeId).Contains(a)) : subjectTypeIds.All(a => w.Select(s => s.SubjectTypeId).Contains(a))) .Select(s => s.Key); routes = routes.Where(w => attrSubjIds.Contains(w.Id)); } if (durationFilter != null) { routes = routes.Where(w => w.Time >= durationFilter.From && w.Time <= durationFilter.To); } if (lengthFilter != null) { routes = routes.Where(w => w.Length >= lengthFilter.From && w.Length <= lengthFilter.To); } IReadOnlyCollection <Route> routesFinal = await routes.GetFilteredTable(new SearchModel() { Order = orderModel }, cp) .Skip((page - 1) * pageSize) .Take(pageSize) .ToArrayAsync(); var paging = new PagingResult <IRoute>() { Total = routes.Count(), Items = !routesFinal.Any() ? new IRoute[0] : DtoMapper.Map <IRoute[]>(routesFinal), }; var res = await GetPagingWithLinksInternal(paging); return(res); } }
public async Task <PagingResult <IEventWithLinks> > CustomFilter(int page, int pageSize, int?cityId, int?districtId, IFromToFilter <DateTime> startDateFilter, IFromToFilter <DateTime> endDateFilter, IFromToFilter <DateTime> dateFilter, SearchModel search) { using (var cp = _contextProviderFactory.Create()) { var events = cp.GetTable <Event>(); if (cityId != null) { events = events.Where(w => w.CityId == cityId); } if (districtId != null) { events = events.Where(w => w.DistrictId == districtId); } if (startDateFilter != null) { events = events.Where(w => w.StartDate >= startDateFilter.From && w.StartDate <= startDateFilter.To); } if (endDateFilter != null) { events = events.Where(w => w.EndDate >= endDateFilter.From && w.EndDate <= endDateFilter.To); } if (dateFilter != null) { events = events.Where(w => (w.StartDate >= dateFilter.From && w.StartDate <= dateFilter.To) || (w.EndDate >= dateFilter.From && w.EndDate <= dateFilter.To) || (w.StartDate <= dateFilter.From && w.EndDate >= dateFilter.To)); } IReadOnlyCollection <Event> eventsFinal = await events.GetFilteredTable(search, cp) .Skip((page - 1) * pageSize) .Take(pageSize) .ToArrayAsync(); var paging = new PagingResult <IEvent>() { Total = events.Count(), Items = !eventsFinal.Any() ? new IEvent[0] : DtoMapper.Map <IEvent[]>(eventsFinal), }; var res = await GetPagingWithLinksInternal(paging); return(res); } }