예제 #1
0
        /// <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);
        }
예제 #2
0
        public void GetTypeMappingNoSectionTest()
        {
            TypeMappingElement actual =
                ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping("thisConfigDoesNotExist");

            Assert.IsNull(actual);
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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();
        }
예제 #6
0
 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);
 }
예제 #7
0
        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);
        }
예제 #8
0
        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());
        }
예제 #9
0
        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());
        }
예제 #10
0
        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());
            }
        }
예제 #11
0
 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");
 }
예제 #12
0
 public ConfigurationValueService(Context context)
 {
     _configurationValueRepository = new ConfigurationValueRepository(context);
     _configurationRowRepository   = new ConfigurationRowRepository(context);
     _mapper = new Mapper(ConfigurationMapper.MapperConfiguration());
 }
예제 #13
0
        public void GetTypeMappingTest()
        {
            var actual = ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping();

            Assert.IsNotNull(actual);
        }
예제 #14
0
 public void GetTypeMappingNullSectionTest()
 {
     ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping(null);
 }
 public ConfigurationColumnService(Context context)
 {
     _configurationColumnRepository = new ConfigurationColumnRepository(context);
     _mapper = new Mapper(ConfigurationMapper.MapperConfiguration());
 }
예제 #16
0
 /// <summary>
 /// The static constructor auto loads the default configuration
 /// by discovery
 /// </summary>
 static ValueFactory()
 {
     ConfigurationMapper.AutoConfigure();
     _initialisized = true;
 }
예제 #17
0
 public ConfigurationMapperShould()
 {
     Sut = new ConfigurationMapper();
 }
예제 #18
0
 /// <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;
 }