Пример #1
0
        public void ControllerWithNoResourcesShouldNotMapsOptions()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<EmptyController>(routes, new MvcRouteHandler());

            mapper.MapSupportedMethods();

            Assert.That(routes.Count, Is.EqualTo(0));
        }
Пример #2
0
        public void ShouldCreateRoutesForAnnotatedActions()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<TestController>(routes, new MvcRouteHandler());

            mapper.MapSupportedMethods();

            Assert.That("GET /Test", Routes.To(new {controller = "Test", action = "List"}, routes));
            Assert.That("POST /Test", Routes.To(new {controller = "Test", action = "Create"}, routes));
        }
Пример #3
0
        public void ShouldMapHeadForAllResources()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<TestController>(routes, new MvcRouteHandler());

            mapper.MapHead();

            Assert.That("HEAD /test", Routes.To(new {controller = "Test", action = "Head", resourceUri = "Test"}, routes));
            Assert.That("HEAD /test/1", Routes.To(new {controller = "Test", action = "Head", resourceUri = "Test/{id}"}, routes));
        }
Пример #4
0
        public void ShouldMapHeadToDifferentControllerWithoutSubclassing()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<DifferentSuperclassController>(routes, new MvcRouteHandler());

            mapper.MapHead();

            Assert.That("HEAD /test", Routes.To(
                new {controller = "Restful", action = "Head", resourceUri = "Test", controllerType = typeof(DifferentSuperclassController)}, routes));
        }
Пример #5
0
        public void ShouldCreateMethodNotSupportedRoutesForUnmappedHttpMethods()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<TestController>(routes, new MvcRouteHandler());

            mapper.MapUnsupportedMethods();

            var methodNotSupported = new {controller = "Test", action = "MethodNotSupported", resourceUri = "test"};
            Assert.That("DELETE /test", Routes.To(methodNotSupported, routes));
            Assert.That("PUT /test", Routes.To(methodNotSupported, routes));
        }
Пример #6
0
        public void ShouldCreateRestfulControllerForUnmappedHttpMethodsWithoutSubclassing()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<DifferentSuperclassController>(routes, new MvcRouteHandler());

            mapper.MapUnsupportedMethods();

            var methodNotSupported = new {controller = "Restful", action = "MethodNotSupported",
                resourceUri = "test", controllerType = typeof(DifferentSuperclassController)};
            Assert.That("DELETE /test", Routes.To(methodNotSupported, routes));
        }
Пример #7
0
        public ActionResult <ApiResponse <List <ResourceDTO> > > GetResources()
        {
            List <Resource>    resources = this.repository.GetAll();
            List <ResourceDTO> resesDTO  = new List <ResourceDTO>();

            foreach (Resource res in resources)
            {
                ResourceDTO resDTO = ResourceMapper.MapToDTO(res);
                resesDTO.Add(resDTO);
            }
            return(new ApiResponse <List <ResourceDTO> >
            {
                Data = resesDTO
            });
        }
Пример #8
0
        public void Map_ClearsArray_ThenCopiesEntriesToNewArray()
        {
            ResourceMapper.Setup(c => c.Map(typeof(string), typeof(string), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>()))
            .Returns <Type, Type, string, string, object>((tfrom, tto, from, to, context) => from);
            var result = InvokeMapper(new List <string>()
            {
                "1", null, "3"
            }, new [] { "a", "b", "c" });

            InvokeMapper(new List <string>()
            {
                "4", "5", "6"
            }, result);
            Assert.AreEqual("4", result[0]);
            Assert.AreEqual("5", result[1]);
            Assert.AreEqual("6", result[2]);
        }
Пример #9
0
        public async Task <IPagedList <Resource> > GetResource(int page)
        {
            string url = "/api/Resource/GetResources";
            ApiResponse <List <ResourceDTO> > data = await request.CallApiWithoutAuth <ApiResponse <List <ResourceDTO> > >(url);

            IEnumerable <ResourceDTO> enumerable = data.Data as IEnumerable <ResourceDTO>;
            List <Resource>           resource   = new List <Resource>();

            foreach (ResourceDTO re in enumerable)
            {
                Resource reso = ResourceMapper.MapToModel(re);
                resource.Add(reso);
            }
            IPagedList <Resource> resources = resource.ToPagedList(page, 4);

            return(resources);
        }
