public void TestBasicSetup2() { ILoaderFactory factory = new LoaderFactory(); Assert.IsNotNull(factory); Assert.IsNull(factory.GetLoader(null)); }
public void TestFileLoaderReturn() { ILoaderFactory factory = new LoaderFactory(); Mock <ILoaderConfiguration> testConfig = new Mock <ILoaderConfiguration>(); testConfig.Setup(x => x.LoaderType).Returns(LoaderTypeEnum.FileLoader); ILoader loader = factory.GetLoader(testConfig.Object); Assert.AreEqual(typeof(FileLoader), loader.GetType()); }
// Metodos para Crear y destruir configuraciones dinamicas en tiempo de ejecuccion. // Se puede usar estos metodos a modo de cache seguro dentro de las aplicaciones. /// <summary> /// Crea un contenedor en modo manual y los guarda en el sistema de configuracion. /// El programador puede crear un contenedor en tiempo de ejecuccion y usarlo posteriormente con los demas contenedores. /// </summary> /// <param name="appKey">Llave para el contenedor. No puede estar repetida.</param> /// <param name="groups">Listado de nombres para los grupos. Debe tener almenos uno.</param> /// <returns>Contenedor creado.</returns> public static SettingsManager CreateContainer(string appKey, IEnumerable <string> groups) { lock (_instanceLock) { //Validaciones if (String.IsNullOrWhiteSpace(appKey)) { throw new ArgumentException("AppKey must be not null and not empty", "appKey"); } if (groups == null) { throw new ArgumentNullException("groups", "Groups cannot be null."); } if (!groups.Any()) { throw new ArgumentException("Groups must have at least 1 element.", "groups"); } if (groups.Any(x => String.IsNullOrWhiteSpace(x))) { throw new ArgumentException("All groups must be not null and not empty.", "groups"); } if (_stores.ContainsKey(appKey)) { throw new DuplicateKeyException(appKey, String.Format("Cannot create SettingsManager with key {0}, call method MergeSettings instead.", appKey)); } //Crear contenedor var storeData = new ConcurrentDictionary <string, IDictionary <string, object> >( groups.Select(groupKey => new KeyValuePair <string, IDictionary <string, object> >( groupKey, new ConcurrentDictionary <string, object>() ))); var newStore = new SettingsManager(appKey, storeData); foreach (var group in groups) { newStore._loaders.Add(LoaderFactory.GetLoader(Sections.LoaderType.Manual, appKey, null, group)); } _stores.Add(appKey, newStore); Logger.InfoFormat("[Manual-Mode] {0} SettingsManager Store Added successfully.", appKey); return(newStore); } }
public static void AddGroup(string appKey, string group) { lock (_instanceLock) { if (String.IsNullOrWhiteSpace(group)) { throw new ArgumentException("Group must be not null and not empty", "group"); } var store = GetStore(appKey); //Get the Store if (store._settingsContainer.ContainsKey(group)) { throw new DuplicateKeyException(group, String.Format("Group {0} already exisit in Store {1}.", group, appKey)); } if (!store._settingsContainer.TryAdd(group, new ConcurrentDictionary <string, object>())) { throw new Exception(String.Format("Error adding Group {0} into Store {1}", group, appKey)); } store._loaders.Add(LoaderFactory.GetLoader(Sections.LoaderType.Manual, appKey, null, group)); } }