public void Properties_GetAfterAddingChild_ReturnsNonEmpty()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "name", "value");
            Assert.NotEmpty(service.Options.Properties);
        }
Esempio n. 2
0
        public void DesignerOptionConverterGetProperties_ValidValue_ReturnsExpected()
        {
            TypeConverter converter = TypeDescriptor.GetConverter(typeof(DesignerOptionService.DesignerOptionCollection));
            var           service   = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", new TestClass());
            service.DoCreateOptionCollection(options, "Name", null);

            PropertyDescriptorCollection properties = converter.GetProperties(options);

            Assert.Equal(2, properties.Count);

            PropertyDescriptor optionsDescriptor = properties[0];

            Assert.Equal(typeof(DesignerOptionService.DesignerOptionCollection), optionsDescriptor.ComponentType);
            Assert.Equal(typeof(DesignerOptionService.DesignerOptionCollection), optionsDescriptor.PropertyType);
            Assert.Same(options[0], optionsDescriptor.GetValue(null));

            Assert.True(optionsDescriptor.IsReadOnly);
            Assert.False(optionsDescriptor.CanResetValue(null));
            Assert.False(optionsDescriptor.ShouldSerializeValue(null));

            optionsDescriptor.ResetValue(null);
            optionsDescriptor.SetValue(null, null);

            PropertyDescriptor propertyDescriptor = properties[1];

            Assert.Same(options.Properties[0], propertyDescriptor);
        }
Esempio n. 3
0
        public void Indexer_InvalidName_ReturnsNull(string name)
        {
            var service = new TestDesignerOptionService();

            service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Null(service.Options[name]);
        }
Esempio n. 4
0
        public void Indexer_ValidName_ReturnsExpected(string name)
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Same(options, service.Options[name]);
        }
Esempio n. 5
0
        public void Contains_NoSuchOptions_ReturnsFalse()
        {
            var   service = new TestDesignerOptionService();
            IList options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.False(options.Contains(service.Options));
            Assert.False(options.Contains(null));
        }
Esempio n. 6
0
        public void ShowDialog_NonNestedValue_Success()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.True(options.ShowDialog());
            Assert.Equal("Value", service.ShowDialogValue);
        }
Esempio n. 7
0
        public void Indexer_InvalidIndex_ThrowsIndexOutOfRangeException(int index)
        {
            var service = new TestDesignerOptionService();

            service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Throws <IndexOutOfRangeException>(() => service.Options[index]);
            Assert.Throws <IndexOutOfRangeException>(() => ((IList)service.Options)[index]);
        }
Esempio n. 8
0
        public void Indexer_ValidIndex_ReturnsExpected()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Same(options, service.Options[0]);
            Assert.Same(options, ((IList)service.Options)[0]);
        }
Esempio n. 9
0
        public void Contains_ValueExists_ReturnsExpected()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Equal(0, service.Options.IndexOf(options));
            Assert.Equal(0, ((IList)service.Options).IndexOf(options));
        }
Esempio n. 10
0
        public void ShowDialog_NullValue_Success()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", null);
            service.DoCreateOptionCollection(options, "Name", null);

            Assert.False(options.ShowDialog());
            Assert.Equal("Default", service.ShowDialogValue);
        }
Esempio n. 11
0
        public void IndexOf_NoSuchOptions_ReturnsNegativeOne()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", "Value");

            Assert.Equal(-1, service.Options.IndexOf(service.Options));
            Assert.Equal(-1, service.Options.IndexOf(null));
            Assert.Equal(-1, ((IList)service.Options).IndexOf(service.Options));
        }
Esempio n. 12
0
        public void IList_Modification_ThrowsNotSupportedException()
        {
            var   service = new TestDesignerOptionService();
            IList options = service.Options;

            Assert.Throws <NotSupportedException>(() => options[0] = null);
            Assert.Throws <NotSupportedException>(() => options.Add(null));
            Assert.Throws <NotSupportedException>(() => options.Insert(0, null));
            Assert.Throws <NotSupportedException>(() => options.Remove(null));
            Assert.Throws <NotSupportedException>(() => options.RemoveAt(0));
            Assert.Throws <NotSupportedException>(() => options.Clear());
        }
Esempio n. 13
0
        public void Options_Get_ReturnsExpected()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.Options;
            Assert.Same(options, service.Options);

            Assert.Equal(0, options.Count);
            Assert.Empty(options.Properties);
            Assert.Same(options.Properties, options.Properties);
            Assert.Null(options.Parent);
        }
Esempio n. 14
0
        public void Options_IListProperties_ReturnsExpected()
        {
            var   service = new TestDesignerOptionService();
            IList options = service.Options;

            Assert.Same(options, service.Options);

            Assert.Equal(0, options.Count);
            Assert.True(options.IsFixedSize);
            Assert.True(options.IsReadOnly);
            Assert.False(options.IsSynchronized);
            Assert.Same(options, options.SyncRoot);
        }