Пример #10
0
        public void when_type_is_provided__resource_key_is_generated__patterns()
        {
            // GIVEN: a resource mapper
            ResourceMapperOptions options = new ResourceMapperOptions();

            options.StringCase = StringCase.PascalCase;
            options.Rules.AddRange(new[]
            {
                new Rule(
                    pattern: "System.ComponentModel.DataAnnotations.{class}Attribute.{property}#{descriptor}",
                    keyTemplate: "Validation_{class}_{property}",
                    sourceTemplate: "Core"
                    ),
                new Rule(
                    pattern: "{brand}.{library}.{package}.{module}.{feature}.{model}.{field}#{descriptor}",
                    keyTemplate: "{feature}_{model}_{field}_{descriptor}",
                    sourceTemplate: "{module}"
                    )
            });

            ResourceMapper resourceMapper = new ResourceMapper(options);

            // WHEN: a raw full qualified name is provided
            ResourceKey rawKey = resourceMapper.GetKey("Brand.Library.Package.Module.Feature.Model.Field#Descriptor");

            // THEN: a valid resource key is returned.
            Assert.Equal("Feature_Model_Field_Descriptor", rawKey.KeyName);
            Assert.Equal("Module", rawKey.ResourceName);
            Assert.Null(rawKey.ResourceLocation);

            // WHEN: a model type, field and descriptor is provided
            ResourceKey propKey = resourceMapper.GetKey <ClassMock>(m => m.PropertyMock, "DisplayName");

            // THEN: a valid resource key is returned.
            Assert.Equal("FeatureMock_ClassMock_PropertyMock_DisplayName", propKey.KeyName);
            Assert.Equal("ModuleMock", propKey.ResourceName);
            Assert.Null(propKey.ResourceLocation);

            // WHEN: a specially mapped class is provided
            ResourceKey validatorKey = resourceMapper.GetKey <RequiredAttribute>(r => r.ErrorMessage);

            // THEN: a valid key is provided
            Assert.Equal("Validation_Required_ErrorMessage", validatorKey.KeyName);
            Assert.Equal("Core", validatorKey.ResourceName);
        }
Пример #11
0
        private void getMaterials()
        {
            resDGV.Rows.Clear();
            db.Connect();
            var obj = db.GetRows("resource", "*", "");
            var res = new List <Resource>();

            foreach (var row in obj)
            {
                res.Add(ResourceMapper.Map(row));
            }

            foreach (var r in res)
            {
                resDGV.Rows.Add(r, r.price, r.unit, r.description);
            }

            db.Disconnect();
        }
Пример #12
0
 public ActionResult Edit(ResourceViewModel model)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var resource = ResourceMapper.MapViewModelToItem(model);
             resource.updated = DateTime.Today;
             unitOfWork.ResourcesRepository.Update(resource);
             unitOfWork.Save();
             return(RedirectToAction("Index"));
         }
     }
     catch (DataException dex)
     {
         ModelState.AddModelError("", dex.Message);
     }
     return(View(model));
 }
Пример #13
0
        public void Example()
        {
            // Create our source object
            var sourceObj = new SourceEntity {
                Number         = 10,
                NumberToString = -1000
            };

            var destObj = new DestEntity();

            // Create the object mapper
            var mapper = new ResourceMapper <object>();

            mapper.LoadStandardConverters(); // Load standard converters from System.Convert (e.g., int to string)
            mapper.RegisterTwoWayMapping <SourceEntity, DestEntity>(
                sourceToDest =>
            {
                sourceToDest.Set(to => to.DifferentlyNamedNumber, from => from.Number);
                sourceToDest.Set(to => to.DifferentlyNamedNumberToString, from => from.NumberToString);
                // Unspecified properties will be automapped after this point if not explicitly ignored using mapping.Ignore
            },
                destToSource =>
            {
                destToSource.Set(to => to.Number, from => from.DifferentlyNamedNumber);
                destToSource.Set(to => to.NumberToString, from => from.DifferentlyNamedNumberToString);
                // Unspecified properties will be automapped after this point if not explicitly ignored using mapping.Ignore
            });
            mapper.InitializeMap();

            // Perform map source => dest
            mapper.Map(sourceObj, destObj, null);
            Assert.AreEqual(sourceObj.Id, destObj.Id);
            Assert.AreEqual(sourceObj.Number, destObj.DifferentlyNamedNumber);
            Assert.AreEqual(sourceObj.NumberToString.ToString(), destObj.DifferentlyNamedNumberToString);

            // Perform map dest => source
            var newSourceObj = mapper.Map(destObj, new SourceEntity(), null);

            Assert.AreEqual(destObj.Id, newSourceObj.Id);
            Assert.AreEqual(destObj.DifferentlyNamedNumber, newSourceObj.Number);
            Assert.AreEqual(destObj.DifferentlyNamedNumberToString, newSourceObj.NumberToString.ToString());
        }
