/// <summary> /// Un-sets the explicit construction method for the <see cref="TType"/> type. /// </summary> /// <remarks> /// An explicit construction method can only be unset if it was previously set with the same instance. /// </remarks> /// <param name="constructor">The construction method.</param> /// <typeparam name="TType">The type to set the explicit construction method.</typeparam> public static void UnsetExplicitConstructionMethod <TType>(ConstructorMethod <TType> constructor) { if (!TryUnsetExplicitConstructionMethod(constructor)) { throw new InvalidOperationException(); } }
void SetImplicitConstructor() { var type = typeof(T); if (type.IsValueType) { m_ImplicitConstructor = CreateValueTypeInstance; return; } if (type.IsAbstract) { return; } #if !UNITY_DOTSPLAYER if (typeof(UnityEngine.ScriptableObject).IsAssignableFrom(type)) { m_ImplicitConstructor = CreateScriptableObjectInstance; return; } #endif if (null != type.GetConstructor(Array.Empty <Type>())) { m_ImplicitConstructor = CreateClassInstance; } }
public ConstructorDefinition(ConstructorMethod getConstructor, IEnumerable<ParameterDefinition> parameters, bool isPreferredConstructor) { if (getConstructor == null) throw new ArgumentNullException("getConstructor"); if (parameters == null) throw new ArgumentNullException("parameters"); Construct = getConstructor; Parameters = new ReadOnlyCollection<ParameterDefinition>(parameters.ToList()); IsPreferredConstructor = isPreferredConstructor; }
public void SutIsMethod() { // Arrange var dummyCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); // Act var sut = new ConstructorMethod(dummyCtor); // Assert Assert.IsAssignableFrom <IMethod>(sut); }
/// <summary> /// Un-sets the explicit construction method for the <see cref="TType"/> type. /// </summary> /// <remarks> /// An explicit construction method can only be unset if it was previously set with the same instance. /// </remarks> /// <param name="constructor">The construction method.</param> /// <typeparam name="TType">The type to set the explicit construction method.</typeparam> /// <returns><see langword="true"/> if the constructor was unset; otherwise, <see langword="false"/>.</returns> public static bool TryUnsetExplicitConstructionMethod <TType>(ConstructorMethod <TType> constructor) { if (TypeConstructionCache.GetExplicitConstruction <TType>() != constructor) { return(false); } TypeConstructionCache.SetExplicitConstruction <TType>(null); return(true); }
public void SutIsMethod() { // Fixture setup var dummyCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); // Exercise system var sut = new ConstructorMethod(dummyCtor); // Verify outcome Assert.IsAssignableFrom<IMethod>(sut); // Teardown }
/// <summary> /// Sets the explicit construction method for the <see cref="TType"/>. /// </summary> /// <param name="constructor">The construction method.</param> /// <typeparam name="TType">The type to set the explicit construction method.</typeparam> /// <returns><see langword="true"/> if the constructor was set; otherwise, <see langword="false"/>.</returns> public static bool TrySetExplicitConstructionMethod <TType>(ConstructorMethod <TType> constructor) { if (TypeConstructionCache.HasExplicitConstruction <TType>()) { return(false); } TypeConstructionCache.SetExplicitConstruction(constructor); return(true); }
public void ConstructorIsCorrect() { // Fixture setup var expectedCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(expectedCtor); // Exercise system ConstructorInfo result = sut.Constructor; // Verify outcome Assert.Equal(expectedCtor, result); // Teardown }
public void InvokeWithSingleParameterReturnsCorrectResult(Type targetType, object parameter) { // Arrange var ctor = targetType.GetConstructor(targetType.GetTypeInfo().GetGenericArguments().ToArray()); var sut = new ConstructorMethod(ctor); // Act var result = sut.Invoke(new[] { parameter }); // Assert Assert.IsAssignableFrom(targetType, result); }
public void InvokeWithDefaultConstructorReturnsCorrectResult(Type targetType) { // Fixture setup var ctor = targetType.GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); // Exercise system var result = sut.Invoke(Enumerable.Empty<object>()); // Verify outcome Assert.IsAssignableFrom(targetType, result); // Teardown }
public void InvokeWithDefaultConstructorReturnsCorrectResult(Type targetType) { // Arrange var ctor = targetType.GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); // Act var result = sut.Invoke(Enumerable.Empty <object>()); // Assert Assert.IsAssignableFrom(targetType, result); }
public void SutIsMethod() { // Fixture setup var dummyCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); // Exercise system var sut = new ConstructorMethod(dummyCtor); // Verify outcome Assert.IsAssignableFrom <IMethod>(sut); // Teardown }
public void ConstructorIsCorrect() { // Arrange var expectedCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(expectedCtor); // Act ConstructorInfo result = sut.Constructor; // Assert Assert.Equal(expectedCtor, result); }
public void SutDoesNotEqualSomeOtherObject() { // Arrange var dummyCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(dummyCtor); // Act var result = sut.Equals(new object()); // Assert Assert.False(result); }
public void GetHashCodeReturnsCorrectResult() { // Arrange var ctor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); // Act var result = sut.GetHashCode(); // Assert var expectedHasCode = ctor.GetHashCode(); Assert.Equal(expectedHasCode, result); }
public void SutEqualsOtherSutWithSameCtor() { // Arrange var ctor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); var other = new ConstructorMethod(ctor); // Act var result = sut.Equals(other); // Assert Assert.True(result); }
public void InvokeWithDefaultConstructorReturnsCorrectResult(Type targetType) { // Fixture setup var ctor = targetType.GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); // Exercise system var result = sut.Invoke(Enumerable.Empty <object>()); // Verify outcome Assert.IsAssignableFrom(targetType, result); // Teardown }
public void InvokeWithSingleParameterReturnsCorrectResult(Type targetType, object parameter) { // Fixture setup var ctor = targetType.GetConstructor(targetType.GetGenericArguments().ToArray()); var sut = new ConstructorMethod(ctor); // Exercise system var result = sut.Invoke(new[] { parameter }); // Verify outcome Assert.IsAssignableFrom(targetType, result); // Teardown }
public void SutDoesNotEqualSomeOtherObject() { // Fixture setup var dummyCtor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(dummyCtor); // Exercise system var result = sut.Equals(new object()); // Verify outcome Assert.False(result); // Teardown }
public void SutEqualsOtherSutWithSameCtor() { // Fixture setup var ctor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); var other = new ConstructorMethod(ctor); // Exercise system var result = sut.Equals(other); // Verify outcome Assert.True(result); // Teardown }
public void GetHashCodeReturnsCorrectResult() { // Fixture setup var ctor = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor); // Exercise system var result = sut.GetHashCode(); // Verify outcome var expectedHasCode = ctor.GetHashCode(); Assert.Equal(expectedHasCode, result); // Teardown }
public void ParametersReturnsCorrectResult(Type targetType, int index) { // Fixture setup var ctor = targetType.GetConstructors().ElementAt(index); var expectedParameters = ctor.GetParameters(); var sut = new ConstructorMethod(ctor); // Exercise system var result = sut.Parameters; // Verify outcome Assert.True(expectedParameters.SequenceEqual(result)); // Teardown }
/// <summary> /// Verifies that a constructor has appropriate Guard Clauses in place. /// </summary> /// <param name="constructorInfo">The constructor.</param> /// <remarks> /// <para> /// Exactly which Guard Clauses are verified is defined by /// <see cref="BehaviorExpectation" />. /// </para> /// </remarks> public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) { throw new ArgumentNullException("constructorInfo"); } EnsureTypeIsNotGeneric(constructorInfo.ReflectedType); var method = new ConstructorMethod(constructorInfo); this.Verify(method, false); }
/// <summary> /// Verifies that a constructor has appropriate Guard Clauses in place. /// </summary> /// <param name="constructorInfo">The constructor.</param> /// <remarks> /// <para> /// Exactly which Guard Clauses are verified is defined by /// <see cref="BehaviorExpectation" />. /// </para> /// </remarks> public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) { throw new ArgumentNullException("constructorInfo"); } constructorInfo = this.ResolveUnclosedGenericType(constructorInfo); var method = new ConstructorMethod(constructorInfo); this.Verify(method, false, false); }
/// <summary> /// Verifies that a constructor has appropriate Guard Clauses in place. /// </summary> /// <param name="constructorInfo">The constructor.</param> /// <remarks> /// <para> /// Exactly which Guard Clauses are verified is defined by /// <see cref="BehaviorExpectation" />. /// </para> /// </remarks> public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) { throw new ArgumentNullException(nameof(constructorInfo)); } constructorInfo = this.openGenericTypeClosingUtil.CloseGenericType(constructorInfo); var method = new ConstructorMethod(constructorInfo); this.DoVerify(method, isReturnValueDeferable: false, isReturnValueTask: false); }
public void ParametersReturnsCorrectResult(Type targetType, int index) { // Arrange var ctor = targetType.GetConstructors().ElementAt(index); var expectedParameters = ctor.GetParameters(); var sut = new ConstructorMethod(ctor); // Act var result = sut.Parameters; // Assert Assert.True(expectedParameters.SequenceEqual(result)); }
public void SutDoesNotEqualOtherSutWithDifferentCtor() { // Arrange var ctor1 = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor1); var ctor2 = typeof(PropertyHolder <string>).GetConstructor(Type.EmptyTypes); var other = new ConstructorMethod(ctor2); // Act var result = sut.Equals(other); // Assert Assert.False(result); }
public void SutDoesNotEqualOtherSutWithDifferentCtor() { // Fixture setup var ctor1 = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor1); var ctor2 = typeof(PropertyHolder <string>).GetConstructor(Type.EmptyTypes); var other = new ConstructorMethod(ctor2); // Exercise system var result = sut.Equals(other); // Verify outcome Assert.False(result); // Teardown }
public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) { throw new ArgumentNullException("constructorInfo"); } if (constructorInfo.ReflectedType.IsGenericTypeDefinition) { throw new GuardClauseException( string.Format( CultureInfo.CurrentCulture, "AutoFixture was unable to create an instance of {0}, because it's a generic type definition.", constructorInfo.ReflectedType.Name)); } var method = new ConstructorMethod(constructorInfo); this.Verify(method, false); }
/// <summary> /// Returns a value from the internal dictionary, calling the /// function to create a new instance and registering it if /// none already exists. /// </summary> public T Get <T>(string id, ConstructorMethod createInstance) where T : GuiControl { T ret; if (TryGetValue <T>(id, out ret) == false) { ret = createInstance() as T; if (ret != default(T)) { ret.ID = id; if (ret is IGuiInputHandler) { ret.InputHandler = ret as IGuiInputHandler; } Register(id, ret); } } return(ret); }
/// <summary> /// Verifies that a constructor has appripriate Guard Clauses in place. /// </summary> /// <param name="constructorInfo">The constructor.</param> /// <remarks> /// <para> /// Exactly which Guard Clauses are verified is defined by /// <see cref="BehaviorExpectation" />. /// </para> /// </remarks> public override void Verify(ConstructorInfo constructorInfo) { var method = new ConstructorMethod(constructorInfo); this.Verify(method); }
public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) throw new ArgumentNullException("constructorInfo"); if (constructorInfo.ReflectedType.IsGenericTypeDefinition) throw new GuardClauseException( string.Format( CultureInfo.CurrentCulture, "AutoFixture was unable to create an instance of {0}, because it's a generic type definition.", constructorInfo.ReflectedType.Name)); var method = new ConstructorMethod(constructorInfo); this.Verify(method, false); }
public Constructor(ConstructorMethod <TType> method) { Construct = method; }
public void SutDoesNotEqualOtherSutWithDifferentCtor() { // Fixture setup var ctor1 = typeof(ConcreteType).GetConstructor(Type.EmptyTypes); var sut = new ConstructorMethod(ctor1); var ctor2 = typeof(PropertyHolder<string>).GetConstructor(Type.EmptyTypes); var other = new ConstructorMethod(ctor2); // Exercise system var result = sut.Equals(other); // Verify outcome Assert.False(result); // Teardown }
/// <summary> /// Verifies that a constructor has appropriate Guard Clauses in place. /// </summary> /// <param name="constructorInfo">The constructor.</param> /// <remarks> /// <para> /// Exactly which Guard Clauses are verified is defined by /// <see cref="BehaviorExpectation" />. /// </para> /// </remarks> public override void Verify(ConstructorInfo constructorInfo) { if (constructorInfo == null) throw new ArgumentNullException("constructorInfo"); EnsureTypeIsNotGeneric(constructorInfo.ReflectedType); var method = new ConstructorMethod(constructorInfo); this.Verify(method, false); }