/// <summary> /// Try to get an instance of type T based on the dynamic object /// values and the IConfigurationMappingBase instance that defines /// the mapping between a T object and a dynamic instance /// </summary> /// <typeparam name="T">the type of the object to construct and fill</typeparam> /// <param name="values">a dynamic object with the values to fill</param> /// <returns></returns> public static T TryGet <T>(dynamic values) where T : class, new() { if (!ConfigurationMapper.HasMappingFor <T>()) { if (Automap) { return(TryGetWithoutMapping <T>(values)); } else { _logger.Warn("Type {0} is not mapped in the configuration", typeof(T)); //return new T(); throw new NotAMappedTypeException(); } } T result = default(T); try { IConfigurationMappingsBase <T> mapper = ConfigurationMapper.GetMapper <T>(); result = mapper.Get(values); } catch (Exception ex) { _logger.Error(ex.Message); throw new MapperInvocationException(); } return(result); }
public void GetTypeMappingNoSectionTest() { TypeMappingElement actual = ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping("thisConfigDoesNotExist"); Assert.IsNull(actual); }
public void Test_LoadConfigurationForFile() { var filePath = CreateConfigFile("config.json", new JObject( new JProperty("SomeKey", "SomeValue"))); var directory = new Directory(null, "dir"); var fileMock = MockFile("file.ext", "", directory); directory.AddFile(fileMock.Object); var configFileMock = MockFile("file.ext.MusicFileCop.json", filePath, directory); directory.AddFile(configFileMock.Object); var mapper = new ConfigurationMapper(); var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object); configurationLoader.LoadConfiguration(MockConfigurationNode().Object, fileMock.Object); var config = mapper.GetConfiguration(fileMock.Object); Assert.NotNull(config); Assert.Equal("SomeValue", config.GetValue("SomeKey")); }
public void Test_FileInheritsDirectoryConfiguration() { var directoryConfig = CreateConfigFile("config1.json", new JObject( new JProperty("SomeKey", "SomeValue"))); var directory = new Directory(null, "Irrelevant"); var directoryConfigMock = MockFile("MusicFileCop.json", directoryConfig, directory); var fileMock = MockFile("file1.ext", "", directory); directory.AddFile(directoryConfigMock.Object); directory.AddFile(fileMock.Object); var mapper = new ConfigurationMapper(); var configurationLoader = new ConfigurationLoader(mapper, MockDefaultConfigurationNode().Object); configurationLoader.LoadConfiguration(MockConfigurationNode().Object, directory); var fileConfig = mapper.GetConfiguration(fileMock.Object); Assert.NotNull(fileConfig); Assert.Equal("SomeValue", fileConfig.GetValue("SomeKey")); }
public Startup(IConfiguration configuration) { Configuration = configuration; HelperAppSettings helperAppSettings = new HelperAppSettings(Configuration); ConfigurationMapper.Register(); }
public void MapTest() { ConfigurationMapper<TestClassA, TestClassB> target = new ConfigurationMapper<TestClassA, TestClassB>(); TestClassA from = new TestClassA() { Name = "test" }; TestClassB to = new TestClassB(); target.Map(from, to); Assert.AreEqual(from.Name, to.InnerClassName); }
public void MapTest() { var target = new ConfigurationMapper <TestClassA, TestClassB>(); var from = new TestClassA { Name = "test" }; var to = new TestClassB(); target.Map(from, to); Assert.AreEqual(from.Name, to.InnerClassName); }
public async Task <IEnumerable <ITableEntity> > PeckAsync(PeckSource source) { var config = new ConfigurationMapper().Map(source.SourceConnectionString); var startTimeUtc = source.LastOffset.DateTime; var metricCollectionService = CreateMetricCollectionService(config); var request = CreateRequest(source.CustomConfig, config.ResourceId, startTimeUtc, source.IntervalMinutes); var metrics = await metricCollectionService.CollectMetrics( request); var timeCapturedUtc = DateTimeOffset.UtcNow; return(metrics.Select(m => PeckResultExtensions.ToEntity(m, source.Name, timeCapturedUtc)).ToArray()); }
public void ShouldGetAnEmptyValueWithEmptyData() { Dictionary <string, object> dv = new Dictionary <string, object>(); dv.Add("test_name", "Rui"); User user = ValueFactory.TryGet <User>(dv); IConfigurationMappingsBase <User> mapper = ConfigurationMapper.GetMapper <User>(); Assert.IsNotNull(mapper); Log(mapper.ConfiguredType); Log(mapper.Settings.ToList()); var result = mapper.Get(dv); Assert.IsNotNull(result); Assert.IsTrue(ConfigurationMapper.HasMappingFor <User>()); Log(result.ToString()); Log(ConfigurationMapper.HasMappingFor <User>(), "Have mapping for user"); Assert.IsNotNull(user); Log(user.ToString()); }
public IHttpActionResult Get() { #region Preconditions if (configurationRepository == null) { throw new InvalidOperationException(); } #endregion try { var configuration = configurationRepository.GetConfiguration(); var dtoConfiguration = ConfigurationMapper.TranslateModelConfigurationToDTOConfiguration(configuration); return(Ok(dtoConfiguration)); } catch (Exception) { return(InternalServerError()); } }
public void ShouldHaveMappingForUserTypeAfterAutoConfigure() { Assert.IsTrue(ValueFactory.Initialized); Assert.IsTrue(ConfigurationMapper.HasMappingFor <User>(), "Configuration should have mapping for 'User' class defined in test assembly after autoconfigure"); }
public ConfigurationValueService(Context context) { _configurationValueRepository = new ConfigurationValueRepository(context); _configurationRowRepository = new ConfigurationRowRepository(context); _mapper = new Mapper(ConfigurationMapper.MapperConfiguration()); }
public void GetTypeMappingTest() { var actual = ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping(); Assert.IsNotNull(actual); }
public void GetTypeMappingNullSectionTest() { ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping(null); }
public ConfigurationColumnService(Context context) { _configurationColumnRepository = new ConfigurationColumnRepository(context); _mapper = new Mapper(ConfigurationMapper.MapperConfiguration()); }
/// <summary> /// The static constructor auto loads the default configuration /// by discovery /// </summary> static ValueFactory() { ConfigurationMapper.AutoConfigure(); _initialisized = true; }
public ConfigurationMapperShould() { Sut = new ConfigurationMapper(); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationScript"/> class. /// </summary> /// <param name="unitOfWork">The unit of work - database context used in persistance.</param> public ConfigurationScript(IUnitOfWork unitOfWork, ExecutionController controller) : base(unitOfWork) { this.mapper = new ConfigurationMapper(unitOfWork.ConnectionManager); this.mapper.Transaction = unitOfWork.Transaction; this.ExecutionController = controller; }