Пример #14
0
        private void eventsLB_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (eventsLB.SelectedItem is Event)
            {
                Event ev = eventsLB.SelectedItem as Event;
                approveGB.Visible = true;
                db.Connect();
                var resourcesForEvent = db.GetRows("event_resource", "event_id, resource_id, description, value",
                                                   "event_id=" + ev.id);
                var resources = new List <Resource>();
                foreach (var resForEvent in resourcesForEvent)
                {
                    var res      = db.GetRows("resource", "*", "resource_id=" + resForEvent[1]);
                    var resource = ResourceMapper.Map(res[0]);
                    resource.description = resForEvent[2].ToString();
                    resource.value       = Int32.Parse(resForEvent[3].ToString());
                    resources.Add(resource);
                }

                eventListGrid.Rows.Clear();
                double totalPrice = 0;
                foreach (var r in resources)
                {
                    eventListGrid.Rows.Add(r, r.description, r.value, r.unit, r.price, r.value * r.price);
                    totalPrice += r.value * r.price;
                }
                totalPriceLbl.Text = totalPrice.ToString();

                updateEvent(ev);

                var docObj = db.GetRows("event_documents", "*", "event_id=" + ev.id);
                var docs   = new List <Document>();
                foreach (var row in docObj)
                {
                    docs.Add(DocumentMapper.Map(row));
                }
                docsLB.Items.Clear();
                docsLB.Items.AddRange(docs.ToArray());

                db.Disconnect();
            }
        }