Esempio n. 15
0
        public void GetOptionValue_NotNested_ReturnsExpected()
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            service.DoCreateOptionCollection(service.Options, "Name", value);

            Assert.Equal("StringValue", iService.GetOptionValue("Name", "Value"));
        }
Esempio n. 16
0
        public void CopyTo_ValidRange_Success()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options1 = service.DoCreateOptionCollection(service.Options, "name", "value");
            DesignerOptionService.DesignerOptionCollection options2 = service.DoCreateOptionCollection(service.Options, "name", "value");

            var destination = new object[3];

            service.Options.CopyTo(destination, 1);

            Assert.Equal(new object[] { null, options1, options2 }, destination);
        }
Esempio n. 17
0
        public void SetOptionValue_NoSuchValue_Nop(string pageName, string valueName)
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", null);
            service.DoCreateOptionCollection(options, "SubName", value);

            iService.SetOptionValue(pageName, valueName, "value");
        }
Esempio n. 18
0
        public void SetOptionValue_Nested_ReturnsExpected()
        {
            var value = new TestClass {
                Value = "StringValue"
            };

            var service = new TestDesignerOptionService();
            IDesignerOptionService iService = service;

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", null);
            service.DoCreateOptionCollection(options, "SubName", value);

            iService.SetOptionValue("Name\\SubName", "Value", "abc");
            Assert.Equal("abc", value.Value);
        }
Esempio n. 19
0
        public void CreateOptionCollection_CreateMultipleTimes_ReturnsExpected()
        {
            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options1 = service.DoCreateOptionCollection(service.Options, "name", "value");
            Assert.Equal(0, options1.Count);
            Assert.NotEmpty(options1.Properties);
            Assert.Same(options1.Properties, options1.Properties);
            Assert.Same(service.Options, options1.Parent);

            DesignerOptionService.DesignerOptionCollection options2 = service.DoCreateOptionCollection(service.Options, "name", "value");
            Assert.Equal(2, service.Options.Count);
            Assert.Equal(0, options2.Count);
            Assert.NotEmpty(options2.Properties);
            Assert.Same(options2.Properties, options2.Properties);
            Assert.Same(service.Options, options2.Parent);

            Assert.Equal(new DesignerOptionService.DesignerOptionCollection[] { options1, options2 }, service.Options.Cast <object>());
        }
Esempio n. 20
0
        public void Properties_PropertyDescriptorAttributes_Success()
        {
            var value = new TestClass {
                Value = "Value"
            };

            var service = new TestDesignerOptionService();

            DesignerOptionService.DesignerOptionCollection options = service.DoCreateOptionCollection(service.Options, "Name", value);
            PropertyDescriptor propertyDescriptor = Assert.IsAssignableFrom <PropertyDescriptor>(Assert.Single(options.Properties));
            PropertyDescriptor actualProperty     = Assert.IsAssignableFrom <PropertyDescriptor>(Assert.Single(TypeDescriptor.GetProperties(value)));

            Assert.Equal(actualProperty.Attributes, propertyDescriptor.Attributes);
            Assert.Equal(actualProperty.ComponentType, propertyDescriptor.ComponentType);
            Assert.Equal(actualProperty.IsReadOnly, propertyDescriptor.IsReadOnly);
            Assert.Equal(actualProperty.PropertyType, propertyDescriptor.PropertyType);
            Assert.Equal(actualProperty.CanResetValue(value), propertyDescriptor.CanResetValue("InvalidComponent"));
            Assert.Equal(actualProperty.ShouldSerializeValue(value), propertyDescriptor.ShouldSerializeValue("InvalidComponent"));

            propertyDescriptor.ResetValue(null);
            Assert.Equal("Value", value.Value);
        }
Esempio n. 21
0
        public void ShowDialog_Invoke_ReturnsFalseByDefault()
        {
            var service = new TestDesignerOptionService();

            Assert.False(service.DoShowDialog(null, null));
        }
Esempio n. 22
0
        public void CreateOptionCollection_EmptyName_ThrowsArgumentException()
        {
            var service = new TestDesignerOptionService();

            AssertExtensions.Throws <ArgumentException>("name.Length", () => service.DoCreateOptionCollection(service.Options, string.Empty, "value"));
        }
Esempio n. 23
0
        public void SetOptionValue_NullValueName_ThrowsArgumentNullException()
        {
            IDesignerOptionService service = new TestDesignerOptionService();

            AssertExtensions.Throws <ArgumentNullException>("valueName", () => service.SetOptionValue("PageName", null, "value"));
        }
Esempio n. 24
0
        public void CreateOptionCollection_NullName_ThrowsArgumentNullException()
        {
            var service = new TestDesignerOptionService();

            AssertExtensions.Throws <ArgumentNullException>("name", () => service.DoCreateOptionCollection(service.Options, null, "value"));
        }