Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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);
 }
Ejemplo n.º 3
0
 public DoctorManager(IDoctorRepository doctorRepository,
                      IPrescriptionRepository prescriptionRepository,
                      IMedicineRepository medicineRepository,
                      DtoMapper dtoMapper)
 {
     mDoctorRepository       = doctorRepository;
     mPrescriptionRepository = prescriptionRepository;
     mMedicineRepository     = medicineRepository;
     mDtoMapper = dtoMapper;
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            DtoMapper.Configure();
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void Map_NullParameter_ArgumentNullExceptionThrown()
        {
            // arrange
            IMapper mapper = new DtoMapper();

            // act
            Func <object> act = () => mapper.Map <Source, Destination>(null);

            // assert
            Assert.Throws <ArgumentNullException>(act);
        }
Ejemplo n.º 9
0
        public void Update_IdDoesNotMatchItemId_ReturnBadRequest()
        {
            var poi    = CityPoiItemBuilder.GeneratePointOfInterest();
            var poiDto = DtoMapper.PoiToPoiDto(poi);


            var result = PoiController.UpdatePointOfInterest(NotMatchingId, poiDto);


            result.Should().BeOfType <BadRequestResult>();
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            DtoMapper.Initialize();
            DependecyRunningOn.Initialise();
            FluentValidationModelValidatorProvider.Configure();
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        public static void AssemblyInitFunction(TestContext context)
        {
            EnvironmentFactoryFactory.Initialize(context.Properties);

            AssemblyResolver.Initialize();

            Management.Services.DtoMapper.Setup();
            DtoMapper.Setup();

            SettingInitializer.Init();
        }
Ejemplo n.º 14
0
        public TripDto Checkin()
        {
            var trip = new Trip
            {
                TripIdentifier = Guid.NewGuid().ToString()
            };

            _tripRepository.Add(trip);

            return(DtoMapper.ConvertTripToDto(trip));
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 19
0
        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);
        }
Ejemplo n.º 22
0
        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();
            }
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 25
0
        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>();
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
        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;
        }
Ejemplo n.º 28
0
        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();
        }
Ejemplo n.º 29
0
        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)));
        }
Ejemplo n.º 30
0
        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));
        }
Ejemplo n.º 31
0
        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();
        }
Ejemplo n.º 32
0
        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);
        }
Ejemplo n.º 33
0
 protected DataAccessBase(DtoMapper mapper)
 {
     Mapper = mapper;
 }
Ejemplo n.º 34
0
 public CategoryDataAccess(DtoMapper mapper, CategoryRepository categoryRepository)
     : base(mapper)
 {
     _repository = categoryRepository;
 }
Ejemplo n.º 35
0
 public ProductDataAccess(DtoMapper mapper, IProductRepository repository)
     : base(mapper)
 {
     _repository = repository;
 }