public void Should_map_sucessfully() { string hostname = "hostname"; var client = "someClient"; var freq = 100; var configMapper = new ConfigMapper(hostname, stop, dataClientFactory, graphiteClientFactory, log); var taskSet = new List<SqlToGraphiteConfigTemplatesWorkItemsTaskSet>(); var x = new SqlToGraphiteConfigTemplatesWorkItemsTaskSet { frequency = freq.ToString(), Task = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask[1] }; x.Task[0] = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask { client = client, connectionstring = "cs", name = "name", path = "path", port = "1234", sql = "sql", type = "type" }; taskSet.Add(x); var clients = new GraphiteClients(); clients.Add(client, "1234"); var taskList = configMapper.Map(taskSet, clients); Assert.That(taskList.Count, Is.EqualTo(1)); Assert.That(taskList[0].Frequency, Is.EqualTo(freq)); Assert.That(taskList[0].Tasks.Count, Is.EqualTo(1)); Assert.That(taskList[0].Tasks[0].GetType(), Is.EqualTo(typeof(Task))); }
public GradeController() { mapper = ConfigMapper.Config(); repository = AutofacConfig.Confing() .BeginLifetimeScope() .Resolve <IGenericRepository <Grade> >(); }
public bool Map(object parentObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper) { var collectionElement = element.GetElementNamed(ElementName ?? destinationProperty.Name); if (collectionElement == null) { return false; } object destinationCollection = GetDestinationCollection(parentObject, destinationProperty); Action<object> adder = GetCollectionAdder(destinationCollection); var payloadType = destinationProperty.PropertyType.GetGenericArguments()[0]; if (payloadType.IsComplex()) { PopulateComplexValues(collectionElement, payloadType, mapper, adder); } else { PopulateSimpleValues(collectionElement, payloadType, mapper, adder); } return true; }
/// <summary> /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs. /// </summary> /// <param name="services"></param> /// <param name="settingsFile">The full path of where the configuration settings file is located.</param> /// <param name="configSection">The section found within the configuration file.</param> /// <returns></returns> public static IServiceCollection AddHareDu(this IServiceCollection services, string settingsFile, string configSection) { var internalConfig = new InternalHareDuConfig(); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile(settingsFile, false) .Build(); configuration.Bind(configSection, internalConfig); HareDuConfig config = ConfigMapper.Map(internalConfig); services.AddSingleton(config); services.AddSingleton <IBrokerObjectFactory, BrokerObjectFactory>(); services.AddSingleton <IScanner, Scanner>(); services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>(); services.AddSingleton <IScannerFactory, ScannerFactory>(); services.AddSingleton <IScannerResultAnalyzer, ScannerResultAnalyzer>(); services.AddSingleton <ISnapshotFactory>(x => new SnapshotFactory(x.GetService <IBrokerObjectFactory>())); services.AddSingleton <ISnapshotWriter, SnapshotWriter>(); services.AddSingleton <IDiagnosticReportFormatter, DiagnosticReportTextFormatter>(); services.AddSingleton <IDiagnosticWriter, DiagnosticWriter>(); return(services); }
public void Should_map_sucessfully() { string hostname = "hostname"; var clientName = "someClient"; var freq = 100; var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository); var taskSets = new List<TaskSet>(); var taskSet = new TaskSet { Frequency = freq, Tasks = new List<Task>() }; string name = new Guid().ToString(); Job job = new WmiClient(); job.ClientName = clientName; configRepository.Expect(y => y.GetJob(name)).Return(job); configRepository.Expect(y => y.GetClient(clientName)).Return(new GraphiteTcpClient()); taskSet.Tasks.Add(new Task() { JobName = name }); taskSets.Add(taskSet); //Test var taskList = configMapper.Map(taskSets); //Assert Assert.That(taskList.Count, Is.EqualTo(1)); Assert.That(taskList[0].Frequency, Is.EqualTo(freq)); Assert.That(taskList[0].Tasks.Count, Is.EqualTo(1)); Assert.That(taskList[0].Tasks[0].GetType(), Is.EqualTo(typeof(RunableRunTask))); configRepository.VerifyAllExpectations(); }
private void PopulateComplexValues(XmlElement collectionElement, Type payloadType, ConfigMapper mapper, Action<object> adder) { foreach (var childElement in collectionElement.ChildNodes.OfType<XmlElement>()) { var mappedObject = mapper.GetObjectFromXml(payloadType, childElement); adder(mappedObject); } }
public override ResponseBase ExecuteRequest() { CustomerDTO CustomerDTO = new CustomerDTO(); AddCustomerResponse responseObject = new AddCustomerResponse(); try { Customer CUSTOMER = new Customer(); using (CustomerDemoEntities ctx = new CustomerDemoEntities()) { var _customer = ctx.Customers.Where(c => c.Name == customer.Name).FirstOrDefault(); if (_customer == null) { if (customer.PhoneNumbers.Count > 0) { List <PhoneNumber> phoneNumbers = new List <PhoneNumber>(); for (int i = 0; i < customer.PhoneNumbers.Count; i++) { PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.Number = customer.PhoneNumbers[i].Number; phoneNumbers.Add(phoneNumber); ctx.PhoneNumbers.Add(phoneNumber); } CUSTOMER.PhoneNumbers = phoneNumbers; } CUSTOMER.Name = customer.Name; CUSTOMER.BirthDate = customer.BirthDate; CUSTOMER.Gender = customer.Gender; CUSTOMER.Email = customer.Email; CUSTOMER.Address = customer.Address; CUSTOMER.Notes = customer.Notes; ctx.Customers.Add(CUSTOMER); ctx.SaveChanges(); customer.ID = CUSTOMER.ID; CustomerDTO = ConfigMapper.Map <Customer, CustomerDTO>(CUSTOMER); responseObject.Message = "Customer Added Successufully"; responseObject.IsSuccess = true; responseObject.customer = CustomerDTO; } else { responseObject.IsSuccess = false; responseObject.Message = "Customer already exist"; } } } catch (Exception e) { responseObject.IsSuccess = false; responseObject.Message = e.Message; } return(responseObject); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.IoC(Configuration); ConfigMapper.RegistrarMapas(); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ConfigMapper.Config(); }
/// <summary> /// Registers all the necessary components to use the low level HareDu Broker, Diagnostic, and Snapshotting APIs. /// </summary> /// <param name="builder"></param> /// <param name="settingsFile">The full path of where the configuration settings file is located.</param> /// <param name="configSection">The section found within the configuration file.</param> /// <returns></returns> public static ContainerBuilder AddHareDu(this ContainerBuilder builder, string settingsFile, string configSection) { builder.Register(x => { var internalConfig = new InternalHareDuConfig(); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile(settingsFile, false) .Build(); configuration.Bind(configSection, internalConfig); HareDuConfig config = ConfigMapper.Map(internalConfig); return(config); }) .SingleInstance(); builder.RegisterType <BrokerObjectFactory>() .As <IBrokerObjectFactory>() .SingleInstance(); builder.RegisterType <Scanner>() .As <IScanner>() .SingleInstance(); builder.RegisterType <KnowledgeBaseProvider>() .As <IKnowledgeBaseProvider>() .SingleInstance(); builder.RegisterType <ScannerFactory>() .As <IScannerFactory>() .SingleInstance(); builder.RegisterType <ScannerResultAnalyzer>() .As <IScannerResultAnalyzer>() .SingleInstance(); builder.RegisterType <SnapshotWriter>() .As <ISnapshotWriter>() .SingleInstance(); builder.RegisterType <DiagnosticReportTextFormatter>() .As <IDiagnosticReportFormatter>() .SingleInstance(); builder.RegisterType <DiagnosticWriter>() .As <IDiagnosticWriter>() .SingleInstance(); builder.Register(x => new SnapshotFactory(x.Resolve <IBrokerObjectFactory>())) .As <ISnapshotFactory>() .SingleInstance(); return(builder); }
public IActionResult get() { using (var db = new StepperTaskDBContext()) { List <Steps> steps = db.Steps.Include(step => step.Items).ToList(); List <StepDTO> result = ConfigMapper.MapList <Steps, StepDTO>(steps); return(Ok(result)); } }
public void RetrieveConfig() { FakeConfig Config = new FakeConfig(); FakeConfig RetrievedConfig = ConfigMapper.Get <FakeConfig>(); if (Config.Test == RetrievedConfig.Test) { Assert.Fail(); } }
public void ImplicitCastingShouldInvokeTheMapper() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); Person person = (dynamic)mapper; person.Name.Should().Be("Jon"); person.Age.Should().Be(30); }
public void InterfaceWithMultipleSubInterfacesShouldBeSupported() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); ISpecialistEmployee employee = (dynamic)mapper; employee.Name.Should().Be("Jon"); employee.SpecialistField.Should().Be("Cheese"); }
public void InterfaceWithMultipleConflictingInterfacesShouldBeSupported() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); IDepartmentEmployee employee = (dynamic)mapper; ((IPerson)employee).Name.Should().Be("Jon"); ((IHaveADepartment)employee).Name.Should().Be("Jon"); //example kinda sucks, but you are also somewhat insane }
public void FlatInterfaceWithGettersButNoSettersShouldBeSupported() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); IPersonGettersOnly person = (dynamic)mapper; person.Name.Should().Be("Jon"); person.Age.Should().Be(30); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); UnityConfig.RegisterComponents(); // Kickstart Unity GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); ConfigMapper.MapAll(); // Kickstart AutoMapper; Declare Maps }
public void InterfaceWithSingleSubInterfaceShouldBeSupported() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); IEmployee employee = (dynamic)mapper; employee.Id.Should().Be("A123"); employee.Name.Should().Be("Jon"); }
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); ConfigMapper.Initialize(); }
public void InterfaceFlatInterfaceWithGettersButNoSettersShouldBeSupported() { var doc = new XmlDocument(); doc.LoadXml(XML); var mapper = new ConfigMapper(doc.DocumentElement); IPersonGetSchoolOnly person = (dynamic)mapper; var school = person.School; school.Should().NotBeNull(); school.Name.Should().Be("westcliff"); }
public void CollectionsOfSimpleValuesShouldBeMapped() { var doc = new XmlDocument(); doc.LoadXml(SIMPLE); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml<SimplePersonRW>(); var pets = person.Pets; pets.Count.Should().Be(3); pets[0].Should().Be("scruffy"); pets[1].Should().Be("scratchy"); pets[2].Should().Be("tiddles"); }
public void CollectionsOfSimpleValuesShouldBeMapped_EvenWhenThePropertyOnlyHasASetter() { var doc = new XmlDocument(); doc.LoadXml(SIMPLE); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml<SimplePersonWO>(); var pets = person.GetPets(); pets.Count.Should().Be(3); pets[0].Should().Be("scruffy"); pets[1].Should().Be("scratchy"); pets[2].Should().Be("tiddles"); }
public override ResponseBase ExecuteRequest() { List <CustomerDTO> CustomerDTOs = new List <CustomerDTO>(); GetCustomerResponse responseObject = new GetCustomerResponse(); try { List <Customer> CUSTOMERs = new List <Customer>(); using (CustomerDemoEntities ctx = new CustomerDemoEntities()) { if (!String.IsNullOrEmpty(SearchKey)) { CUSTOMERs = ctx.Customers.Where(c => c.Name.Contains(SearchKey) || c.Email.Contains(SearchKey)).ToList(); // || (c.ID = ctx.PhoneNumbers.Where(p => p.Number.ToString().Contains(SearchKey)).FirstOrDefault().ID).ToList(); CustomerDTOs = ConfigMapper.MapList <Customer, CustomerDTO>(CUSTOMERs); if (CustomerDTOs.Count == 0) { responseObject.Message = "No Customer found"; } responseObject.IsSuccess = true; responseObject.customers = CustomerDTOs; } else { CUSTOMERs = ctx.Customers.ToList(); if (CUSTOMERs.Count > 0) { CustomerDTOs = ConfigMapper.MapList <Customer, CustomerDTO>(CUSTOMERs); responseObject.IsSuccess = true; responseObject.customers = CustomerDTOs; } else { responseObject.Message = "No Customer found"; responseObject.IsSuccess = true; } } } } catch (Exception e) { responseObject.IsSuccess = false; responseObject.Message = e.Message; } return(responseObject); }
public void Map_Simple_PrivateProperty_Exception() { var value = "some value"; var configMapper = new ConfigMapper <ClassSimple>(); var path = new List <string> { "ClassName", "PropStringPrivate", }; Assert.Throws <NullReferenceException>(() => configMapper.Map(path, value)); }
public void CollectionsOfComplexValuesShouldBeMapped() { var doc = new XmlDocument(); doc.LoadXml(COMPLEX); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml<ComplexPersonRW>(); var pets = person.Pets; pets.Count.Should().Be(2); pets[0].Paws.Should().Be(4); pets[0].Name.Should().Be("Cuddles"); pets[1].Paws.Should().Be(3); pets[1].Name.Should().Be("Tiddles"); }
public void Map_Simple_WrongTypeProperty_Exception() { var fakeValue = 10; var configMapper = new ConfigMapper <ClassSimple>(); var path = new List <string> { "ClassName", "PropStringPublic", }; Assert.Throws <DataException>(() => configMapper.Map(path, fakeValue)); }
public void CollectionsOfSimpleValuesShouldBeMapped_EvenWhenThePropertyOnlyHasASetter() { var doc = new XmlDocument(); doc.LoadXml(XML); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml<PersonWO>(); var car = person.GetCar(); car.Make.Should().Be("Ford"); car.Year.Should().Be(2010); var stereo = car.GetStereo(); stereo.Model.Should().Be("Alpine"); stereo.MP3.Should().BeTrue(); }
public void CollectionsOfSimpleValuesShouldBeMapped() { var doc = new XmlDocument(); doc.LoadXml(XML); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml<Person>(); var car = person.Car; car.Make.Should().Be("Ford"); car.Year.Should().Be(2010); var stereo = car.Stereo; stereo.Model.Should().Be("Alpine"); stereo.MP3.Should().BeTrue(); }
public void CollectionsOfSimpleValuesShouldBeMapped() { var doc = new XmlDocument(); doc.LoadXml(SIMPLE); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml <SimplePersonRW>(); var pets = person.Pets; pets.Count.Should().Be(3); pets[0].Should().Be("scruffy"); pets[1].Should().Be("scratchy"); pets[2].Should().Be("tiddles"); }
public void CollectionsOfSimpleValuesShouldBeMapped_EvenWhenThePropertyOnlyHasASetter() { var doc = new XmlDocument(); doc.LoadXml(SIMPLE); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml <SimplePersonWO>(); var pets = person.GetPets(); pets.Count.Should().Be(3); pets[0].Should().Be("scruffy"); pets[1].Should().Be("scratchy"); pets[2].Should().Be("tiddles"); }
public void TestPresistance() { FakeConfig Config = ConfigMapper.Get <FakeConfig>(false); Assert.IsFalse(ConfigMapper.Configs.ContainsKey(Config.GetType()), "Presistance avoidance failed"); Config = (FakeConfig)ConfigMapper.Get(typeof(FakeConfig), false); Assert.IsFalse(ConfigMapper.Configs.ContainsKey(Config.GetType()), "Presistance avoidance failed"); Config = ConfigMapper.Get <FakeConfig>(); Assert.IsTrue(ConfigMapper.Configs.ContainsKey(Config.GetType()), "Presistance failed"); }
public bool Map(object destinationObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper) { var childElement = element.GetElementNamed(ElementName ?? destinationProperty.Name); if (childElement == null) { return false; } var elementValue = childElement.InnerText; var destinationPropertyType = destinationProperty.PropertyType; if (destinationPropertyType.IsEnum) { var value = Enum.Parse(destinationPropertyType, elementValue); destinationProperty.SetValue(destinationObject, value, null); return true; } if (destinationPropertyType.IsNullable()) { if (elementValue == "") { destinationProperty.SetValue(destinationObject, null, null); return true; } destinationPropertyType = destinationPropertyType.GetGenericArguments()[0]; } if (destinationPropertyType.IsA<IConvertible>()) { var value = Convert.ChangeType(elementValue, destinationPropertyType); destinationProperty.SetValue(destinationObject, value, null); return true; } var converter = TypeDescriptor.GetConverter(destinationPropertyType); if (converter.CanConvertFrom(typeof (string))) { var value = converter.ConvertFromString(elementValue); destinationProperty.SetValue(destinationObject, value, null); return true; } return false; }
public static TaskManager CreateTaskManager(SqlToGraphiteSection configuration) { var cacheLength = new TimeSpan(0, configuration.ConfigCacheLengthMinutes, 0); var stop = new Stop(); IDataClientFactory dataClientFactory = new DataClientFactory(log); IGraphiteClientFactory graphiteClientFactory = new GraphiteClientFactory(log); var configMapper = new ConfigMapper(configuration.Hostname, stop, dataClientFactory, graphiteClientFactory, log); var configReader = new ConfigReader(configuration.ConfigUri,configuration.ConfigUsername,configuration.ConfigPassword); var cache = new Cache(cacheLength, log); var sleeper = new Sleeper(); var knownGraphiteClients = new KnownGraphiteClients(); var cr = new ConfigRepository(configReader, knownGraphiteClients, cache, sleeper, log, configuration.MinutesBetweenRetryToGetConfigOnError); var configController = new ConfigController(configMapper, log, cr); return new TaskManager(log, configController, configuration.ConfigUri, stop, sleeper, configuration.CheckConfigUpdatedEveryMinutes); }
public void CollectionsOfComplexValuesShouldBeMapped_EvenWhenThePropertyOnlyHasAGetter() { var doc = new XmlDocument(); doc.LoadXml(COMPLEX); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml <ComplexPersonRO>(); var pets = person.Pets; pets.Count.Should().Be(2); pets[0].Paws.Should().Be(4); pets[0].Name.Should().Be("Cuddles"); pets[1].Paws.Should().Be(3); pets[1].Name.Should().Be("Tiddles"); }
public bool Map(object parentObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper) { var objectElement = element.GetElementNamed(ElementName ?? destinationProperty.Name); if (objectElement == null) { return false; } object destinationObject = GetDestinationObject(parentObject, destinationProperty); /////////not sure about this.... mapper.PopulateObject(destinationObject, objectElement); return true; }
public void ConfigureServices(IServiceCollection services) { services.AddDbContext <AppDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddIdentity <IdentityUser, IdentityRole>().AddEntityFrameworkStores <AppDbContext>(); services.AddTransient <IClientesRepositorio, ClientesRepositorio>(); services.AddTransient <IProcedimentosRepositorio, ProcedimentosRepositorio>(); services.AddTransient <IFeedBackRepositorio, FeedBackRepositorio>(); services.AddMvc(); ConfigMapper.RegisterMapper(); }
public void Init() { var services = new ServiceCollection(); services.AddSingleton <IKnowledgeBaseProvider, KnowledgeBaseProvider>(); var internalConfig = new InternalHareDuConfig(); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile($"{TestContext.CurrentContext.TestDirectory}/appsettings.json", false) .Build(); configuration.Bind("HareDuConfig", internalConfig); HareDuConfig config = ConfigMapper.Map(internalConfig); services.AddSingleton(config); _provider = services.BuildServiceProvider(); var knowledgeBaseProvider = _provider.GetService <IKnowledgeBaseProvider>(); _probes = new List <DiagnosticProbe> { new HighConnectionCreationRateProbe(config.Diagnostics, knowledgeBaseProvider), new HighConnectionClosureRateProbe(config.Diagnostics, knowledgeBaseProvider), new UnlimitedPrefetchCountProbe(knowledgeBaseProvider), new ChannelThrottlingProbe(knowledgeBaseProvider), new ChannelLimitReachedProbe(knowledgeBaseProvider), new BlockedConnectionProbe(knowledgeBaseProvider), new QueueGrowthProbe(knowledgeBaseProvider), new MessagePagingProbe(knowledgeBaseProvider), new RedeliveredMessagesProbe(config.Diagnostics, knowledgeBaseProvider), new ConsumerUtilizationProbe(config.Diagnostics, knowledgeBaseProvider), new UnroutableMessageProbe(knowledgeBaseProvider), new QueueLowFlowProbe(config.Diagnostics, knowledgeBaseProvider), new QueueNoFlowProbe(knowledgeBaseProvider), new QueueHighFlowProbe(config.Diagnostics, knowledgeBaseProvider), new RuntimeProcessLimitProbe(config.Diagnostics, knowledgeBaseProvider), new SocketDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider), new NetworkPartitionProbe(knowledgeBaseProvider), new MemoryAlarmProbe(knowledgeBaseProvider), new DiskAlarmProbe(knowledgeBaseProvider), new AvailableCpuCoresProbe(knowledgeBaseProvider), new FileDescriptorThrottlingProbe(config.Diagnostics, knowledgeBaseProvider) }; }
public void Test1() { var config = new Config { Adapter = AdapterType.SHA256, IgnoreNullValue = true, OutputType = OutputType.Hex }; var value = ConfigMapper.MapToString(config); var resultConfig = ConfigMapper.FromString(value); Assert.AreEqual(AdapterType.SHA256, resultConfig.Adapter); Assert.AreEqual(OutputType.Hex, resultConfig.OutputType); Assert.AreEqual(true, resultConfig.IgnoreNullValue); }
public void CollectionsOfSimpleValuesShouldBeMapped_EvenWhenThePropertyOnlyHasASetter() { var doc = new XmlDocument(); doc.LoadXml(XML); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml <PersonWO>(); var car = person.GetCar(); car.Make.Should().Be("Ford"); car.Year.Should().Be(2010); var stereo = car.GetStereo(); stereo.Model.Should().Be("Alpine"); stereo.MP3.Should().BeTrue(); }
public void CollectionsOfSimpleValuesShouldBeMapped() { var doc = new XmlDocument(); doc.LoadXml(XML); var person = new ConfigMapper(doc.DocumentElement).GetObjectFromXml <Person>(); var car = person.Car; car.Make.Should().Be("Ford"); car.Year.Should().Be(2010); var stereo = car.Stereo; stereo.Model.Should().Be("Alpine"); stereo.MP3.Should().BeTrue(); }
public IActionResult post(ItemDTO model) { try { using (var db = new StepperTaskDBContext()) { Items item = ConfigMapper.Map <ItemDTO, Items>(model); db.Items.Add(item); db.SaveChanges(); return(Ok(item)); } } catch (Exception) { return(BadRequest()); } }
private void PopulateSimpleValues(XmlElement collectionElement, Type payloadType, ConfigMapper mapper, Action<object> adder) { foreach (var childElement in collectionElement.ChildNodes.OfType<XmlElement>()) { var elementValue = childElement.InnerText; if (payloadType.IsEnum) { var value = Enum.Parse(payloadType, elementValue); adder(value); } else if (payloadType.IsA<IConvertible>()) { var value = Convert.ChangeType(elementValue, payloadType); adder(value); } } }
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddAuthentication("OAuth_2.0") .AddJwtBearer("JWT", config => { config.RequireHttpsMetadata = false; config.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = JWT_Options.ISSUER, ValidateAudience = true, ValidAudience = JWT_Options.AUDIENCE, ValidateIssuerSigningKey = true, IssuerSigningKey = JWT_Options.GetSymmetricSecurityKey() }; }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); var mapperConfig = new MapperConfiguration(cfg => { ConfigMapper.Init(cfg); MapperConfig.Init(cfg); }); mapperConfig.CompileMappings(); var mapper = new Mapper(mapperConfig); ConfigServices.BuildConfig(services, Configuration.GetConnectionString("DefaultConnection")); services.AddSingleton <IMapper>(mapperConfig.CreateMapper()); services.AddScoped <ICarService, CarService>(); services.AddScoped <ICarClassService, CarClassService>(); services.AddScoped <ICompanyService, CompanyService>(); services.AddScoped <IOrderService, OrderService>(); services.AddScoped <IImageService, ImageService>(); services.AddScoped <ICustomerService, CustomerService>(); }
public void Should_throw_exception_if_graphite_client_is_unknown() { string hostname = "hostname"; var configMapper = new ConfigMapper(hostname, stop, dataClientFactory, graphiteClientFactory, log); var taskSet = new List<SqlToGraphiteConfigTemplatesWorkItemsTaskSet>(); var x = new SqlToGraphiteConfigTemplatesWorkItemsTaskSet { frequency = "100", Task = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask[1] }; x.Task[0] = new SqlToGraphiteConfigTemplatesWorkItemsTaskSetTask { client = "client", connectionstring = "cs", name = "name", path = "path", port = "1234", sql = "sql", type = "typr" }; taskSet.Add(x); var clients = new GraphiteClients(); var ex = Assert.Throws<ClientNotFoundException>(() => configMapper.Map(taskSet, clients)); Assert.That(ex.Message, Is.EqualTo("Client client is not known add this into the conifiguration xml")); }
public static TaskManager CreateTaskManager(SqlToGraphiteSection configuration) { var cacheLength = new TimeSpan(0, configuration.ConfigCacheLengthMinutes, 0); var stop = new Stop(); var directoryImpl = new DirectoryImpl(); var assemblyResolver = new AssemblyResolver(directoryImpl, log); IEncryption encryption = new Encryption(); IDataClientFactory dataClientFactory = new DataClientFactory(log, assemblyResolver, encryption); IGraphiteClientFactory graphiteClientFactory = new GraphiteClientFactory(log); var configReader = new ConfigHttpReader(configuration.ConfigUri, configuration.ConfigUsername, configuration.ConfigPassword); var cache = new Cache(cacheLength, log); var sleeper = new Sleeper(); var genericSer = new GenericSerializer(Global.GetNameSpace()); var cr = new ConfigRepository(configReader, cache, sleeper, log, configuration.MinutesBetweenRetryToGetConfigOnError, genericSer); var configMapper = new ConfigMapper(configuration.Hostname, stop, dataClientFactory, graphiteClientFactory, log, cr); var roleConfigFactory = new RoleConfigFactory(); var environment = new Environment(); var taskSetBuilder = new TaskSetBuilder(); var configController = new ConfigController(configMapper, log, cr, roleConfigFactory, environment, taskSetBuilder); return new TaskManager(log, configController, configuration.ConfigUri, stop, sleeper, configuration.CheckConfigUpdatedEveryMinutes); }
public bool Map(object destinationObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper) { var attributeValue = element.GetAttributeValue(AttributeName ?? destinationProperty.Name); if (attributeValue == null) { return false; } var destinationPropertyType = destinationProperty.PropertyType; if (destinationPropertyType.IsEnum) { var value = Enum.Parse(destinationPropertyType, attributeValue); destinationProperty.SetValue(destinationObject, value, null); return true; } if (destinationPropertyType.IsNullable()) { if (attributeValue == "") { destinationProperty.SetValue(destinationObject, null, null); return true; } destinationPropertyType = destinationPropertyType.GetGenericArguments()[0]; } if (destinationPropertyType.IsA<IConvertible>()) { var value = Convert.ChangeType(attributeValue, destinationPropertyType); destinationProperty.SetValue(destinationObject, value, null); return true; } return false; }
public void Should_throw_exception_if_graphite_client_is_unknown() { string clientName = "notKnown"; string jobName = "someJob"; var job = new WmiClient(); var msg = "some exception message"; job.ClientName = clientName; job.Name = jobName; configRepository.Expect(x => x.GetClient(clientName)).Throw(new ClientNotFoundException(msg)); configRepository.Expect(x => x.GetJob(jobName)).Return(job); string hostname = "hostname"; var configMapper = new ConfigMapper(hostname, this.stop, this.dataClientFactory, this.graphiteClientFactory, this.log, configRepository); var taskSets = new List<TaskSet>(); var taskSet = new TaskSet { Frequency = 100, Tasks = new List<Task>() }; var t = new Task { JobName = jobName }; taskSet.Tasks.Add(t); taskSets.Add(taskSet); //Test var ex = Assert.Throws<ClientNotFoundException>(() => configMapper.Map(taskSets)); //Assert Assert.That(ex.Message, Is.EqualTo(msg)); }
public bool Map(object destinationObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper) { return true; }