Пример #15
0
        public double BenchmarkTransmute(MapBuilder builderType)
        {
            // Resource mapper
            var mapper = new ResourceMapper <object>(builderType);

            mapper.LoadStandardConverters();
            mapper.RegisterOneWayMapping <ResourceClassComplex, DomainClassComplex>();
            mapper.RegisterOneWayMapping <ResourceClassSimple, DomainClassSimple>(mapping => mapping.Ignore(to => to.RandomProperty));
            mapper.InitializeMap();

            var start = DateTime.Now;

            for (int i = 0; i < Total; i++)
            {
                var domainObj = new DomainClassComplex();
                mapper.Map(_resourceObj, domainObj, null);
            }
            var end = DateTime.Now;

            return((end - start).TotalMilliseconds);
        }
        public IHttpActionResult GetByInfringementNumber(string infringementNumber)
        {
            try
            {
                var entity       = new infringementEntities();
                var infringement = entity.infringements.FirstOrDefault(x => x.Number == infringementNumber);

                if (infringement == null)
                {
                    return(NotFound());
                }

                var resource = ResourceMapper.Map(infringement);

                return(Ok(resource));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #17
0
        public ActionResult Appointments()
        {
            //var model = AppointMapper.MapAllItemsToViewModel(
            //    unitOfWork.ResInTasksRepository.Get(includeProperties: "Resource,Task"),
            //    unitOfWork.ResourcesRepository.Get());

            var model = new List <AppointViewModel>();
            var rits  = unitOfWork.ResInTasksRepository.Get(includeProperties: "Resource,Task");

            foreach (var item in rits.GroupBy(rit => rit.task_id).Select(g => g.First()))
            {
                IEnumerable <ResourceInTaskVM> resources = rits.Where(rit => rit.task_id == item.task_id).Select(x => AppointMapper.MapItemToViewModel(x)).ToList();
                model.Add(new AppointViewModel
                {
                    Task         = TaskMapper.MapItemToViewModel(item.Task),
                    Resources    = resources.ToList(),
                    AllResources = ResourceMapper.MapItemToViewModel(unitOfWork.ResourcesRepository.Get().Where(r => !resources.Any(vm => vm.Resource.Id == r.resource_id)))
                });
            }

            return(View(model));
        }
Пример #18
0
        public ActionResult Appoint(int id)
        {
            AppointViewModel model = new AppointViewModel();

            model.Task = TaskMapper.MapItemToViewModel(unitOfWork.TasksRepository.GetByID(id));

            var rits = unitOfWork.ResInTasksRepository.Get(x => x.task_id == id, includeProperties: "Resource,Task");

            if (rits != null)
            {
                model.Resources = AppointMapper.MapItemsToViewModel(rits);
            }
            else
            {
                model.Resources = new List <ResourceInTaskVM>();
            }

            model.AllResources = ResourceMapper.MapItemToViewModel(unitOfWork.ResourcesRepository.Get()
                                                                   .Where(r => !model.Resources.Any(vm => vm.Resource.Id == r.resource_id)));

            return(PartialView("_Appoint", model));
        }
Пример #19
0
        private void PlannedEventsForm_Load(object sender, EventArgs e)
        {
            db.Connect();
            var obj    = db.GetRows("event_template", "*", "");
            var events = new List <Event>();

            foreach (var row in obj)
            {
                events.Add(EventTemplateMapper.Map(row));
            }


            eventsLB.Items.AddRange(events.ToArray());


            issuesCB.Items.Clear();
            var iss    = db.GetRows("issues", "*", "");
            var issues = new List <Issue>();

            foreach (var row in iss)
            {
                issues.Add(IssueMapper.Map(row));
            }

            issuesCB.Items.AddRange(issues.ToArray());
            issuesCB.SelectedIndex = 0;

            var res       = db.GetRows("resource", "*", "");
            var resources = new List <Resource>();

            foreach (var row in res)
            {
                resources.Add(ResourceMapper.Map(row));
            }
            resLB.Items.AddRange(resources.ToArray());

            db.Disconnect();
        }
        public IHttpActionResult GetByRego(string rego)
        {
            try
            {
                var entity       = new infringementEntities();
                var infringement = entity.infringements
                                   .OrderByDescending(x => x.Id)
                                   .FirstOrDefault(x => x.Rego == rego & x.StatusId == 1);

                if (infringement == null)
                {
                    return(NotFound());
                }

                var resource = ResourceMapper.Map(infringement);

                return(Ok(resource));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Пример #21
0
        public void Example()
        {
            // Create our source object
            var sourceObj = new SourceEntity {
                Number = 10
            };

            sourceObj.NumberToString = -1000;

            var destObj = new DestEntity();

            // Create the object mapper
            var mapper = new ResourceMapper <object>();

            mapper.LoadStandardConverters(); // Load standard converters from System.Convert (e.g., int to string)
            mapper.RegisterOneWayMapping <SourceEntity, DestEntity>();
            mapper.InitializeMap();

            // Perform map
            mapper.Map(sourceObj, destObj, null);

            Assert.AreEqual(sourceObj.Number, destObj.Number);
            Assert.AreEqual(sourceObj.NumberToString.ToString(), destObj.NumberToString);
        }
Пример #22
0
        public void ShouldMapTunnelledRoutes()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<TunnelledController>(routes, new MvcRouteHandler());

            mapper.MapTunnelledMethods();

            Assert.That("POST /test _method=PUT", Routes.To(new {controller = "Tunnelled", action = "Put"}, routes));
            Assert.That("POST /test _method=DELETE", Routes.To(new {controller = "Tunnelled", action = "Delete"}, routes));
        }
Пример #23
0
 public ResourceMapperTest()
 {
     _resourceMapperSUT = new ResourceMapper();
     ResourceMapper.ConfigAutoMapper();
 }
Пример #24
0
        private dynamic CreateResource(JsonApiDocument document, JsonApiResource jsonApiResource)
        {
            var mapper = new ResourceMapper(document, _settings);

            return(mapper.ToObject(jsonApiResource));
        }
Пример #25
0
 public void CanMapFrom_AcceptedType_IfResourceMapperCanMap()
 {
     ResourceMapper.Setup(m => m.CanMap(typeof(DomainClassSimple), typeof(ResourceClassSimple))).Returns(true);
     Assert.IsTrue(Map.CanMap(typeof(IEnumerable <DomainClassSimple>), typeof(List <ResourceClassSimple>)));
     ResourceMapper.Verify(m => m.CanMap(typeof(DomainClassSimple), typeof(ResourceClassSimple)));
 }
Пример #26
0
 public DTOResource GetById(int Id)
 {
     return(ResourceMapper.GetDTOResources(UnitOfWork.ResourceRepository.GetByID(Id)));
 }
 public void SetUp()
 {
     _builder = new Builder();
     _mapper  = new ResourceMapper <object>();
     _mapper.ExportMapsTo("complex");
 }
Пример #28
0
 public void CanMapFrom_RejectedType_IfResourceMapperCantMap()
 {
     ResourceMapper.Setup(m => m.CanMap(typeof(DomainClassSimple), typeof(ResourceClassSimple))).Returns(false);
     Assert.IsFalse(Map.CanMap(typeof(IEnumerable <DomainClassSimple>), typeof(ResourceClassSimple[])));
     ResourceMapper.Verify(m => m.CanMap(typeof(DomainClassSimple), typeof(ResourceClassSimple)));
 }
Пример #29
0
        // GET: Resources/Edit/5
        public ActionResult Edit(int id)
        {
            var model = ResourceMapper.MapItemToViewModel(unitOfWork.ResourcesRepository.GetByID(id));

            return(View(model));
        }
Пример #30
0
 public override void Map_NullDestination()
 {
     ResourceMapper.Setup(c => c.ConstructOrThrow(typeof(ClassWithSeveralPropertiesDest))).Returns(new ClassWithSeveralPropertiesDest());
     InvokeMapper(new ClassWithSeveralPropertiesSrc(), null);
     ResourceMapper.Verify(c => c.ConstructOrThrow(typeof(ClassWithSeveralPropertiesDest)));
 }
 public override void Map_NullDestination()
 {
     ResourceMapper.Setup(m => m.RequireOneWayMap(typeof(int), typeof(long), It.IsAny <string>()));
     Map.GetMapper(typeof(int), typeof(long?));
     ResourceMapper.Verify(m => m.RequireOneWayMap(typeof(int), typeof(long), It.IsAny <string>()));
 }
Пример #32
0
        public ActionResult EditPartial(int id)
        {
            ResourceViewModel model = ResourceMapper.MapItemToViewModel(unitOfWork.ResourcesRepository.GetByID(id));

            return(PartialView("_Edit", model));
        }
Пример #33
0
        public void ShouldRouteAllUrisInAttribute()
        {
            var routes = new RouteCollection();
            var mapper = new ResourceMapper<MultipleController>(routes, new MvcRouteHandler());

            mapper.MapSupportedMethods();

            Assert.That("GET /test1", Routes.To(new {controller = "Multiple", action = "Test"}, routes));
            Assert.That("GET /test2", Routes.To(new {controller = "Multiple", action = "Test"}, routes));
        }
 public void TestInitialize()
 {
     this.resourceMapper = new ResourceMapper();
 }
        public void RunActions(string[] args)
        {
            log.Info("------------------------------------------------------------");
            log.Info("Starting XP2AFSAirportConverter");
            log.Info("------------------------------------------------------------");

            this.CreateDirectories();
            this.ReadSettings();

            this.ParseArgs(args);

            this.resourceMapper = new ResourceMapper();
            this.resourceMapper.ReadResourceMapping(Settings.ResourceMapPath);

            foreach (ConverterAction action in this.actions)
            {
                switch (action)
                {
                case ConverterAction.DownloadAirports:
                    log.Info("Starting Download Airports action");
                    this.DownloadAirports(icaoCodes);
                    log.Info("Finished Download Airports action");
                    break;

                case ConverterAction.GetAirportList:
                    log.Info("Starting Get Airport List action");
                    this.GetAirportList();
                    log.Info("Finished Get Airport List action");
                    break;

                case ConverterAction.GenerateRenderScripts:
                    log.Info("Starting Generate Render Scripts action");
                    this.GenerateRenderScripts(icaoCodes);
                    log.Info("Finished Generate Render Scripts action");
                    break;

                case ConverterAction.RunRenderScripts:
                    log.Info("Starting Run Render Scripts action");
                    this.RunRenderScripts(icaoCodes);
                    log.Info("Finished Run Render Scripts action");
                    break;

                case ConverterAction.BuildAirports:
                    log.Info("Starting Build Airports action");
                    this.BuildAirports();
                    log.Info("Finished Build Airports action");
                    break;

                case ConverterAction.UploadAirports:
                    log.Info("Starting Uplooad Airports action");
                    this.UploadAirports();
                    log.Info("Finished Uplooad Airports action");
                    break;

                case ConverterAction.AirportCsvList:
                    log.Info("Starting Airport CSV List action");
                    this.GenerateAirportCsvList();
                    log.Info("Finished Airport CSV List action");
                    break;

                case ConverterAction.ImportAirportCsvList:
                    log.Info("Starting Import Airport CSV List action");
                    this.ImportAirportCsvList();
                    log.Info("Finished Import Airport CSV List action");
                    break;

                case ConverterAction.Clean:
                    log.Info("Starting Clean action");
                    this.Clean();
                    log.Info("Finished Clean action");
                    break;

                case ConverterAction.GenerateAssetList:
                    log.Info("Starting Generate Asset List action");
                    this.GenereateAssetList();
                    log.Info("Finished Generate Asset List action");
                    break;

                case ConverterAction.GetMissingLocationData:
                    log.Info("Starting GetMissingLocationData action");
                    this.GetMissingLocationData();
                    log.Info("Finished GetMissingLocationData action");
                    break;
                }
            }

            log.Info("All actions complete");
        }