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() { 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 DoctorManager(IDoctorRepository doctorRepository, IPrescriptionRepository prescriptionRepository, IMedicineRepository medicineRepository, DtoMapper dtoMapper) { mDoctorRepository = doctorRepository; mPrescriptionRepository = prescriptionRepository; mMedicineRepository = medicineRepository; mDtoMapper = dtoMapper; }
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); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DtoMapper.Configure(); }
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 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 Update_IdDoesNotMatchItemId_ReturnBadRequest() { var poi = CityPoiItemBuilder.GeneratePointOfInterest(); var poiDto = DtoMapper.PoiToPoiDto(poi); var result = PoiController.UpdatePointOfInterest(NotMatchingId, poiDto); result.Should().BeOfType <BadRequestResult>(); }
public List <CalendarEntryDTO> GetCalendarEntries(int year, int month) { var startDate = new DateTime(year, month, 1); var endDate = startDate.AddMonths(1); return(_context .CalendarEntries .Where(x => x.StartDate >= startDate && x.StartDate < endDate || x.EndDate >= startDate && x.StartDate < startDate) .Select(x => DtoMapper.MapCalendarEntryToDTO(x)) .ToList()); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DtoMapper.Initialize(); DependecyRunningOn.Initialise(); FluentValidationModelValidatorProvider.Configure(); }
public async Task <CalendarEntryDTO> GetCalendarEntryById(int entryId) { var entry = await _context.CalendarEntries.FindAsync(entryId); if (entry == null) { throw new ArgumentException("Entry was deleted by someone else."); } return(DtoMapper.MapCalendarEntryToDTO(entry)); }
public static void AssemblyInitFunction(TestContext context) { EnvironmentFactoryFactory.Initialize(context.Properties); AssemblyResolver.Initialize(); Management.Services.DtoMapper.Setup(); DtoMapper.Setup(); SettingInitializer.Init(); }
public TripDto Checkin() { var trip = new Trip { TripIdentifier = Guid.NewGuid().ToString() }; _tripRepository.Add(trip); return(DtoMapper.ConvertTripToDto(trip)); }
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 MapResultDtoToCreatedOrderDto_ShouldReturnCreatedOrderDtoType() { var result = new ResultDto { SingleOrder = new ReadOrderDto { OrderNumber = 5, UserId = 456, PayableAmount = 99.12, PaymentGateWay = "Seb", Description = "This is order number 5" }, Message = "OK" }; var actual = DtoMapper.MapResultDtoToCreatedOrderDto(result); Assert.IsType <CreatedOrderDto>(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); }
public void CanConvertDtoToLocation() { var locationDto = new LocationDto { Latitude = 55.6739062, Longitude = 12.5556993 }; var location = DtoMapper.ConvertDtoToLocation(locationDto); Assert.Equal(locationDto.Latitude, location.Latitude); Assert.Equal(locationDto.Longitude, location.Longitude); }
void Application_Start(object sender, EventArgs e) { // Code that runs on application startup //AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); LogHelper.LogConfig(Server.MapPath(@"~\App_Data\log4net.config")); DtoMapper.AutoMapper(); QiniuUpload.Config(); }
public async Task <IActionResult> LoginEmployee([FromBody] LoginDTO loginDto) { var result = await _signInManager.PasswordSignInAsync(loginDto.Email, loginDto.Password, true, false); if (result.Succeeded) { var normalizedEmail = loginDto.Email.ToUpper(); var user = _context.Users.FirstOrDefault(x => x.NormalizedEmail == normalizedEmail); return(Ok(DtoMapper.MapEmployeeToDTO(user))); } return(BadRequest(new UserLoginFailedException())); }
public void CanConvertLocationToDto() { var location = new Location { Latitude = 55.6739062, Longitude = 12.5556993 }; var locationDto = DtoMapper.ConvertLocationToDto(location); Assert.Equal(location.Latitude, locationDto.Latitude); Assert.Equal(location.Longitude, locationDto.Longitude); }
public static void AssemblyInitFunction(TestContext context) { EnvironmentFactoryFactory.Initialize(context.Properties); AssemblyResolver.Initialize(); DtoMapper.Setup(); var environmentFactory = EnvironmentFactoryFactory.Create(); if (environmentFactory.TelemetryEnvironment.DataSinkCurrent != null) { SettingInitializer.Init(); } }
public void UpdatePointOfInterest_BadRequest_ReturnBadRequestObjectWithError() { //Arrange var poi = CityPoiItemBuilder.GeneratePointOfInterest(); var poiDto = DtoMapper.PoiToPoiDto(poi); PoiController.ModelState.AddModelError("Error", "Model state error"); //Action var result = PoiController.UpdatePointOfInterest(poi.Id, poiDto); //Assert result.Should().BeOfType <BadRequestObjectResult>(); }
public void CanConvertTripToDto() { var trip = new Trip { Id = 101, TripIdentifier = Guid.NewGuid().ToString(), Locations = TestUtils.GetDummyLocations() }; var tripDto = DtoMapper.ConvertTripToDto(trip); Assert.Equal(trip.TripIdentifier, tripDto.TripIdentifier); TestUtils.AssertEqual(trip.Locations, tripDto.Locations); }
public void UpdatePointOfInterest_PoiFound_CallsUpdateOnRepository() { var city = CityPoiItemBuilder.GenerateCity(); var poi = CityPoiItemBuilder.GeneratePointOfInterest(); city.PointsOfInterest.Add(poi); poi.CityId = city.Id; var poiDto = DtoMapper.PoiToPoiDto(poi); FakeCityRepository.GetCity(city.Id, IncludePointsOfInterest).Returns(city); var result = PoiController.UpdatePointOfInterest(poi.Id, poiDto); result.Should().BeOfType <NoContentResult>(); }
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 Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) { _appEnv = appEnv; AssemblyResolver.Initialize(); Framework.Logging.NLogLogger.SetConfiguration( Path.Combine(Path.Combine(appEnv.ApplicationBasePath, "config"), "web.nlog")); DtoMapper.Setup(); ServicePointManager.DefaultConnectionLimit = 10000; ServicePointManager.Expect100Continue = false; ServicePointManager.UseNagleAlgorithm = false; }
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(); }
public IActionResult GetLocations(string tripIdentifier, int fromIndex = 0) { if (string.IsNullOrEmpty(tripIdentifier)) { return(NotFound()); } var trip = _tripRepository.FindTrip(tripIdentifier); if (trip == null) { return(NotFound()); } var locations = trip.Locations.Where((location, index) => index >= fromIndex); return(Ok(DtoMapper.ConvertLocationsToDto(locations))); }
public async Task <CalendarEntryDTO> AddUpdateCalendarEntry(string loggedUserId, EmployeeTypeEnum loggedUserType, CalendarEntryDTO entryDTO) { if (entryDTO.EmployeeId != loggedUserId && loggedUserType == EmployeeTypeEnum.User) { throw new AdminRoleRequiredException(); } if (entryDTO.StartDate >= entryDTO.EndDate) { throw new ArgumentException("End Date must be after Start Date"); } CalendarEntry entry = entryDTO.IsNew ? await addCalendarEntry(loggedUserType, entryDTO) : await updateCalendarEntry(loggedUserId, loggedUserType, entryDTO); await _context.SaveChangesAsync(); return(DtoMapper.MapCalendarEntryToDTO(entry)); }
public override void Configure(Funq.Container container) { ServiceStack.Text.JsConfig.EmitCamelCaseNames = true; Plugins.Add(new SwaggerFeature()); // Disabling Html seems to make it so browsers can't hit the service. const Feature DisableFeatures = Feature.Xml | Feature.Jsv | Feature.Csv | Feature.Soap; // | Feature.Html; SetConfig(new EndpointHostConfig { EnableFeatures = Feature.All.Remove(DisableFeatures), DefaultContentType = ContentType.Json }); DtoMapper.Init(); }
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); }
protected DataAccessBase(DtoMapper mapper) { Mapper = mapper; }
public CategoryDataAccess(DtoMapper mapper, CategoryRepository categoryRepository) : base(mapper) { _repository = categoryRepository; }
public ProductDataAccess(DtoMapper mapper, IProductRepository repository) : base(mapper) { _repository = repository; }