public void ExcludeNonPublicTypes() { TypeSelectorIncludeFlags flags = TypeSelectorIncludeFlags.Default; TypeSelector selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView); bool valid = selector.IsTypeValid(typeof(NonPublicClass)); Assert.IsFalse(valid); }
public void ExcludeAbstractTypesTest() { TypeSelectorIncludeFlags flags = TypeSelectorIncludeFlags.Default; TypeSelector selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView); bool valid = selector.IsTypeValid(typeof(Stream)); Assert.IsFalse(valid); }
public void ExcludeBaseTypeTest() { TypeSelectorIncludeFlags flags = TypeSelectorIncludeFlags.Default; TypeSelector selector = new TypeSelector(null, typeof(Exception), flags, treeView); bool valid = selector.IsTypeValid(typeof(Exception)); Assert.IsFalse(valid); }
public void ExcludeAllInterfacesTest() { TypeSelectorIncludeFlags flags = TypeSelectorIncludeFlags.Default; TypeSelector selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView); bool valid = selector.IsTypeValid(typeof(IComparable)); Assert.IsFalse(valid); }
public void FlagsTest() { TypeSelectorIncludeFlags flags = TypeSelectorIncludeFlags.AbstractTypes | TypeSelectorIncludeFlags.Interfaces | TypeSelectorIncludeFlags.BaseType; TypeSelector selector = new TypeSelector(null, typeof(ITest), flags, treeView); bool valid = selector.IsTypeValid(typeof(AbstractTest)); Assert.IsTrue(valid); valid = selector.IsTypeValid(typeof(ITest)); Assert.IsTrue(valid); }
public void When_selecting_global_types_from_global_namespace_it_should_succeed() { // Arrange TypeSelector types = new[] { typeof(ClassInGlobalNamespace) }.Types(); // Act TypeSelector filteredTypes = types.ThatAreUnderNamespace(null); // Assert filteredTypes.As <IEnumerable <Type> >().Should().ContainSingle(); }
public void When_a_type_is_not_in_the_unexpected_parent_namespace_it_should_not_throw() { // Arrange var types = new TypeSelector(typeof(ClassInInnerDummyNamespace)); // Act Action act = () => types.Should().NotBeInNamespace(nameof(DummyNamespace)); // Assert act.Should().NotThrow(); }
public void When_all_types_are_not_sealed_it_succeeds() { // Arrange var types = new TypeSelector(new[] { typeof(Abstract) }); // Act / Assert types.Should().NotBeSealed(); }
public void When_a_type_is_in_the_expected_global_namespace_it_should_not_throw() { // Arrange var types = new TypeSelector(typeof(ClassInGlobalNamespace)); // Act Action act = () => types.Should().BeInNamespace(null); // Assert act.Should().NotThrow(); }
public void When_deselecting_a_prefix_of_a_namespace_it_should_not_match() { // Arrange TypeSelector types = new[] { typeof(SomeBaseClass) }.Types(); // Act TypeSelector filteredTypes = types.ThatAreNotUnderNamespace("Internal.Main.Tes"); // Assert filteredTypes.As <IEnumerable <Type> >().Should().ContainSingle(); }
public void When_selecting_local_types_not_from_global_namespace_it_should_succeed() { // Arrange TypeSelector types = new[] { typeof(SomeBaseClass) }.Types(); // Act TypeSelector filteredTypes = types.ThatAreNotUnderNamespace(null); // Assert filteredTypes.As <IEnumerable <Type> >().Should().BeEmpty(); }
public void When_a_selection_of_types_do_not_inherit_unexpected_attribute_with_the_expected_properties_it_succeeds() { // Arrange var types = new TypeSelector(typeof(ClassWithoutAttribute)); // Act Action act = () => types.Should() .NotBeDecoratedWithOrInherit <DummyClassAttribute>(a => (a.Name == "Expected") && a.IsEnabled); // Assert act.Should().NotThrow(); }
public void When_a_type_is_under_the_expected_nested_namespace_it_should_not_throw() { // Arrange var types = new TypeSelector(typeof(ClassInInnerDummyNamespace)); // Act Action act = () => types.Should().BeUnderNamespace($"{nameof(DummyNamespace)}.{nameof(DummyNamespace.InnerDummyNamespace)}"); // Assert act.Should().NotThrow(); }
public void When_type_selector_is_null_then_should_should_throw() { // Arrange TypeSelector propertyInfoSelector = null; // Act Action act = () => propertyInfoSelector.Should(); // Assert act.Should().ThrowExactly <ArgumentNullException>() .WithParameterName("typeSelector"); }
public void FlagsTest() { TypeSelectorIncludes flags = TypeSelectorIncludes.AbstractTypes | TypeSelectorIncludes.Interfaces | TypeSelectorIncludes.BaseType; TypeSelector selector = new TypeSelector(null, typeof(ITest), flags, treeView); bool valid = selector.IsTypeValid(typeof(AbstractTest)); Assert.IsTrue(valid); valid = selector.IsTypeValid(typeof(ITest)); Assert.IsTrue(valid); }
public void When_selecting_types_that_derive_from_a_specific_generic_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeGenericBaseClass).GetTypeInfo().Assembly; // Act TypeSelector types = AllTypes.From(assembly).ThatDeriveFrom <SomeGenericBaseClass <int> >(); // Assert types.ToArray().Should().ContainSingle() .Which.Should().Be(typeof(ClassDerivedFromSomeGenericBaseClass)); }
private void UpdateTypeList() { var typeList = from type in this.TypeOptions orderby type.Name select new { HashCode = type.FullName.GetHashCode(), Label = type.GetShortLabel() }; TypeSelector.DataSource = typeList; TypeSelector.DataTextField = "Label"; TypeSelector.DataValueField = "HashCode"; TypeSelector.DataBind(); }
public void When_type_selector_is_created_with_a_null_type_list_it_should_throw() { // Arrange TypeSelector propertyInfoSelector; // Act Action act = () => propertyInfoSelector = new TypeSelector((Type[])null); // Assert act.Should().ThrowExactly <ArgumentNullException>() .WithParameterName("types"); }
public void When_injecting_a_null_predicate_into_TypeSelector_NotBeDecoratedWithOrInherit_it_should_throw() { // Arrange var types = new TypeSelector(typeof(ClassWithAttribute)); // Act Action act = () => types.Should() .NotBeDecoratedWithOrInherit <DummyClassAttribute>(isMatchingAttributePredicate: null); // Assert act.Should().ThrowExactly <ArgumentNullException>() .WithParameterName("isMatchingAttributePredicate"); }
private void DrawTopBar() { Rect rect = SirenixEditorGUI.BeginHorizontalToolbar(); { var iconRect = rect.AlignLeft(SerializationInfoMenuItem.IconSize).AlignMiddle(SerializationInfoMenuItem.IconSize); iconRect.x += SerializationInfoMenuItem.IconSpacing * 2; GUI.color = (this.backendFlags & SerializationBackendFlags.Odin) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f); GUI.DrawTexture(iconRect.Padding(2), EditorIcons.OdinInspectorLogo, ScaleMode.ScaleToFit); iconRect.x += SerializationInfoMenuItem.IconSize + SerializationInfoMenuItem.IconSpacing * 2; GUI.color = (this.backendFlags & SerializationBackendFlags.Unity) != 0 ? Color.white : new Color(1f, 1f, 1f, 0.2f); GUI.DrawTexture(iconRect.Padding(2), EditorIcons.UnityLogo, ScaleMode.ScaleToFit); GUI.color = Color.white; var typeName = " " + (this.targetType == null ? "Select Type" : this.targetType.GetNiceName().SplitPascalCase()) + " "; GUILayout.Space(iconRect.xMax + 3); bool selectB = SirenixEditorGUI.ToolbarButton(new GUIContent(typeName)); GUILayout.FlexibleSpace(); bool selectA = SirenixEditorGUI.ToolbarButton(EditorIcons.TriangleDown); if (selectA || selectB) { var btnRect = GUIHelper.GetCurrentLayoutRect().HorizontalPadding(20).AlignTop(20); btnRect = btnRect.AlignRight(400); var source = AssemblyUtilities.GetTypes(AssemblyTypeFlags.CustomTypes) .Where(x => !x.IsAbstract && x.IsClass && x.InheritsFrom <UnityEngine.Object>()) .Where(x => !x.Assembly.FullName.StartsWith("Sirenix")) .OrderBy(x => x.Assembly.GetAssemblyTypeFlag()) .OrderBy(x => x.Assembly.GetAssemblyTypeFlag()) .ThenBy(x => x.Namespace) .ThenByDescending(x => x.Name); var p = new TypeSelector(source, false); p.SelectionChanged += (types) => { var t = types.FirstOrDefault(); if (t != null) { this.targetType = t; this.odinContext = this.targetType.IsDefined <ShowOdinSerializedPropertiesInInspectorAttribute>(true); this.CreateMenuTree(true); } }; p.SetSelection(this.targetType); p.ShowInPopup(300); } } SirenixEditorGUI.EndHorizontalToolbar(); }
public void When_a_type_is_under_the_unexpected_global_namespace_it_should_throw() { // Arrange var types = new TypeSelector(typeof(ClassInGlobalNamespace)); // Act Action act = () => types.Should().NotBeUnderNamespace(null); // Assert act.Should().Throw <XunitException>() .WithMessage( "Expected the namespaces of all types to not start with <null>" + ", but the namespaces of the following types start with it:*\"ClassInGlobalNamespace\"."); }
public void When_selecting_types_that_do_not_derive_from_a_specific_generic_class_it_should_return_the_correct_types() { // Arrange Assembly assembly = typeof(ClassDerivedFromSomeGenericBaseClass).GetTypeInfo().Assembly; // Act TypeSelector types = AllTypes.From(assembly) .ThatAreInNamespace("Internal.Main.Test") .ThatDoNotDeriveFrom <SomeGenericBaseClass <int> >(); // Assert types.ToArray().Should() .HaveCount(12); }
public void When_a_type_only_shares_a_prefix_with_the_expected_namespace_it_should_throw() { // Arrange var types = new TypeSelector(typeof(ClassInDummyNamespaceTwo)); // Act Action act = () => types.Should().BeUnderNamespace(nameof(DummyNamespace), "we want to test the failure {0}", "message"); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected the namespaces of all types to start with \"DummyNamespace\" *failure message*" + ", but the namespaces of the following types do not start with it:*\"*.ClassInDummyNamespaceTwo\"."); }
public void When_a_type_in_the_global_namespace_is_not_in_the_expected_namespace_it_should_throw() { // Arrange var types = new TypeSelector(typeof(ClassInGlobalNamespace)); // Act Action act = () => types.Should().BeInNamespace(nameof(DummyNamespace)); // Assert act.Should().Throw <XunitException>() .WithMessage( "Expected all types to be in namespace \"DummyNamespace\", but the following types " + "are in a different namespace:*\"ClassInGlobalNamespace\"."); }
public void InitEnumTypeSelector(Type baseType, string enumTypeVar) { this.enumTypeFieldName = enumTypeVar; if (enumTypeSelector == null) { enumTypeSelector = new TypeSelector(baseType); } else { enumTypeSelector.SetBaseType(baseType); } string enumTypeName = obj.GetFieldValue <string>(enumTypeVar); enumTypeSelector.SetSelected(TypeEx.GetType(enumTypeName)); }
public void When_asserting_a_selection_of_decorated_types_is_decorated_with_an_attribute_it_succeeds() { // Arrange var types = new TypeSelector(new[] { typeof(ClassWithAttribute) }); // Act Action act = () => types.Should().BeDecoratedWith <DummyClassAttribute>(); // Assert act.Should().NotThrow(); }
public void When_a_type_is_under_the_unexpected_nested_namespace_it_should_throw() { // Arrange var types = new TypeSelector(typeof(ClassInInnerDummyNamespace)); // Act Action act = () => types.Should().NotBeUnderNamespace($"{nameof(DummyNamespace)}.{nameof(DummyNamespace.InnerDummyNamespace)}"); // Assert act.Should().Throw <XunitException>() .WithMessage( "Expected the namespaces of all types to not start with \"DummyNamespace.InnerDummyNamespace\"" + ", but the namespaces of the following types start with it:*\"*.ClassInInnerDummyNamespace\"."); }
public static object FromRawBody(this byte[] body, out string message, TypeSelector typeSelector = null) { if (typeSelector == null) { typeSelector = DefaultTypeSelector; } var typeNameSize = BitConverter.ToInt16(body, 0); var typeName = Encoding.UTF8.GetString(body, 2, typeNameSize); message = Encoding.UTF8.GetString(body, 2 + typeNameSize, body.Length - 2 - typeNameSize); var(_, type) = typeSelector(typeName); var input = JsonConvert.DeserializeObject(message, type, Settings); return(input); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSelectCodeDomCompiler_Click(object sender, System.EventArgs e) { using (new LengthyOperation(this)) { TypeSelector selector = new TypeSelector(Resources.TEXT_SELCOMPILER_TITLE, Resources.TEXT_SELCOMPILER_DESC, typeof(Compiler)); selector.SelectFileEnabled = false; if (selector.ShowDialog() == DialogResult.OK) { txtCodeDomCompilerType.Text = selector.SelectedText; } } }
public void When_using_the_single_type_ctor_of_TypeSelector_it_should_contain_that_singe_type() { // Arrange Type type = typeof(ClassWithSomeAttribute); // Act var typeSelector = new TypeSelector(type); // Assert typeSelector .ToArray() .Should() .ContainSingle() .Which.Should().Be(type); }
public void When_asserting_a_selection_of_non_decorated_types_does_not_inherit_an_attribute_it_succeeds() { // Arrange var types = new TypeSelector(new[] { typeof(ClassWithoutAttribute), typeof(OtherClassWithoutAttribute) }); // Act Action act = () => types.Should().NotBeDecoratedWithOrInherit <DummyClassAttribute>(); // Assert act.Should().NotThrow(); }
public void When_a_type_is_under_the_expected_global_namespace_it_should_not_throw() { // Arrange var types = new TypeSelector(new[] { typeof(ClassInDummyNamespace), typeof(ClassNotInDummyNamespace), typeof(OtherClassNotInDummyNamespace) }); // Act Action act = () => types.Should().BeUnderNamespace(null); // Assert act.Should().NotThrow(); }
public void When_any_type_is_sealed_it_fails_with_a_meaningful_message() { // Arrange var types = new TypeSelector(new[] { typeof(Abstract), typeof(Sealed) }); // Act Action act = () => types.Should().NotBeSealed("we want to test the failure {0}", "message"); // Assert act.Should().Throw <XunitException>() .WithMessage("Expected all types not to be sealed *failure message*, but the following types are:*\"*.Sealed\"."); }
/// <summary> /// 添加新项目 /// </summary> /// <param name="Path"></param> /// <param name="Name"></param> /// <param name="Arguments"></param> /// <returns></returns> public static Item AddItem(String Path, string Name = "", string Arguments = "", string tagName = "") { //构造类型选择器对象 TypeSelector ts = new TypeSelector(new InputInfo(Path, Name, Arguments, tagName)); //检查可用状态 if (ts.IsInitialized) { //构造itemdata类对象 ItemData itemdata = new ItemData(new ItemData.DataST(ts.TH.Name, ts.TH.Path, ts.TH.Icon, ts.TH.Arguments, ts.TH.SubPath)); //查找重复 bool itemexists = false; foreach (ItemData idd in listOfInnerData) { if (idd.ID == itemdata.ID) { itemexists = true; break; } } //重复则返回空引用并给出提示 if (itemexists) { TipPublic.ShowFixed(WindowMain, ItemExists); return(null); } //添加到Item后台数据集合 Manage.listOfInnerData.Add(itemdata); //构造UI对象 Item item = new Item(itemdata); //创建事件绑定 item.Click += Item_Click; //返回构造的前台数据对象 return(item); } else { return(null); } }
public void When_a_types_is_not_under_the_unexpected_namespace_it_should_not_throw() { // Arrange var types = new TypeSelector(new[] { typeof(ClassInDummyNamespace), typeof(ClassNotInDummyNamespace), typeof(OtherClassNotInDummyNamespace) }); // Act Action act = () => types.Should().NotBeUnderNamespace($"{nameof(DummyNamespace)}.{nameof(DummyNamespace.InnerDummyNamespace)}"); // Assert act.Should().NotThrow(); }
public void When_asserting_a_selection_of_decorated_types_is_decorated_with_an_attribute_it_should_succeed() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var types = new TypeSelector(new[] { typeof (ClassWithAttribute) }); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => types.Should().BeDecoratedWith<DummyClassAttribute>(); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldNotThrow(); }
public void SetUp() { treeView = new TreeView(); treeView.ImageList = new TypeSelectorUI().TypeImageList; selector = new TypeSelector(typeof(TestNode), typeof(BaseTestNode), treeView); }
public void IncludeNonPublicTypes() { TypeSelectorIncludes flags = TypeSelectorIncludes.NonpublicTypes; TypeSelector selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, treeView); bool valid = selector.IsTypeValid(typeof(NonPublicClass)); Assert.IsTrue(valid); }
public void IncludeNestedPublic() { TypeSelector selector = new TypeSelector(null, typeof(EventArgs), TypeSelectorIncludes.None, treeView); bool valid = selector.IsTypeValid(typeof(MockInnerTypeTest.InnerInner)); Assert.IsTrue(valid); }
public void IncludeBaseTypeTest() { TypeSelectorIncludes flags = TypeSelectorIncludes.BaseType; TypeSelector selector = new TypeSelector(null, typeof(Exception), flags, treeView); bool valid = selector.IsTypeValid(typeof(Exception)); Assert.IsTrue(valid); }
public void IncludeAbstractTypesTest() { TypeSelectorIncludes flags = TypeSelectorIncludes.AbstractTypes; TypeSelector selector = new TypeSelector(null, typeof(ITest), flags, treeView); bool valid = selector.IsTypeValid(typeof(AbstractTest)); Assert.IsTrue(valid); valid = selector.IsTypeValid(typeof(ITest2)); Assert.IsTrue(valid); }
public void ExcludeTypesWithoutConfigurationElementType() { TypeSelectorIncludes flags = TypeSelectorIncludes.None; TypeSelector selector = new TypeSelector(null, typeof(MarshalByRefObject), flags, typeof(TestConfigurationElement), treeView); bool valid = selector.IsTypeValid(typeof(ITest)); Assert.IsFalse(valid); }
public void When_asserting_a_selection_of_non_decorated_types_is_decorated_with_an_attribute_it_should_throw() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var types = new TypeSelector(new[] { typeof(ClassWithAttribute), typeof(ClassWithoutAttribute), typeof(OtherClassWithoutAttribute) }); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => types.Should().BeDecoratedWith<DummyClassAttribute>("because we do"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("Expected all types to be decorated with FluentAssertions.Specs.DummyClassAttribute" + " because we do, but the attribute was not found on the following types:\r\n" + "FluentAssertions.Specs.ClassWithoutAttribute\r\n" + "FluentAssertions.Specs.OtherClassWithoutAttribute"); }
public void When_asserting_a_selection_of_types_with_unexpected_attribute_property_it_should_throw() { //------------------------------------------------------------------------------------------------------------------- // Arrange //------------------------------------------------------------------------------------------------------------------- var types = new TypeSelector(new[] { typeof(ClassWithAttribute), typeof(ClassWithoutAttribute), typeof(OtherClassWithoutAttribute) }); //------------------------------------------------------------------------------------------------------------------- // Act //------------------------------------------------------------------------------------------------------------------- Action act = () => types.Should() .BeDecoratedWith<DummyClassAttribute>(a => ((a.Name == "Expected") && a.IsEnabled), "because we do"); //------------------------------------------------------------------------------------------------------------------- // Assert //------------------------------------------------------------------------------------------------------------------- act.ShouldThrow<AssertFailedException>() .WithMessage("Expected all types to be decorated with FluentAssertions.Specs.DummyClassAttribute" + " that matches ((a.Name == \"Expected\")*a.IsEnabled) because we do," + " but no matching attribute was found on the following types:\r\n" + "FluentAssertions.Specs.ClassWithoutAttribute\r\n" + "FluentAssertions.Specs.OtherClassWithoutAttribute"); }
public void IncludeTypesWithConfigurationElementType() { TypeSelectorIncludes flags = TypeSelectorIncludes.None; TypeSelector selector = new TypeSelector(null, typeof(ITest), flags, typeof(TestConfigurationElement), treeView); bool valid = selector.IsTypeValid(typeof(TestWithConfigurationType)); Assert.IsTrue(valid); }