/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <typeparam name="TService">Type of service to register</typeparam> /// <typeparam name="TObject">Type of object implementing the service</typeparam> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public static void Register <TService, TObject>(InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { ServiceRegistry.DefaultContainer.Register(typeof(TService), typeof(TObject), parameters, properties, ltManager, customContext); }
/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <param name="serviceType">Type of service to register</param> /// <param name="serviceObjectType">Type of object implementing the service</param> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public static void Register(Type serviceType, Type serviceObjectType, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { ServiceRegistry.DefaultContainer.Register(serviceType, serviceObjectType, parameters, properties, ltManager, customContext); }
/// <summary> /// Sets the properties of an object as provided. /// </summary> /// <param name="instance">Object instance</param> /// <param name="properties">Object properties</param> public static void InjectProperties(ref object instance, PropertySettingsCollection properties) { if (properties == null) { return; } var type = instance.GetType(); foreach (var parameter in properties) { // --- Set up the initial values of properties var propInfo = type.GetProperty(parameter.Name, BindingFlags.Instance | BindingFlags.Public); if (propInfo == null) { // --- Undefined property used throw new ConfigurationErrorsException( string.Format("Type {0} does not have '{1}' public property.", type, parameter.Name)); } object objectValue; if (propInfo.PropertyType.IsEnum) { objectValue = Enum.Parse(propInfo.PropertyType, parameter.Value); } else { objectValue = Convert.ChangeType(parameter.Value, propInfo.PropertyType, CultureInfo.InvariantCulture); } propInfo.SetValue(instance, objectValue, null); } }
/// <summary> /// Instantiates an object and sets its properties as provided. /// </summary> /// <param name="type">Type to instantiate</param> /// <param name="properties">Collection of properties to set up</param> /// <returns>The newly instantiated object</returns> public static object CreateInstance(Type type, PropertySettingsCollection properties) { // --- Instantiate the object var tempInstance = Activator.CreateInstance(type); InjectProperties(ref tempInstance, properties); return tempInstance; }
/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <param name="serviceType">Type of service to register</param> /// <param name="serviceObjectType">Type of object implementing the service</param> /// <param name="parameters">Object construction parameters</param> /// <param name="properties">Object properties to inject</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="customContext"></param> public void Register(Type serviceType, Type serviceObjectType, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null, ILifetimeManager ltManager = null, object customContext = null) { if (serviceType == null) { throw new ArgumentNullException("serviceType"); } if (serviceObjectType == null) { throw new ArgumentNullException("serviceObjectType"); } if (_services.ContainsKey(serviceType)) { throw new ServiceAlreadyRegisteredException(serviceType); } // --- Register the new mapping _services[serviceType] = new ServiceMapping( serviceType, serviceObjectType, ltManager ?? new PerCallLifetimeManager(), parameters, properties, customContext); // --- Reset lifetime managers foreach (var mapping in _services.Values) { mapping.LifetimeManager.ResetState(); mapping.Resolved = false; } }
/// <summary> /// Sets the properties of an object as provided. /// </summary> /// <param name="instance">Object instance</param> /// <param name="properties">Object properties</param> public static void InjectProperties(ref object instance, PropertySettingsCollection properties) { if (properties == null) return; var type = instance.GetType(); foreach (var parameter in properties) { // --- Set up the initial values of properties var propInfo = type.GetProperty(parameter.Name, BindingFlags.Instance | BindingFlags.Public); if (propInfo == null) { // --- Undefined property used throw new ConfigurationErrorsException( string.Format("Type {0} does not have '{1}' public property.", type, parameter.Name)); } object objectValue; if (propInfo.PropertyType.IsEnum) { objectValue = Enum.Parse(propInfo.PropertyType, parameter.Value); } else { objectValue = Convert.ChangeType(parameter.Value, propInfo.PropertyType, CultureInfo.InvariantCulture); } propInfo.SetValue(instance, objectValue, null); } }
public void EmptyCollectionResultsEmptyProperties() { // --- Act var collection = new PropertySettingsCollection(); // --- Assert collection.ShouldHaveCountOf(0); }
/// <summary> /// Instantiates an object and sets its properties as provided. /// </summary> /// <param name="type">Type to instantiate</param> /// <param name="properties">Collection of properties to set up</param> /// <returns>The newly instantiated object</returns> public static object CreateInstance(Type type, PropertySettingsCollection properties) { // --- Instantiate the object var tempInstance = Activator.CreateInstance(type); InjectProperties(ref tempInstance, properties); return(tempInstance); }
/// <summary> /// Parse the specified configuration settings /// </summary> /// <param name="element">Element holding configuration settings</param> protected override void ParseFromXml(XElement element) { From = element.TypeAttribute(FROM, _typeResolver); To = element.TypeAttribute(TO, _typeResolver); Lifetime = element.OptionalTypeAttribute(LIFETIME, new LifeTimeTypeResolver(_typeResolver)); element.ProcessOptionalElement(PROPERTIES, item => Properties = new PropertySettingsCollection(item)); element.ProcessOptionalElement(CONSTRUCT, item => Parameters = new InjectedParameterSettingsCollection(item, _typeResolver)); }
public MappingSettings(Type @from, Type to, Type lifetime = null, InjectedParameterSettingsCollection parameters = null, PropertySettingsCollection properties = null) { From = @from; To = to; Lifetime = lifetime; Parameters = parameters; Properties = properties; }
/// <summary> /// Creates an instance initializing it with the specified parameters. /// </summary> /// <param name="instancePrefix">Application instance prefix</param> /// <param name="instanceName">Application instance name</param> /// <param name="provider">Application configuration provider</param> /// <param name="constructorParams">Constructor parameters</param> /// <param name="properties">Configuration instance properties</param> public AppConfigurationSettings(string instancePrefix, string instanceName, Type provider, UnnamedPropertySettingsCollection constructorParams = null, PropertySettingsCollection properties = null): this() { Init(); InstancePrefix = instancePrefix; InstanceName = instanceName; Provider = provider; if (constructorParams != null) ConstructorParameters = constructorParams; if (properties != null) Properties = properties; }
/// <summary> /// Creates an instance initializing it with the specified parameters. /// </summary> /// <param name="provider">Application configuration provider</param> /// <param name="constructorParams">Constructor parameters</param> /// <param name="properties">Configuration instance properties</param> /// <param name="instancePrefix">Application instance prefix</param> /// <param name="instanceName">Application instance name</param> public AppConfigurationSettings(Type provider, ConstructorParameterSettingsCollection constructorParams = null, PropertySettingsCollection properties = null, string instancePrefix = null, string instanceName = null) { InstancePrefix = instancePrefix; InstanceName = instanceName; Provider = provider; ConstructorParameters = constructorParams ?? new ConstructorParameterSettingsCollection(); Properties = properties ?? new PropertySettingsCollection(); }
/// <summary> /// Registers the specified object with its related lifetime manager, and the /// construction parameters used by the lifetime manager. /// </summary> /// <param name="serviceType">Type of service to register</param> /// <param name="ltManager">Lifetime manager object</param> /// <param name="constructionParams">Instance construction parameters</param> /// <param name="properties">Initial property values</param> public void Register(Type serviceType, ILifetimeManager ltManager, object[] constructionParams, PropertySettingsCollection properties = null) { if (_registry.ContainsKey(serviceType)) { throw new ConfigurationErrorsException( String.Format("'{0}' type already registered with DefaultServiceRegistry", serviceType)); } _registry[serviceType] = new Tuple<ILifetimeManager, object[], PropertySettingsCollection>( ltManager, constructionParams, properties); }
/// <summary> /// Creates a new instance of this class form the specified parameters. /// </summary> /// <param name="name">Task processor name</param> /// <param name="processorType">Processor type</param> /// <param name="taskType">Task type</param> /// <param name="instanceCount">Number of instances</param> /// <param name="context">Task execution copntext</param> /// <param name="properties">Collection of properties</param> public TaskProcessorSettings(string name, string processorType, Type taskType, int instanceCount, TaskExecutionContextSettings context, PropertySettingsCollection properties = null) { Name = name; ProcessorType = processorType; TaskType = taskType; InstanceCount = instanceCount; Context = context; if (properties != null) { _propertysSettings = properties; } }
/// <summary> /// Creates a new instance with the specified parameters. /// </summary> public ServiceMapping( Type serviceType, Type serviceObjectType, ILifetimeManager lifetimeManager, InjectedParameterSettingsCollection constructionParameters, PropertySettingsCollection properties, object customContext) { ServiceType = serviceType; ServiceObjectType = serviceObjectType; LifetimeManager = lifetimeManager; ConstructionParameters = constructionParameters; Properties = properties; CustomContext = customContext; }
public void InjectPropertiesWithInvalidNameFails() { // --- Arrange var settings = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("X", "12"), new PropertySettings("Dummy", "23") } ); // --- Act object myPoint = new MyPoint(); ConfigurationHelper.InjectProperties(ref myPoint, settings); }
/// <summary> /// Initializes a new instance of the PropertyParser class. /// </summary> /// <param name="selectedObject"></param> public PropertyParser(object[] selectedObjects, Attribute[] attributeFilter, PropertyNodeFactory nodeFactory, List<string> ignoredProperties, List<string> ignoredCategories, IPropertyGridLocalizer localizer, PropertySettingsCollection propertySettings) { _SelectedObjects = selectedObjects; _AttributeFilter = attributeFilter; _PropertyNodeFactory = nodeFactory; _IgnoredProperties = ignoredProperties; _IgnoredCategories = ignoredCategories; _Localizer = localizer; _PropertySettings = propertySettings; }
/// <summary> /// Instantiates an object and sets its properties as provided. /// </summary> /// <param name="type">Type to instantiate</param> /// <param name="constructorParams">Collection of construction parameters</param> /// <param name="properties">Collection of properties to set up</param> /// <returns>The newly instantiated object</returns> public static object CreateInstance(Type type, ConstructorParameterSettingsCollection constructorParams, PropertySettingsCollection properties) { // --- Create the constructor parameter array var parameters = new object[constructorParams.Count]; for (var i = 0; i < constructorParams.Count; i++) { var converter = TypeDescriptor.GetConverter(constructorParams[i].Type); parameters[i] = converter.ConvertFromString(constructorParams[i].Value); } // --- Instantiate the object var tempInstance = Activator.CreateInstance(type, parameters); InjectProperties(ref tempInstance, properties); return tempInstance; }
public void ConstructorWorksWithXElement2() { // --- Act var collection1 = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings(new PropertySettings("Prop1", "2").WriteToXml("temp")), new PropertySettings(new PropertySettings("Prop2", "Hello").WriteToXml("temp")), }); var element1 = collection1.WriteToXml("Test"); var collection2 = new PropertySettingsCollection(element1); // --- Assert element1.Elements("Property").ShouldHaveCountOf(2); collection2.ShouldHaveCountOf(2); }
public void ConstructorWorksWithXElement2() { // --- Act var collection1 = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings(new PropertySettings("Prop1", "2").WriteToXml("temp")), new PropertySettings(new PropertySettings("Prop2", "Hello").WriteToXml("temp")), }); var element1 = collection1.WriteToXml("Test"); var collection2 = new PropertySettingsCollection(element1); // --- Assert element1.Elements("Property").ShouldHaveCountOf(2); collection2.ShouldHaveCountOf(2); }
public void ConstructorWorksWithNullRootName() { // --- Act var collection1 = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("Prop1", "2"), new PropertySettings("Prop2", "hello") }); var element1 = collection1.WriteToXml("Test"); var collection2 = new PropertySettingsCollection(); collection2.ReadFromXml(element1); // --- Assert element1.Elements("Property").ShouldHaveCountOf(2); collection2.ShouldHaveCountOf(2); }
/// <summary> /// Instantiates an object and sets its properties as provided. /// </summary> /// <param name="type">Type to instantiate</param> /// <param name="constructorParams">Collection of construction parameters</param> /// <param name="properties">Collection of properties to set up</param> /// <returns>The newly instantiated object</returns> public static object CreateInstance(Type type, ConstructorParameterSettingsCollection constructorParams, PropertySettingsCollection properties) { // --- Create the constructor parameter array var parameters = new object[constructorParams.Count]; for (var i = 0; i < constructorParams.Count; i++) { var converter = TypeDescriptor.GetConverter(constructorParams[i].Type); parameters[i] = converter.ConvertFromString(constructorParams[i].Value); } // --- Instantiate the object var tempInstance = Activator.CreateInstance(type, parameters); InjectProperties(ref tempInstance, properties); return(tempInstance); }
public void InjectPropertieswithEnumWorksAsExpected() { // --- Arrange var settings = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("Entry", EventLogEntryType.Error.ToString()), } ); // --- Act object myEnum = new MyEnum(); ConfigurationHelper.InjectProperties(ref myEnum, settings); // --- Assert var asEnum = (MyEnum)myEnum; asEnum.Entry.ShouldEqual(EventLogEntryType.Error); }
/// <summary> /// Initializes a new instance of the PropertyParser class. /// </summary> /// <param name="selectedObject"></param> public PropertyParser( ITypeDescriptorContext context, object selectedObject, Attribute[] attributeFilter, PropertyNodeFactory nodeFactory, List<string> ignoredProperties, List<string> ignoredCategories, IPropertyGridLocalizer localizer, PropertySettingsCollection propertySettings) { _TypeDescriptorContext = context; _SelectedObject = selectedObject; _AttributeFilter = attributeFilter; _PropertyNodeFactory = nodeFactory; _IgnoredProperties = ignoredProperties; _IgnoredCategories = ignoredCategories; _Localizer = localizer; _PropertySettings = propertySettings; }
public void ConstructorWorksWithNullRootName() { // --- Act var collection1 = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("Prop1", "2"), new PropertySettings("Prop2", "hello") }); var element1 = collection1.WriteToXml("Test"); var collection2 = new PropertySettingsCollection(); collection2.ReadFromXml(element1); // --- Assert element1.Elements("Property").ShouldHaveCountOf(2); collection2.ShouldHaveCountOf(2); }
public void InjectPropertieswithEnumWorksAsExpected() { // --- Arrange var settings = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("Entry", EventLogEntryType.Error.ToString()), } ); // --- Act object myEnum = new MyEnum(); ConfigurationHelper.InjectProperties(ref myEnum, settings); // --- Assert var asEnum = (MyEnum)myEnum; asEnum.Entry.ShouldEqual(EventLogEntryType.Error); }
public void CreateInstanceWithPropertiesWorksAsExpected() { // --- Arrange var settings = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("X", "12"), new PropertySettings("Y", "23") } ); // --- Act var myPoint = ConfigurationHelper.CreateInstance(typeof (MyPoint), settings) as MyPoint; // --- Assert myPoint.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException myPoint.X.ShouldEqual(12); // ReSharper restore PossibleNullReferenceException myPoint.Y.ShouldEqual(23); }
public void ContructorWithCollectionInitializerWorks() { // --- Act var collection = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("Prop1", "2"), new PropertySettings("Prop2", "hello") }); // --- Assert collection.ShouldHaveCountOf(2); collection[0].Name.ShouldEqual("Prop1"); collection[0].Value.ShouldEqual("2"); collection[1].Name.ShouldEqual("Prop2"); collection[1].Value.ShouldEqual("hello"); collection.Count.ShouldEqual(2); collection["Prop1"].Value.ShouldEqual("2"); collection["Prop2"].Value.ShouldEqual("hello"); }
public void ContructorWithCollectionInitializerWorks() { // --- Act var collection = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("Prop1", "2"), new PropertySettings("Prop2", "hello") }); // --- Assert collection.ShouldHaveCountOf(2); collection[0].Name.ShouldEqual("Prop1"); collection[0].Value.ShouldEqual("2"); collection[1].Name.ShouldEqual("Prop2"); collection[1].Value.ShouldEqual("hello"); collection.Count.ShouldEqual(2); collection["Prop1"].Value.ShouldEqual("2"); collection["Prop2"].Value.ShouldEqual("hello"); }
public void CreateInstanceWithPropertiesWorksAsExpected() { // --- Arrange var settings = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("X", "12"), new PropertySettings("Y", "23") } ); // --- Act var myPoint = ConfigurationHelper.CreateInstance(typeof(MyPoint), settings) as MyPoint; // --- Assert myPoint.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException myPoint.X.ShouldEqual(12); // ReSharper restore PossibleNullReferenceException myPoint.Y.ShouldEqual(23); }
/// <summary> /// Initializes a new instance of the AdvPropertyGrid class. /// </summary> public AdvPropertyGrid() { _SystemText = new AdvPropertyGridLocalization(); _SystemText.PropertyChanged += new PropertyChangedEventHandler(SystemTextPropertyChanged); _Appearance = new AdvPropertyGridAppearance(); _Appearance.PropertyChanged += new PropertyChangedEventHandler(AppearancePropertyChanged); _PropertySettings = new PropertySettingsCollection(this); _Toolbar = CreateToolbar(); _PropertyTree = CreatePropertyTree(); _SuperTooltip = CreateSuperTooltip(); _ExpandableSplitter = CreateExpandableSplitter(); _HelpPanel = CreateHelpPanel(); _ExpandableSplitter.ExpandableControl = _HelpPanel; this.Controls.Add(_PropertyTree); this.Controls.Add(_Toolbar); this.Controls.Add(_ExpandableSplitter); this.Controls.Add(_HelpPanel); _ExpandableSplitter.Visible = false; _HelpPanel.Visible = false; }
/// <summary> /// Creates a new instance of this class and initializes it from the specified XML element. /// </summary> /// <param name="element">XML element to initialize this instance from.</param> public AppConfigurationSettings(XElement element) { ConstructorParameters = new ConstructorParameterSettingsCollection(); Properties = new PropertySettingsCollection(); ReadFromXml(element); }
public void InjectPropertiesWithInvalidNameFails() { // --- Arrange var settings = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("X", "12"), new PropertySettings("Dummy", "23") } ); // --- Act object myPoint = new MyPoint(); ConfigurationHelper.InjectProperties(ref myPoint, settings); }
public PropertyNode CreatePropertyNode(PropertyDescriptor item, object targetComponent, IPropertyGridLocalizer localizer, PropertySettingsCollection propertySettings, bool isMultiObject) { PropertySettings settings = propertySettings[item, item.Name]; return CreatePropertyNode(item, targetComponent, localizer, settings, isMultiObject); }
public void ReadAndWriteWorksAsExpected() { // --- Arrange const string PROVIDER_KEY = "queue"; var defaultProps = new TypedPropertySettingsCollection( new List <TypedPropertySettings> { new TypedPropertySettings("prop1", "23", typeof(int)), new TypedPropertySettings("prop2", "24", typeof(int)), new TypedPropertySettings("prop3", "23", typeof(string)), }); var defaultContext = new TaskExecutionContextSettings(PROVIDER_KEY, defaultProps); var props = new TypedPropertySettingsCollection( new List <TypedPropertySettings> { new TypedPropertySettings("prop1", "99", typeof(int)), new TypedPropertySettings("prop2", "100", typeof(int)), new TypedPropertySettings("prop3", "101", typeof(string)), }); var optionalContext = new TaskExecutionContextSettings(PROVIDER_KEY, props); var taskProps = new PropertySettingsCollection( new List <PropertySettings> { new PropertySettings("prop1", "1000"), new PropertySettings("prop2", "1001"), }); var proc1 = new TaskProcessorSettings("Proc1", TaskProcessorSettings.SCHEDULED_TYPE, typeof(TaskBase), 3, optionalContext, taskProps); var proc2 = new TaskProcessorSettings("Proc2", TaskProcessorSettings.QUEUED_TYPE, typeof(TaskBase), 2, null, taskProps); var proc3 = new TaskProcessorSettings("Proc3", TaskProcessorSettings.DOUBLE_QUEUED, typeof(TaskBase), 1, null); var host = new BackgroundTaskHostSettings(defaultContext, new List <TaskProcessorSettings> { proc1, proc2, proc3 }); // --- Act var element = host.WriteToXml("BackgroundTaskHost"); Console.WriteLine(element); var config = new BackgroundTaskHostSettings(element); // --- Assert config.DefaultContext.ShouldNotBeNull(); config.DefaultContext.ProviderKey.ShouldEqual(PROVIDER_KEY); config.DefaultContext.Properties.ShouldHaveCountOf(3); config.DefaultContext.Properties["prop1"].Type.ShouldEqual(typeof(int)); config.DefaultContext.Properties["prop1"].Value.ShouldEqual("23"); config.DefaultContext.Properties["prop2"].Type.ShouldEqual(typeof(int)); config.DefaultContext.Properties["prop2"].Value.ShouldEqual("24"); config.DefaultContext.Properties["prop3"].Type.ShouldEqual(typeof(string)); config.DefaultContext.Properties["prop3"].Value.ShouldEqual("23"); var taskProcessors = config.GetTaskProcessors(); taskProcessors.ShouldHaveCountOf(3); taskProcessors[0].Name.ShouldEqual("Proc1"); taskProcessors[0].ProcessorType.ShouldEqual(TaskProcessorSettings.SCHEDULED_TYPE); taskProcessors[0].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[0].InstanceCount.ShouldEqual(3); taskProcessors[0].Context.ShouldNotBeNull(); taskProcessors[0].Context.Properties.ShouldHaveCountOf(3); taskProcessors[0].Context.Properties["prop1"].Type.ShouldEqual(typeof(int)); taskProcessors[0].Context.Properties["prop1"].Value.ShouldEqual("99"); taskProcessors[0].Context.Properties["prop2"].Type.ShouldEqual(typeof(int)); taskProcessors[0].Context.Properties["prop2"].Value.ShouldEqual("100"); taskProcessors[0].Context.Properties["prop3"].Type.ShouldEqual(typeof(string)); taskProcessors[0].Context.Properties["prop3"].Value.ShouldEqual("101"); taskProcessors[0].Properties.ShouldHaveCountOf(2); taskProcessors[0].Properties["prop1"].Value.ShouldEqual("1000"); taskProcessors[0].Properties["prop2"].Value.ShouldEqual("1001"); taskProcessors[1].Name.ShouldEqual("Proc2"); taskProcessors[1].ProcessorType.ShouldEqual(TaskProcessorSettings.QUEUED_TYPE); taskProcessors[1].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[1].InstanceCount.ShouldEqual(2); taskProcessors[1].Context.ShouldBeNull(); taskProcessors[1].Properties.ShouldHaveCountOf(2); taskProcessors[1].Properties["prop1"].Value.ShouldEqual("1000"); taskProcessors[1].Properties["prop2"].Value.ShouldEqual("1001"); taskProcessors[2].Name.ShouldEqual("Proc3"); taskProcessors[2].ProcessorType.ShouldEqual(TaskProcessorSettings.DOUBLE_QUEUED); taskProcessors[2].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[2].InstanceCount.ShouldEqual(1); taskProcessors[2].Context.ShouldBeNull(); taskProcessors[2].Properties.ShouldHaveCountOf(0); }
/// <summary> /// Initializes this instance /// </summary> private void Init() { ConstructorParameters = new UnnamedPropertySettingsCollection(PARAM); Properties = new PropertySettingsCollection(); }
public void ReadAndWriteWorksAsExpected() { // --- Arrange const string PROVIDER_KEY = "queue"; var defaultProps = new TypedPropertySettingsCollection( new List<TypedPropertySettings> { new TypedPropertySettings("prop1", "23", typeof (int)), new TypedPropertySettings("prop2", "24", typeof (int)), new TypedPropertySettings("prop3", "23", typeof (string)), }); var defaultContext = new TaskExecutionContextSettings(PROVIDER_KEY, defaultProps); var props = new TypedPropertySettingsCollection( new List<TypedPropertySettings> { new TypedPropertySettings("prop1", "99", typeof (int)), new TypedPropertySettings("prop2", "100", typeof (int)), new TypedPropertySettings("prop3", "101", typeof (string)), }); var optionalContext = new TaskExecutionContextSettings(PROVIDER_KEY, props); var taskProps = new PropertySettingsCollection( new List<PropertySettings> { new PropertySettings("prop1", "1000"), new PropertySettings("prop2", "1001"), }); var proc1 = new TaskProcessorSettings("Proc1", TaskProcessorSettings.SCHEDULED_TYPE, typeof(TaskBase), 3, optionalContext, taskProps); var proc2 = new TaskProcessorSettings("Proc2", TaskProcessorSettings.QUEUED_TYPE, typeof(TaskBase), 2, null, taskProps); var proc3 = new TaskProcessorSettings("Proc3", TaskProcessorSettings.DOUBLE_QUEUED, typeof(TaskBase), 1, null); var host = new BackgroundTaskHostSettings(defaultContext, new List<TaskProcessorSettings> { proc1, proc2, proc3 }); // --- Act var element = host.WriteToXml("BackgroundTaskHost"); Console.WriteLine(element); var config = new BackgroundTaskHostSettings(element); // --- Assert config.DefaultContext.ShouldNotBeNull(); config.DefaultContext.ProviderKey.ShouldEqual(PROVIDER_KEY); config.DefaultContext.Properties.ShouldHaveCountOf(3); config.DefaultContext.Properties["prop1"].Type.ShouldEqual(typeof(int)); config.DefaultContext.Properties["prop1"].Value.ShouldEqual("23"); config.DefaultContext.Properties["prop2"].Type.ShouldEqual(typeof(int)); config.DefaultContext.Properties["prop2"].Value.ShouldEqual("24"); config.DefaultContext.Properties["prop3"].Type.ShouldEqual(typeof(string)); config.DefaultContext.Properties["prop3"].Value.ShouldEqual("23"); var taskProcessors = config.GetTaskProcessors(); taskProcessors.ShouldHaveCountOf(3); taskProcessors[0].Name.ShouldEqual("Proc1"); taskProcessors[0].ProcessorType.ShouldEqual(TaskProcessorSettings.SCHEDULED_TYPE); taskProcessors[0].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[0].InstanceCount.ShouldEqual(3); taskProcessors[0].Context.ShouldNotBeNull(); taskProcessors[0].Context.Properties.ShouldHaveCountOf(3); taskProcessors[0].Context.Properties["prop1"].Type.ShouldEqual(typeof(int)); taskProcessors[0].Context.Properties["prop1"].Value.ShouldEqual("99"); taskProcessors[0].Context.Properties["prop2"].Type.ShouldEqual(typeof(int)); taskProcessors[0].Context.Properties["prop2"].Value.ShouldEqual("100"); taskProcessors[0].Context.Properties["prop3"].Type.ShouldEqual(typeof(string)); taskProcessors[0].Context.Properties["prop3"].Value.ShouldEqual("101"); taskProcessors[0].Properties.ShouldHaveCountOf(2); taskProcessors[0].Properties["prop1"].Value.ShouldEqual("1000"); taskProcessors[0].Properties["prop2"].Value.ShouldEqual("1001"); taskProcessors[1].Name.ShouldEqual("Proc2"); taskProcessors[1].ProcessorType.ShouldEqual(TaskProcessorSettings.QUEUED_TYPE); taskProcessors[1].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[1].InstanceCount.ShouldEqual(2); taskProcessors[1].Context.ShouldBeNull(); taskProcessors[1].Properties.ShouldHaveCountOf(2); taskProcessors[1].Properties["prop1"].Value.ShouldEqual("1000"); taskProcessors[1].Properties["prop2"].Value.ShouldEqual("1001"); taskProcessors[2].Name.ShouldEqual("Proc3"); taskProcessors[2].ProcessorType.ShouldEqual(TaskProcessorSettings.DOUBLE_QUEUED); taskProcessors[2].TaskType.ShouldEqual(typeof(TaskBase)); taskProcessors[2].InstanceCount.ShouldEqual(1); taskProcessors[2].Context.ShouldBeNull(); taskProcessors[2].Properties.ShouldHaveCountOf(0); }