public void Invoke_WithObject() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0]; var result = constructor.Invoke(new ConstructorTest(1), BindingFlags.Public, null, new object[] { 1234 }, CultureInfo.InvariantCulture); result.Should().BeNull(); }
public void IsDefined() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0]; constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), true).Should().BeTrue(); constructor.IsDefined(typeof(EditorAttribute), true).Should().BeTrue(); constructor.IsDefined(typeof(BrowsableAttribute), true).Should().BeFalse(); constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false).Should().BeTrue(); constructor.IsDefined(typeof(EditorAttribute), false).Should().BeTrue(); constructor.IsDefined(typeof(BrowsableAttribute), false).Should().BeFalse(); }
public void GetConstructors_NoMatchingVisibility() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorForNoMatchingVisibilityTest)); var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Static); constructors.Should().HaveCount(0); type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Static).Should().Equal(constructors); // Compare with the .NET behavior constructors = typeof(ConstructorForNoMatchingVisibilityTest).GetConstructors(BindingFlags.NonPublic | BindingFlags.Static); constructors.Should().HaveCount(0); }
public void ActivatorUtilitiesConstructorPropertiesRedirectedToWrappedConstructor() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0]; var dotNetConstructor = typeof(ConstructorTest).GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0]; constructor.MethodHandle.Should().Be(dotNetConstructor.MethodHandle); constructor.Attributes.Should().Be(dotNetConstructor.Attributes); constructor.Name.Should().Be(".ctor"); constructor.DeclaringType.Should().BeSameAs(typeof(ConstructorTest)); constructor.ReflectedType.Should().BeSameAs(typeof(ConstructorTest)); constructor.GetMethodImplementationFlags().Should().Be(dotNetConstructor.GetMethodImplementationFlags()); constructor.GetParameters().Should().BeEquivalentTo(dotNetConstructor.GetParameters()); }
public void GetCustomAttributes_WithTypeActivatorUtilitiesConstructorAttribute() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0]; var attributes = constructor.GetCustomAttributes(typeof(ActivatorUtilitiesConstructorAttribute), true); attributes.Should().HaveCount(1); attributes[0].Should().BeOfType(typeof(ActivatorUtilitiesConstructorAttribute)); var otherAttributes = constructor.GetCustomAttributes(typeof(ActivatorUtilitiesConstructorAttribute), true); otherAttributes.Should().HaveCount(1); otherAttributes[0].Should().NotBeSameAs(attributes[0]); }
public void GetConstructors_NonPublicStatic() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Static); constructors.Should().HaveCount(1); constructors[0].GetParameters().Should().BeEmpty(); type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Static).Should().Equal(constructors); // Compare with the .NET behavior constructors = typeof(ConstructorTest).GetConstructors(BindingFlags.NonPublic | BindingFlags.Static); constructors.Should().HaveCount(1); constructors[0].GetParameters().Should().BeEmpty(); }
public void GetConstructors_ParameterlessInstance() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorParameterless)); var constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance); constructors.Should().HaveCount(1); constructors[0].IsPublic.Should().BeTrue(); type.GetConstructors(BindingFlags.Public | BindingFlags.Instance).Should().Equal(constructors); // Compare with the .NET behavior constructors = typeof(ConstructorParameterless).GetConstructors(BindingFlags.Public | BindingFlags.Instance); constructors.Should().HaveCount(1); constructors[0].IsPublic.Should().BeTrue(); }
public void GetConstructors_PublicInstance() { var type = new ActivatorUtilitiesConstructorTypeAdapter(typeof(ConstructorTest)); var constructors = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance); constructors.Should().HaveCount(2); constructors[0].GetParameters().Single(p => p.Name == "isPublic1").Should().NotBeNull(); constructors[1].GetParameters().Single(p => p.Name == "isPublic2").Should().NotBeNull(); type.GetConstructors(BindingFlags.Public | BindingFlags.Instance).Should().Equal(constructors); // Compare with the .NET behavior constructors = typeof(ConstructorTest).GetConstructors(BindingFlags.Public | BindingFlags.Instance); constructors.Should().HaveCount(2); constructors[0].GetParameters().Single(p => p.Name == "isPublic1").Should().NotBeNull(); constructors[1].GetParameters().Single(p => p.Name == "isPublic2").Should().NotBeNull(); }